#Day 06
302 messages · Page 1 of 1 (latest)
comp back on top of his game
that was fun
I started doing something that was bad and realized there's a very easy way to do it
lmaong
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
honestly took me too long to read the problem
yeah, reading takes a bit
mainly cause i didnt expect the solution to be so simple
since yesterday was way harder
i was off by one and got hit by the timeout rip
I just spent half a second making it even better after I submitted part 2, now part 1 - part 2 is changing 2 chars
oh comp you made the thread before starting the challenge
yeah
how much time did that take
like 30 seconds
i dont mind 
part of it is so that i get to put anime recommendations in the op
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
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)
Ayy I did this too
Easiest part 2 ever
i made part 1 work with any marker length already so part 2 is literally nothing 
Yeah lol
we kinda did the same thing i guess except i used a hashmap instead of an array
i haven't seen yours, wait
oh i guess yea
should be O(n)
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>
set also a size property 
man 
is fixed
I overcomplicate things in my head
you shouldn't look at my solution then
you threw in some error cases, nice
just for the sake of it lol
I feel like you couldve made it easier by just splitting the input in the first place
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 
strings are effectively arrays of chars, don't know why i've seen so many split("") s today
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
well I kinda need mine to be an array cuz of findIndex sooo
... .indexOf
is it really
indexOf requires a search string instead of a function smh
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 
Write-up-ish: https://github.com/GodderE2D/advent-of-code#day-6
Direct code: https://github.com/GodderE2D/advent-of-code/blob/main/results/2022/day-6/part-1.ts
Easy-hard-easy days loop
cheeze did some unreadable fuckery for this one jesus
i wanna see
i'd be surprised if anyone understands my solution tbh
looks like fuckery
looks like youre looping over a the string in windows checking if any 2 letters are the same in the window
eh 50% of the idea is there 
whats the other half
figure out what the variable a does
mine is prob not the most efficient but i accept it already
did you see mne
let me see
Shmexy
oh yeah thats cleaner
forgot .slice existed wtf
i used that like 10 times yesterday
now...if you don't want to mutate things get very different
i mean, everyone's solution is just a variant of ||slicing + using set or make unique + compare set size|| 
smh
well, yea
i don't see other solution that is different other than urcute's one
and urcute is just doing the same thing except he made the map himself
yea true
instead of using set
am i the only one that doesn't use a set 🥹
.
lmfao
does it keep a track of number of duplicates of any letter of the current marker?, a = 0 means there's no duplicates

wow thats kind of smart of not using sets
mostly ppl are exposed to ideas of sets so thats what comes to mind first 
i dont 
same shit
julia more like coolia
julia is poggers
Inefficient as always xd
my solution is closer to cheezes than doing the slicing
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
k<=26 so it's all O(n) smh
@heavy raft :angerycat:
pigeonhole
huh?
you can only have up to 26 before there has to be a duplicate
well it has to be less than or equal to 26 cause there's 26 letters in the alphabet
oh yeah
you can't have 27 unique letters
lets just imagine a version of the question where the character isn't limited to alphabets
that's the pigeonhole principle yeptune
but if you're generalizing for problems including other chars then k can be >26
then cheeze would have to change some numbers
and by numbers I mean implement a map
ya that's what i did
so the problem is that map operations aren't constant time 
no
whaat
close enough man
but by themselves they're not


is it the same for js objects
probably
yikes
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
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
no one knows what they're talking about 
i know i always knew it but bringing it up every time is heavy akshually vibes

day 6 was easy
the part 2 felt kinda useless
yeah. i basically changed one variable
today's one is prolly a calm before tomorrow's some storm
well, that, and maps' running time is probabilistic, depending on where the hash function buckets things
i don't use set either but then i don't really understand my own solution so
i should have used set, but i just did a split and if the length > 2 i knew there was a duplicate 😂
split?
i use a cool variable and unique arrays which i guess is technically just set with extra steps
it just looks like a variant of the slice approach to me
oh you split by each character
yeah
that's a unique one i guess
not a very clean approach but it works
i almost thought to use regex but then i thought better of it
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
id be impressed to see a solution like that
cause that's not an easy regex to write imo
I don't think that should be hard
lemme see
yea
just generalize this to more chars
well the easiest way would be to just enumerate all combinations with unique characters
/((?!\2).)((?!\1).)/
i can't immediately think of a way but my regex is pretty rusty
ill try it out later
too much thinking comp, just bruteforce
its only like 15,000 combinations
for every substring size yeahhh
this is O(nk) 
don't you mean O(n) 
unless you wanna get into k<=#Unicode codepoints 
no frick you
frick you
folder with space 
im complaining about your folder names having spaces in them
part 01 twice :(
Nice ctrl+c myself
also why aren't you use template strings
I started using arrays in the start
For some weird reason
So, for now I just use it for consistency
it may not have a space bc the link 404s 
fixed
it literally just existed
fixed
just rename it, sorry Will
Edited the message now
eww shift
Literally the first thing I thought of that could work
oh, i see my approach was way too complicated once again
https://github.com/almostSouji/advent/blob/main/2022/06_tuning/solve.py
|| that unnecessary len call and weird window handling tho||
appel elixir being pretty as per usual
i wish the find_index callback was prettier
but that was the easiest way i could find to do it :(
oh i'm such a dork for going back instead of starting at 0 and declaring the || moving window || forward
Yoah, that is some clean code
Nice one, so small, mine is a big boy
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
Yeah this was pretty simple using pythons array indexing methods
And slicing
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
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
It's really usefull
JS doesn't have anything close to it
i hate python
same, but it really influenced how bad my solution is today
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 ||
omg no way me too #rust #puckfython 
nah python good
my solution is superior than yours frick u
ngl i liked this one today
but i wish part 2 was a bit more difficult
just consisted of changing a variable lmfao
where do you get the timed stats like these from?
oh i see in the leaderboard
im just blind lol
I think I was 5th last I checked
Which isnt bad for my shitty python stuff
But its the *s that really matter
||```js
const distinctChars = 14;
console.log(
[...input].findIndex(
(_, i) => i-- >= distinctChars && new Set(input.slice(i - distinctChars, i)).size === distinctChars,
) - 1,
);
nice
nah mine better
ok
yours can't be adapted to all alphabets
"hey, which phillips head screwdriver is better? A or B?"
"B, because A cannot screw a hexagon bolt"
btw)

