#Day 06

302 messages · Page 1 of 1 (latest)

heavy raft
loud matrix
#

comp back on top of his game

heavy raft
#

easy day

#

still cant beat dim

#

dang sweatlord

lament ice
#

that was fun

#

I started doing something that was bad and realized there's a very easy way to do it

sleek wagon
#

lmaong

#

honestly took me too long to read the problem

lament ice
#

yeah, reading takes a bit

sleek wagon
#

mainly cause i didnt expect the solution to be so simple

#

since yesterday was way harder

lament ice
heavy raft
#

i was off by one and got hit by the timeout rip

sleek wagon
#

damnn

#

i got fucked by the timeout on day 5

lament ice
#

I just spent half a second making it even better after I submitted part 2, now part 1 - part 2 is changing 2 chars

sleek wagon
#

i mean day 4

#

waited 5 minutes twice in a row

heavy raft
#

my exams start in two days so

#

youre the only speedrunner left

sleek wagon
#

my first exam is wednesday

#

data mining

#

at 5:45-7:45 pm

lament ice
#

I actually think the ts / js solution is quite clever

sleek wagon
#

oh comp you made the thread before starting the challenge

heavy raft
#

yeah

sleek wagon
#

how much time did that take

heavy raft
#

like 30 seconds

#

i dont mind pizzaCat

#

part of it is so that i get to put anime recommendations in the op

lament ice
#

Well it only really needs to take as long as opening the puzzle and writing the name here

#

you can have the rest pre-typed

sleek wagon
#

is anyone going for the most optimized solution

#

most solutions now are O(kn) where n is the length of the string and k is the number of unique chars

#

but it can be done in O(n)

static merlin
pale arrow
#

Well that was easy

pale arrow
#

Easiest part 2 ever

wintry halo
pale arrow
#

Yeah lol

uncut jetty
#

ezpz

#

cant wait to parse 100x100 mazes tomorrow

teal prairie
wintry halo
teal prairie
#

i haven't seen yours, wait

teal prairie
#

oh i guess yea

wintry halo
#

should be O(n)

rich plaza
#

todays was easy ||```rs
fn find_packet_start(data: &str, size: usize) -> usize {
let chars = data.chars().collect::<Vec<char>>();
let found = chars
.windows(size)
.enumerate()
.find(|(, xs)| {
let filtered: HashSet<
> = xs.iter().collect();
filtered.len() >= size
})
.unwrap();

found.0 + size

}

<https://github.com/Fyko/advent-of-code/blob/main/2022/06/src/main.rs>
uncut jetty
#

set also a size property theCutest

red hatch
#

man smh_walter

red hatch
#

I overcomplicate things in my head

slender void
#

you shouldn't look at my solution then

red hatch
#

you threw in some error cases, nice

slender void
#

just for the sake of it lol

red hatch
#

I feel like you couldve made it easier by just splitting the input in the first place

slender void
#

eh, that would at best change iterating over string chars to iterating over array elements

#

i would still need an index in this way, which means i would still use c for loop

#

unless i would do for..of and have a separate index but that's just Thqnkqng

lament ice
#

strings are effectively arrays of chars, don't know why i've seen so many split("") s today

slender void
#

yeah

#

and only reason why i make packets into array is so that i have less fucking around with the set

#

which arguably isn't cleanest, but hey it works

red hatch
slender void
slender void
#

get out of here with your brain

#

some of us don't have one

#

smh

lament ice
#

lol

#

I still think my solution is quite sexy

teal prairie
#

is it really

red hatch
slender void
#

i do some fuckery before the loop cause i wasn't sure how to check in the loop if i should move the window or just add new

#

i can tell in hindsight, but shrugCat

quiet current
red hatch
#

cheeze did some unreadable fuckery for this one jesus

quiet current
#

i wanna see

teal prairie
#

i'd be surprised if anyone understands my solution tbh

quiet current
#

looks like fuckery

red hatch
teal prairie
#

eh 50% of the idea is there Hutao_o7

red hatch
#

whats the other half

teal prairie
#

figure out what the variable a does

quiet current
#

mine is prob not the most efficient but i accept it already

quiet current
#

let me see

lament ice
#

Shmexy

quiet current
#

oh yeah thats cleaner

#

forgot .slice existed wtf

#

i used that like 10 times yesterday

lament ice
#

now...if you don't want to mutate things get very different

teal prairie
#

i mean, everyone's solution is just a variant of ||slicing + using set or make unique + compare set size|| KekTao

slender void
#

smh

teal prairie
#

i don't see other solution that is different other than urcute's one

red hatch
#

and urcute is just doing the same thing except he made the map himself

teal prairie
#

yea true

red hatch
#

instead of using set

teal prairie
#

am i the only one that doesn't use a set 🥹

slender void
red hatch
#

lmfao

granite needle
teal prairie
granite needle
#

wow thats kind of smart of not using sets
mostly ppl are exposed to ideas of sets so thats what comes to mind first cookieCat

cinder moat
cinder moat
teal prairie
#

same shit

uncut jetty
#

julia more like coolia

cinder moat
#

julia is poggers

unique swift
#

Inefficient as always xd

wintry halo
#

because our solutions are in O(n) time while yours is in O(kn)

#

@teal prairie i stopped 2020 at day 6

#

but damn the questions are much easier now than it used to be in 2020 when i just started

heavy raft
#

k<=26 so it's all O(n) smh

sleek wagon
#

@heavy raft :angerycat:

wintry halo
#

it can be anything

heavy raft
#

pigeonhole

wintry halo
#

huh?

heavy raft
#

you can only have up to 26 before there has to be a duplicate

sleek wagon
#

well it has to be less than or equal to 26 cause there's 26 letters in the alphabet

wintry halo
#

oh yeah

sleek wagon
#

you can't have 27 unique letters

wintry halo
#

lets just imagine a version of the question where the character isn't limited to alphabets

heavy raft
#

that's the pigeonhole principle yeptune

sleek wagon
#

but if you're generalizing for problems including other chars then k can be >26

heavy raft
#

then cheeze would have to change some numbers

wintry halo
#

tru

#

but mine still holds dogeHaHa

heavy raft
#

and by numbers I mean implement a map

wintry halo
#

ya that's what i did

heavy raft
#

so the problem is that map operations aren't constant time meguFace

wintry halo
#

huh?

#

set and get isn't O(1) ?

heavy raft
#

no

wintry halo
#

whaat

heavy raft
#

they're amortized constant

#

meaning over time they cancel out

wintry halo
#

close enough man

heavy raft
#

but by themselves they're not

wintry halo
heavy raft
wintry halo
#

is it the same for js objects

heavy raft
#

probably

wintry halo
#

yikes

heavy raft
#

just like how array append is amortized constant

#

the regrow is O(n) but you get back n O(1) appends, so they cancel out

wintry halo
#

using an array was my first thought tbh, you can just keep appending and changing start index instead of removing to keep it O(n)

#

i know it's amortized but cmon no one mentions it

heavy raft
#

no one knows what they're talking about cookieCat

wintry halo
#

wait uhh

#

nvm

wintry halo
heavy raft
wintry halo
#

you can't deny it

#

but I didn't know it was the same for maps and objects

wraith pulsar
#

day 6 was easy

wintry halo
#

the part 2 felt kinda useless

wraith pulsar
#

yeah. i basically changed one variable

granite needle
#

today's one is prolly a calm before tomorrow's some storm

wintry halo
#

oh yeah

#

it always picks up at 7

#

i gave up at 7 my first try

heavy raft
rain pier
#

i don't use set either but then i don't really understand my own solution so

wintry halo
#

no one does

#

because it's more unreadable than a 3 year old's writing

wraith pulsar
#

i should have used set, but i just did a split and if the length > 2 i knew there was a duplicate 😂

wintry halo
#

split?

rain pier
#

i use a cool variable and unique arrays which i guess is technically just set with extra steps

wintry halo
#

oh you split by each character

wraith pulsar
#

yeah

wintry halo
#

that's a unique one i guess

wraith pulsar
#

not a very clean approach but it works

wintry halo
#

not very efficient but unique

#

old me woulda died to use a regex here

wraith pulsar
#

i almost thought to use regex but then i thought better of it

wintry halo
#

no i mean a regex that straight up gives you the answer from the base input

#

it's gonna be a tough regex to write but i think it's possible

wraith pulsar
#

no i get what you mean

#

i almost did that

wintry halo
#

id be impressed to see a solution like that

#

cause that's not an easy regex to write imo

heavy raft
#

I don't think that should be hard

#

lemme see

#

yea

#

just generalize this to more chars

uncut jetty
#

well the easiest way would be to just enumerate all combinations with unique characters

heavy raft
#

/((?!\2).)((?!\1).)/

wintry halo
#

ill try it out later

uncut jetty
#

too much thinking comp, just bruteforce

heavy raft
#

but I just gave the answer

uncut jetty
#

yea but i mean

#

trivially you just do /(abcd)|(abce)|(abcf)|...|(vxya)|...|(vxyz)/ theCutest

heavy raft
#

true, all finite languages are regular languages pizzaCat

uncut jetty
#

its only like 15,000 combinations

wintry halo
heavy raft
uncut jetty
#

O(ink)

#

🐷

wintry halo
#

don't you mean O(n) drakeLUL

heavy raft
#

nope

#

it actually works for any alphabet

wintry halo
#

hmm?

#

oh you mean it's generalised ok

heavy raft
#

unless you wanna get into k<=#Unicode codepoints meguFace

wintry halo
#

i mean

#

sure deusVult

heavy raft
#

no frick you

wintry halo
rain remnant
#

I actually liked what I did this time

rich plaza
#

folder with space MonkaS

rain remnant
#

What space

#

Isn't this day 2006?

#

I should change it

#

I'm just lazy

rich plaza
#

im complaining about your folder names having spaces in them

uncut jetty
#

part 01 twice :(

rain remnant
#

Nice ctrl+c myself

uncut jetty
#

also why aren't you use template strings

rain remnant
#

I started using arrays in the start

#

For some weird reason

#

So, for now I just use it for consistency

unique swift
#

Arrays are good for this tho

#

||Shift and push||

static merlin
rain remnant
slender void
#

it literally just existed

rain remnant
#

Edited the message now

wintry halo
unique swift
#

Literally the first thing I thought of that could work

dusky cypress
dusky cypress
static merlin
#

i wish the find_index callback was prettier

#

but that was the easiest way i could find to do it :(

dusky cypress
#

oh i'm such a dork for going back instead of starting at 0 and declaring the || moving window || forward

rain remnant
rain remnant
cinder moat
#

managed to shorten my Julia solution
||```julia
function findmarker(len::Int64)
    input = read("inputs/06.txt")

~-findfirst(i -> allunique(input[i-~-len:i]), len:length(input)) + len
end

pale arrow
#

And slicing

rain remnant
#

Nice!

#

I should take the time to learn python ngl

sleek wagon
#

I learned python for a data science course in college and then did aoc 2021 with it

#

now I'm good enough to use it for coding challenges

pale arrow
#

That's kinda my level too

#

Made a discord bot in discord.py
Used it for some process automation at work
Can do coding challenges

#

I just love the array[start:stop:step] syntax python has

rain remnant
#

JS doesn't have anything close to it

static merlin
#

i hate python

dusky cypress
#

because i guess my first thought was that i can use it nicely here
but then it's just gibberish - it works - but it's so much harder to read than if i just started at the beginning and added the || window size when outputting ||

cinder moat
pale arrow
#

nah python good

teal prairie
uncut jetty
#

advent of code

#

more like

#

advent of smelly

#

hahahahaha

vast meadow
#

ngl i liked this one today

#

but i wish part 2 was a bit more difficult

#

just consisted of changing a variable lmfao

vast meadow
#

oh i see in the leaderboard

#

im just blind lol

pale arrow
#

I think I was 5th last I checked

#

Which isnt bad for my shitty python stuff

#

But its the *s that really matter

rain pier
#

||```js
const distinctChars = 14;

console.log(
[...input].findIndex(
(_, i) => i-- >= distinctChars && new Set(input.slice(i - distinctChars, i)).size === distinctChars,
) - 1,
);

rich breach
#

nice

wintry halo
teal prairie
#

ok

wintry halo
#

yours can't be adapted to all alphabets

teal prairie
#

"hey, which phillips head screwdriver is better? A or B?"
"B, because A cannot screw a hexagon bolt"