#advent-of-code
1 messages Β· Page 17 of 1
i mean it's a lot simpler than that, ||all the jokers should always be the same as your most frequent card||
oh yea but then it would be greedy and not purely naive anymore
it's pretty easy to convince yourself that's true; imagine yourself with any given hand, add a joker. what the joker should be is always the same ||the most frequent card you already have||
then you still need to ||sort to always choose the bigger of the two in the case of KKTTJ|| right?
no, because it doesn't matter
yea you can just prove this by showing that it wouldnt make sense for all cases
oooooh it doesn't because ||we are not replacing|| omfg I made it soooooo much harder for myself in so many ways with my first solution...
yeah
im too lazy to implement this tbh
I think it's pretty deliberately designed to be this way; to actually make the joker substitution very simple
if there were real poker hands, or if the joker actually became teh card for tie breaking purposes then there would be at least some logic around choosing what to make the joker
as it stands there's zero; I never actually explicitly choose what the jokers will be in my code
why were todays and yesterdays problem so easy compared to the problems before
the questions are all laid out by a single dude, and noones perfect at laying out problems π€·
if you consider that day 5 part 2 worked with brute force, i'm not sure there really was a big difficulty spike
doing day 5 part 2 "properly" has been easily the hardest thing so far but it's not necessary
u could brute force it??
according to the stats page, day 5 does have less 2-star completions than day 6
i got a java heap error π
witness my silly solution
||```py
def replace_jokers(self, hand_type, hand):
if 'J' not in hand:
return hand_type, hand
card_count = Counter(hand.replace('J', ''))
#case 3333J
if hand_type == '4':
hand_type = '5'
#case QQQJA
elif hand_type == '3':
hand_type = '4'
#case QQQJJ or JJJ22
elif hand_type == 'fullHouse':
hand_type = '5'
elif hand_type == '2':
#case KKTTJ
if all(x[1] == 2 for x in card_count.items()) and len(card_count) == 2:
hand_type = 'fullHouse'
#case KTJJT
else:
hand_type = '4'
#case 2388J or 23J8J
elif hand_type == '1':
hand_type = '3'
#case 2348J
elif hand_type == 'highCard':
hand_type = '1'
return hand_type, hand
yea but i dont think that the bruteforce solution was the way it was supposed to be solved
although I guess to brute force 5p2 in python you need to at least use multiprocessing, or do the clever/||reverse|| brute force
yes, I agree
while todays problem is supposed to be solved in a naive/greedy way
what's greedy π
you can't pick the difficulties perfectly
Yah, my d5p2 was brute force.
i bet u tmrs gonna be a pathfindinh or flood fill problem
it's always around this time
that we get the first one
also in the end I think difficulty is more oriented around completion than doing it the way you're "supposed to"
put the lines before and after the backticks
Spoilers should really go in the daily spoiler channel
i think that part of the design in 5 is that the actual input size isn't huge (depending how you look at it), which gave brute force a chance to work.
are u talking about a diff day
oh wait nvm
the size itself wasn't big
but the numbers were hugee
made brute forcing each ||individual seed|| hard
Can you put this in the daily solution thread? Not here plz
greed just refers to algorithms that make the best "immediate" move.
Like when you try to find a minimal spanning tree for a graph, there's a greed solution to always pick the cheapest path that connects an unconnected node.
it's not obvious by inspection that this "greedy" algorithm is optimal, but it actually is
a technique where you choose to do something that gives you a better answer first. like in finding elements in an array that add up to a sum, you could say to pick the largest number smaller than given sum and go from there
there isn't really a good example yet this year of a greedy algorithm, except maybe in a trivial sense
i struggled w part 1 bc i spent 10 min tryna make a custom comparator in kotlin bc u can't compare lists
unless i'm forgetting something
and then i j manually checked each index
well the problems so far are all doing some processing for each input rather than eg finding an optimal way to arrange inputs. tbh for day 5 i considered ||bruteforcing from highest mapped location and reverse map it|| but couldn't think of an efficient way to handle ||unmapped locations||
yeah, there hasn't really been any optimization problems which is where you see greedy
Can anyone look at my day 5 solution and tell me why itβs not working
i can try to have a quick look, send it
Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.
nvm part 2 required me to only add like 10 lines to my code
huh how did this code even get the correct answer
how hard was day 5? chart of every top 100 submission for every year in aoc:
https://www.maurits.vdschee.nl/scatterplot/
this code shouldnt work for the hand JJJJJ
but it somehow does
so like 15 last year, 8 or 16 2 years ago and 16 or 19 3 years ago, cool
what's with the day 1 spike in 2015 I wonder
i assume it's related to AoC 2015 being the first aoc event
what with the 2018 outliers?
actually, too afraid to think about it, it's probably bad, very bad
ok, i see 2015 outliers, now i need to take a check at that problem
2015 day 19 doesn't look too bad. still nothing like day 5 of this year i think
I ended up ||counting up one by one from 0|| lol
Worth noting for anyone that looks at this that they don't keep the y axis scale fixed
So the plot is extremely misleading
Although day 5 certainly still seems to be an outlier
u can fix the y axis
why axes?
This is pretty cool, watching a leaderboard dev solve in realtime. Are there others who do this higher on the leaderboard?
https://www.youtube.com/@nthistlethwaite
Can we do AGC assembly for next roulette?
never would've expected a leaderboard dev to use idle
danke
pretty amazing stuff
what if I want to read the little elven stories?
..or maybe they do..
Guess I'm bad at jokes
Honestly yeah, I def get the alure of the leaderboard, but knowing that I'll never crack it, I like going at a liesurely pace and enjoying the story
Language Roulette: Day 8
The language is ... Bash
oof
gonna bash your keyboard
f
Good luck everyone
π«‘
you know, bash might be less painful than prolog lol
I'm not doing the language roulette but still
Who has a prolog solution up? I wnna see it
!! maybe I should start doing the language roulette from today, good thing it isn't bourne shell
<@&518565788744024082> Good morning! Day 8 is ready to be attempted. View it online now at https://adventofcode.com/2023/day/8. Good luck!
I can tell this is gonna be a CPU-killer in part 2..
31 / 10 wooo
Leaderboard is now filled?
spoiler channel isn't up?
not yet
I too like going at leisure rate. I find problems hard to understand at first, and I'm challenging myself to use a non-generic language to solve it.
Closer to solving day-5 now π
how. part 2 is insane
how many steps did your part 2 take
it's just ||lcm||
how
Can someone pls explain this part for me
Of course, you might not find ZZZ right away. If you run out of left/right instructions, repeat the whole sequence of instructions as necessary: RL really means RLRLRLRLRLRLRLRL... and so on. For example, here is a situation that takes 6 steps to reach ZZZ:
loop around if you reach the end
my best finish
I see clearly that you just need to do LR
How did that become 6 steps?
RR works too
Yeah and the 2ns example confuses me
Start at AAA, go either left/right to reach BBB
||do you have to consider all the nodes at once?||
isn't that what it's asking though. Make sure all end with Z
If the instructions in the first line don't get you there, you repeat them until they do
i just realized i made a crazy assumption that worked out
wait how did that work what???
Hmm yeah I would punch the guy who made this map
idk what you're trying to do with ||lcm||
Why do you make me take 6 turns in a desert when I can get out of it in 2 turns
i started late again oops
my code has already gone through 1,000,000,000 steps and more for part 2
same
so i j read the prompt
i was too slow to understand
i'm worried ab part 2 tho
and i completely forgor to do it yesterday
I kinda like them, make you think a bit
well⦠it's ||lcm||
bruteforcing is taking forwever, I don't think it's a valid way of doing it
how is it ||lcm|| though? That makes no sense
I still have no clue how to get d5 p2 to work. I got the answer that worked for my input but not the example data for some reason...
I thought I could relax but there's a guy on my private leader board who also has part 1 I'mma panic
||order of products of cycles||
that's making no sense
:)

OH I GOT IT
if we imagine each ghost to start on a node ending with A, ||the number of steps (let it be X) needed for each of them to get to Z is independent of each other||, and ||once they get to Z, when we continue following instructions they just keep cycling every X steps||
too late
:')
need a general hint for part 2
||lcm||
i don't understand how it works, but it does
because how would you know if the ||Z makes that node start all over again instead of going for a few more then starting again||
i nearly had it cuz ||i realized the lengths for all ghosts to find a Z node was easily divisible by the length of the instructions||, never occured to me it could be more than that
time to implement it without the math lib, shouldnt be too bad
why without?
tryna do no imports
It doesn't work in the general case
the inputs are just generated so that it works
thought so
you can just explicitly check for a cycle instead
rip
and it just happened that my heat is right when aoc opens
i also realized that the code i wrote wasn't working for automatic example parsing π
I did get a 50 free pb though (29.19)
nice one!
niceee
Right. Psrt1 was easy. Assumed part2 would involve finding the shortest paths, was glad I was using rust because of the 3rd party pathfinding module. ||I was wrong||
After some time in part2 ||trying to convert it to using a vec and sorting it, then hashset, then finding it was taking too long|| realized I just needed ||lcm of all the times (well, used GCD, realized answer was obviously wrong, replaced with LCM and it worked). Unfortunately, rust doesn't have lcm included, so I needed to import it, and a short function using reduce to use it on all elements||. Still, managed a significanlty better part2 rank than part1 (still not in top 1000 though).
there's some kind of trick to this isn't there
wait how does ||lcm|| just work?
eric wanted to be cool
i should've gotten onto the leaderboard but i didn't bc i didn't think ||lcm|| would just work
it shouldn't lmao
||my intuition/hope was that the time for start to dest1 would be time for dest1 to dest2. In retrospect, this might have not been guaranteed, but it worked. Also, it turns out that gcd of all times !=1, so that might be related||
what's dest1/dest2?
oh wait, so ||all the endpoints are in one big cycle||?
||first valid destination reached, second valid destination reached||
Wow 1st place today got 2 stars in 4mins
I feel like the input is specifically constructed so that ||lcm|| would work. I was thinking about using ||Chinese remainder theorem|| if the ||initial number of steps to reach Z|| is different from the ||loop size to reach another Z||, but apparently they're the same
So just 4 mins to do everything, including writing a non-brute forcing solution
can you elaborate
#1182550042091991180 message this is true for all cycles, so it definitely seems intended
Day 8 part 2 is actually so stupid
it's a hidden assumption
so like how am i supposed to know that it would work? like technically it should have never worked, no?
unless im missing something stated in the problem statement
in that case, please enlighten me
you could have figured it out after looking at the values
but that's still assuming
i never want to assume anything by looking at the values. ig im too used to usaco being explicit about everything
Yup, aoc is a completely different style from usaco and other cp competitions
Almost anything is fair game since you have the whole input (except ai ig)
wait, is there a situation that wouldn't work in?
what if there wasnt any cycles
what if it was an acylic graph
what if each "cycle" length was actualyl different
I haven't seen anyone's input not do that, so I'm confident it's designed that way
How is it even possible to solve part 1 in 38 seconds?
it's like coding it while reading it ig
Ah yes I love today's problem haha
Ooooh... yeah actually
It makes brute force totally impractical
now i think of it, possibly AI
i dont like today's pt2
@deep ferry I see what you mean now, ||I assumed the graph cycled immediately after reaching an end node and that happened to be correct||
why
relies on input assumptions
yea
fellow usaco enjoyer
Well, not quite but close enough
grinding for the college app
dont get me wrong i love programming
and USACO's not bad
What's off there?
but i'd rather be making projects
||the number of steps before reaching the loop is equal to the number of steps between the end and the start of the loop, so they cancel out||
I despise usaco
eh W ig
And c++ by extension
I like rust more 
Rust >>
maybe even better than Python
the one thing i would complain about python is the implicit pass-by-references vs pass-by-value
Wow, great idea! Prevent anyone from editing your code without great work or great disruption! Job security! π
is there private leaderboard for this server?
yes
code?
No thanks, I already have enough trouble between tab and 4 spaces π
i cant find it though
@minor cave can you help
@placid lake ? the bot used to show the link but now it doesnt... hope this is the right person to ask
ah
That Dennis Pham leaderboard is not very active
we technically have 9 leaderboards, because we have more people than a single lb can fit
oh so the &aoc and slash commands are different
it used to be &aoc join and it would try to DM people. But using a slash command and having it be an ephemeral message is a much nicer solution
we also re-use the same leaderboards each year, so there are a few people that joined a previous year and aren't active this year
i joined it last year...
pruning inactive members would be nice maybe
I might go through after this year and prune people who haven't done a single day on any year
but it's also a pita because I need the owners of each leaderboard to do that and that's a lot of cat herding
i mean, like 80 people just did the first star for today. That's a good amount i'd say
We are probably in different lb
yes, there are like 9 of them
Yeah so in mine, only 48 ever did a start
is there an archive of older years' leaderboards that I don't know about?
oh were you only referring to the leaderboard you're on?
Not rn, but it has been on my list to do. Maybe I can get it this weekend
Yeah, I cant see other lb anyway
i'm actually on a few of them, i'm not sure why
Where do you get the code for all of our lb?
just delete them all and make everyone join again
You are brute forcing it
π
that's not the worst idea lol
This is the current leaderboard output if anyone's curious https://paste.pythondiscord.com/6SHBR3SN6Y5NFR5NGSMNYGZCVE
Only has top 1,000 because of the paste service size limit
i was curious, the lb command used to output this link
is there no way for us to get the full leaderboard anymore?
the amount of cat herding I'd have to do to get the leaderboards recreated π©
it's still supposed to, but when we moved to the new paste service the feature broke. A fix for it should be merged in tomorrow
the link I have is from me testing the fix
ahhh
Will this page update automatically?
i think pastes are probably immutable
nah, but whenever Chris or Bella wake up and merge in the fix, the &aoc lb command will output a new link with updated results
maybe have an endpoint on pythondiscord.com redirect to the most recent leaderboard?
submit a PR :)
I know how to contribute, but I don't know how I would implement it
ah
If someone wanted to spend sometime and do a cute little page with dynamic results, we store the leaderboard in our redis cache. So theoretically we could pull straight from that and skip the paste service altogether
that would be cool
hmm interesting
theres no ||decision making|| in todays task right?
||its all just traversing a tree in a cyclic fashion||
yeah, if you're gonna store a url to the paste link it may as well just store the leaderboard itself and display it nicely
anyway, at 2am it is time for bed 
careful about spoilers
isnt that just the assignment?
i would argue that figuring out the ||cyclic|| nature of part 2 is part of the problem
ive only just started reading part 1, so i wouldnt know, if it is, im sorry
oh gotcha, and no problem!
just spoiler it lol
seems you have a good eye for the problem then
Yeah I got fumbled at the 2nd example of 1st part, ||cause I initially thought we must find the shortest route or sth||
maybe i should start to use libraries for this
so i dont have to make my own ||loops and trees||
although, i guess it doesnt take much time
i don't think this problem would be very expressible in e.g. networkx.
Wait do we even need those for today's challenge?
i dont know, but thats my solution
i feel like i would struggle to adapt all these problems to networkx. Before i realized it was the wrong solution, I wrote a custom ||bfs|| that of course never finished, but the logic was definitely right
i mean, you dont
you can just make it in a || list or a dict, or whatever|| i guess
now that im thinking about it, it probably just needs a ||dict||
yeah, I represented ||the graph as a [source, destinations] dict|| as I usually do
now that im thinking about it, i would probably just use a ||dict || while building my || tree||
guess that makes it redundant
unless its a P2 thing
i gotta say, it's pretty hilarious how the bot just does not care about spoiler tags. Isn't that right bot? ||tree||
spoiler? hardly know'er
|| santa ||
I'm assuming you're definitely not supposed to just simulate part 2 right?
||yes, you'll have to find a faster solution||
yo guys, rouhgly how big is the answer to number 2?
like what kinda ballpark is it?
Well I have an idea, time to get mathy
though this is gonna be the first time I implement the related algorithm sooo...
To debug hell I go
bc my programs currently at a billion... should i just stop it or is there hope?
||there is no hope||
like ||ten trillion|| actually
I dislike how many days of this year are like "this problem is actually much simpler than it would seem because the input is nice on purpose. nothing in the problem description reveals that, you'll just have to look at your input to find that out. If you didn't do that and started writing a general solution, well, sucks to be you!".
I generally like how AoC makes you learn to solve problems quickly, but I would prefer not learning how to solve problems incorrectly to be more quick.
i'm not sure i understand your critique
i felt like today's prompt foreshadowed what the ultimate solution needed to be
You mean, the example? I don't think so, as there are days on which the example fails to reveal the problem's complexity (e.g. day 1 this year), so "the actual input won't have caveats that aren't in the example" would be a bad lesson to learn.
are you saying you would prefer the example contained all edge cases that are present in the real input?
I think I mostly just want it to be consistent. As it is, if you want to be quick, you have to guess whether the caveats are there or not. E.g. in today's day, it'd be nice if the problem statement mentioned something like ||'the path always leads you back to the start eventually'|| - then it'd be unambigous what the solution is. As it is, today people who solve the general problem instead of a subcase of it (that the problem statement doesn't say it's limited to) will have just wasted their time. I think this is bad - it's teaching a bad lesson in how to generalize from examples to a solution.
hmm, i'm not sure i agree. I think adding that would have been a big spoiler. You already can see that it does that in the small example. I don't think it'd be good to hit you over the head with that
||the path always leads you back to the start eventually||
fwiw this wasn't true for the inputs (it was a slight variation that doesn't change the outcome), but arguably finding the patterns in the input that lets you generalize to it is part of the puzzle too
I disagree - I mostly want to write a solution should work for all inputs, not just the specific one I am given. There are cases where you can get lucky and not have some edge cases in the input that others do, like I did in d5p2.
after seeing part 2, I agree
tho I actually haven't done the puzzle yet
so my opinion may change
or like day 6, where some people had ||inputs where you could reach exactly d for two times, and some people like me didn't, so there was an entire edge case that we just skipped past||
I had a similar gripe 2021 day 24, but it was less bad because it was pretty obvious that brute forcing wasn't the method and you had to analyze the input
but i still didn't like it
2021d24 I probably did via a constraint solver, so I wouldn't have noticed.
i just discovered advent of code yesterday and i got a question
on the first day i compute that number with my code and then what?
do i just put that number in that textfield online or do i upload my code somewhere and it automatically checks?
and is it the same for any day?
just put the number in
you get your input from the website, process it yourself, and then upload your result to the text field on the website and hit submit, then part 2 will appear
nothing checks automatically, you can solve some problems with a calculator
you put the number in, your input is unique so it does the check for you (but your code is not checked)
yes
π
yeah you just get one number as the output, the challenge is meant to be solvable with any language so it's flexible like that
any brainf*ck enjoyers?
No
I dont think AOC is solvable in any existing BF interpreter
I mean there are jit/aot compilers
I dont believe they are good enough
I remember that one of them literally just compiles it to a state machine in C lol
even if you get their fancy jumps are O(1) rather than O(n), I would be surprised if they could get the same time complexity as a more conventional language.
but maybe I am out of date on optimised brainfuck
are we allowed to use any external packages like numpy or just builtins?
anything and everything
you are just asked not to feed the problem into chatgpt
don't tell me the input is literally ||an adjacency list||
@cyan sleet on the bright side, no language to install today π©π©
TIL, bash supports C style for loops (i = initial; i < cond; i += step), and maps!
but why is bash so slow even with the ||lcm|| solution
i agree that for this problem, non special input would be too hard, and giving the trick too easy
but ideally neither would be the case β it would just be a slightly different problem that's the right difficulty without simplification
how do i get the advent of code badge/role on this discord like some of you have?
[Day 8]
will it reach the end node only after full repetitions of the direction string or it can reach in, say 2 and a half repetitions?
what's your idea of slow?
my solution takes like 2 seconds total
it can reach in half
damn
turns out it reaches only in full repetitions, and also another detail
Mine also only had full repeats, so probably not luck but intended
Hmmm... My solution 100% would've failed if an endpoint appeared in the middle of the instruction
I can send you my input of you wanna test
sure?
||others also have told that it only takes full reps, and this is a very important detail (excluding another one)||
Today's inputs have so many weird assumptions you can make
i'll check once i get home. I had such a stupid bug and was debugging it for an hour so maybe my brain mixed my memories lol
oh yeah nvm. I checked my answer and remember my input instruction string had 263 characters, so dividng answer with 263 gave me whole number. So it seems like it made full repeats
But I coded my solution so it works even if it's not a full repeat
wait you solved part 2 as well?
not yet, had to go to university
But I read instructions and it doesn't seem that hard
Boy will I probably mess up lmao
If you're thinking about simulating then, uh, I'm sorry to inform you that (at least in my input) the answer was 14 digits long
so yeah, get comfy with associative arrays (and arrays in general)
it's my first time using associative arrays actually
I'm very thankful for eval
wait so i cant use 32bit int?
the input was luckily very similar to the syntax for inserting things
well... yeah, ints only go to like 2 * 10**9
You can just use a 64bit int though, which goes to like 9 * 10**18... unless the language you're working with doesn't have that?
ah thanks, Go does have 64bit ints
I have done unspeakable things to achieve 2d "arrays"
In what range is the answer of part 1? Cause I get like more than ||10k|| and itβs still running and it really feels like I just created an infinite loop
Mine was ||22k|| so don't worry
Guess I just gotta wait till I get home, my school Chromebook and online ide is way to slow for that haha
Can someone help explain how to do part 2 in a realistic time?
||16k|| here
What language are you using?
||cycles||
Hint: ||The solutions of the individual starts (like what you did in part 1) relates to the whole solution that considers all starts||
wdym, P2 is same as part 1, it just takes longer π
How
Python
Using a dict?
155ms both parts for me
I got an actual pc now but itβs killing the the process after ||150k||, I feel like now something is going wrong
150k is probably too high. I had nothing higher than 25k
Is it ||the lowest common multiple of each of the cycles it takes to complete each one?||
||π||
If you inspect the inputs then you can conclude that it works, which is probably the intended solution
If you only look at what the problem says then not so much, and you would've needed a much more complex solution
What node are you initiating with?
Wdym?
When starting off the simulation what 'AAA' - 'ZZZ' are you starting with
I used the first to last line, in my input itβs βVTMβ - βJDHβ
Thats the reason, you wanna start with 'AAA'
Oh I go from AAA to ZZZ in the input as well?
Oh yeah thatβs it
I feel stupid now π
If you look at the sample input the first row is 'AAA', if you look at your input it's not. Which means you wanna start at the row where 'AAA' is
Ty!
I would predict that is the reason your code keeps running without getting to 'ZZZ', I did the same mistake
i wonder how many ||loops || there are in the input
ive had ||6 starts|| so theres at least that many
what is the question
after doing p2, i agree even more
||i'm fine with some assumptions since otherwise the problem is not really tractable||
||but there were far too many assumptions today for my liking||
yea ikr
No idea what you all mean, just follow the directions π
Did you actually ||solve the full problem in the general case? LCM/product of each path is incorrect as per the problem statement||
Can you explain this a bit further, saw this somewhere else earlier, ||the part where LCM is incorrect per the problem statement||
Consider a ghost whose path goes ||a->b->z->c->z->c->z->z->z->z||, then your ||lcm solution|| will be wrong. ||no such ghost just happens to exist||
||it's not correct to assume there's a cycle||
Ah alright
well, there has to ||be a cycle, since there is a finite number of states - but the cycle does not have to be simple||
right, yeah
But the same way, there also isn't a ghost ||that takes such a route so couldn't you reverse the argument to this too||
Sorry for excessive spoilering, rather do too much than too little
right. but it just so happens to be that way. it's not guaranteed
Interesting day to say the least
i don't really like this problem for that reason, actually. i think that means i agree with stickie
damn pub agrees with me?
I think the problem statement should be the complete description of the problem, and the input should use the ||full extent of the problem statement to test that you implemented it correctly, it should not expand on the problem statement, making it easier.||
as a side note, bash functions are π₯΄
"what did you do for AoC this year?"
"create unspeakable horrors in bash"
it's actually not too bad
the input was nicely almost valid syntax
so i just sedded it then evaled it
a technically incorrect assumption being the only feasible way to approach the problem is meh
||my main gripe with it is that one of the assumptions doesn't even make it that less feasible
making the offset a multiple of step length but different from the cycle length would still be feasible with CRT, and i wouldn't be as annoyed||
that was nice but that was a later puzzle
for a day 8 puzzle I think the difficult is ok
my opinion is that you shouldn't take a hard problem and adjust the difficulty to fit an easier day by putting in assumptions about the input
i would've enjoyed doing this day without the assumptions on a later date
You don't need to "assume" anything though. Analyze, yes, but that's not a surprising part of problem solving imo
sure you're exploiting a pattern you observed, but it's technically incorrect
Idk, I don't agree that a solution necessarily needs to be able to handle all kinds of input. Story-wise, there's just one input - not multiple - so you'd analyze it and solve the situation accordingly π But yeah, it's more satisfying to write general solutions
by assume I mean anything that isn't there on the problem statement and has to be gleaned from the input
I am somewhat ok with two of the assumptions today, but the third is just
||i feeel like the fact that u had to derive that it cycles is kinda dumb||
nowhere did it say ||it cycles||
careful, this is not the spoilers channel
oh oops sorry
Doesn't this clarify that?
"Of course, you might not find ZZZ right away. If you run out of left/right instructions, repeat the whole sequence of instructions as necessary: RL really means RLRLRLRLRLRLRLRL... and so on."
||you wouldn't, and shouldn't, expect the starting offset to be the same as the cycle length, and it doesn't even make the puzzle that much harder, and it awarded people who incorrectly thought "oh i just need to lcm the starting offset/cycle length" and didn't think about CRT, and checking if starting offset == cycle length is such a weird, unusual thing to do that I don't think it should've been an assumption today||
i feel like that's more of behavior w the instructions themselves
||you had to derive that Z cycles, and only one Z per cycle||
I find scanning through the input and trying to find some janky way to "scam" a solution out of the problem remarkably unfun.
||cycles are basically guaranteed by assuming a large enough answer and pigeonhole principle||
Well you can analyze it with code though
of course I can, but that doesn't make it interesting. I should not have to double check whether each possible case actually happens in the input.
shrugs Different perspectives I guess π
i feel like the most fun problems in past years have been path finding problems like flood fill and all or like
snailfish was really fun
and day 24 2021
the arithmetic one
@mossy basin your visualisations are amazing, good job! π
from the perspective of solving the problem blind, you have no idea which assumptions you should be checking imo
thanks
for stuff like day 24 of 2021, the assumption is kinda ok, because there isn't much there to do other than analyze the input
for today, I would not have batted an eye if we had to solve the general case
especially given the difficulty spikes this year
2021d24 also literally tells you to decompile it.
I feel like ||6 and 7 went down in difficulty quite a bit||
yeah
I did have another gripe with 6 because of the lack of edge case testing for some inputs
but that's a separate matter
do you mean day7 with the cards? or what edge cases are you thinking of?
Or more like day 3 and 5 were way too hard haha
You can see from statistics how many ppl dropped the challenge in those days
day 1 3 and 5 were the hardest so far
uncharacteristically difficult for those days
day 1 is hardest day 1 I've seen for years
to me day4 was hard as well because I was determined to ||write a recursive solution but I have never practiced recursion||
I think recursive should be avoided in general
Loops are safer, imho
tbh I couldn't think of how to write the loop solution, ||recursion|| just made sense to me for that problem
I normally change recursion into while loops with a couple of flags
loops are antiquated and should be deprecated, tail recursion is the way π₯±
source: i use functional languages
Idk, I just find recursion very hard to debug
The order of what's happening in recursive loops is hard to track for me
I like while loops
It takes me a while to come up with a recursive solution
I'm kinda surprised people went for it for day 4
I have an iterative solution that looks fairly reasonable
Do you get any prizes for doing well in Advent of Code>
If you get all 50 stars, you get a cute Advent of Code Completionist Role for the month of January
alright!
I like to assume that the function is already perfect so I only have to think about getting from one case to the case immediately before it
Just gotta think of the function as running backwards π
it's nice to think inductively. how can i create the n=1 case from the n=2 case, etc
i never had to use recursion. though I use G'MIC as main, and in the math parser, recursion isn't possible most of the time, so I always have to figure out a iterative solution. by then, when I think of solving a problem, I always end up solving it anyway with no recursion.
I use recursion all the time, I find it more convenient then rewriting an already correct function into a loop.
my ||range splitting solution|| used recursion, for example.
i'm thinking of solving day 5 part 2 by using a while loop to modify dynamic array or list of values, and if the last value of first index reaches the minimal, I then find the minimal values from what point. kind of like modifying all the dynamic array until the last value first index reaches 0.
hmm, i need to figure out how to split a range given ranges here. Hmmm, I"ll think about that
One message removed from a suspended account.
is it to do with Advent of Code?
I never use recursion unless the solution screams for it, personally
Python feels like an iterative-first lang
Sometimes recursion is obviously called for though (e.g. parsing recursive structures) and then I will use it
One message removed from a suspended account.
the answer to my question is clearly no then
this is the wrong channel for you, please look at #βο½how-to-get-help in order to open a help channel for your question
there's languages better for recursion? why would some one use them in that case?
there are people better than me (and almost certainly in this channel) to answer this, but I'll have a go
Functions that are recursive-first (typically functional languages) have features geared to recursion. The key one that comes to mind is "tail call optimisation"
Python doesn't have tail recursion, which feels like an easy answer to why it doesn't necessarily handle recursion well. Without using cache I feel like it's easy to run into a RecursionDepth error for any moderately sized problem/input
^
Then if you want to use cache, you need to make sure you're using inputs that can be hashed. That could result in having to finetune your data structures a bit
I'm probably going to butcher this explanation, but "tail recursion" is where, if the last line of a recursive function is the recursive call, you don't add another stack frame
I think
side eyes dataclasses
I just slap frozen on it and it's never failed for me so far (though I'm sure one day it will)
Also it's worth mentioning that the creator of Python typically is not too much into functional programming and recursive style
map, filter and reduce were almost not going to be in Python 3, for example
(in the end reduce was downgraded out of the std lib built ins to functools)
A valuable aspect that makes recursion significantly easier to think about is functional purity - a functions result only depends on its arguments, and it only returns a result, doesn't modify any global variables etc. At which point, recursion get less "leaky" as an abstraction, and you can mostly just call the same function as you would any other helper function. functional languages tend to make pure functions the default, or the only kind of function.
if every 5 days is hard. i bet day 10 is going to be about writing a OS
today looks super cool. looked at part 1 and thought it was trivial, given the input is ||an adjacency list|| and all xD
thought maybe part 2 would be ||disregard instructions, find shortest path|| but i was like, "||isn't that a lil too textbook :P||"
and wow does it hit me with a twist! i'm currently thinking ||cycle detection and least common multiple||, but i complete forgot ||how to do the former ... need to brush up on graph theory|| xD
can't wait to see your solution!
Tip: ||you can reuse first part||
oh man this is harder than i thought
i think i can go for a clunky solution under the ||very jank, yet (at least for me, i have tested) correct assumption that for every starting node, using the instructions to traverse the network will certainly encounter a cycle, during which a single, unique ending node is encountered||
Well if true then it wonβt be as hard as you might have thought :)
@minor cave what does this mean
but i don't like it π©
this assumption is so specific
it feels like cheating, honestly :P
what if, in a more robust version of the problem with multiple test cases, ||all ending nodes are reached before any cycle commences? some starting nodes don't fall into a cycle at all? two or more ending nodes are encountered in a cycle?||
of course, ||all the above are not true for my puzzle input|| :P
but still
It is often the case that the input is crafted specifically with assumptions in mind
For better or for worse
that's a great point
so at the end of the day, we go back to rule #1 of programming
if it works, it works
If the day has assumptions then Iβll often write assertions to prove the assumptions hold
oh great idea
And document that the solution only works for those assumptions
And write unit tests to prove that the exceptions are raised when the assumption breaks
kk, i think i'll do just that
time to take a break and watch movie today :D
will resume with my janky solution tomorrow lol
i use visual debugging and parameter checking and a bit of hypothesis checking to see how is my code is going, and then if i see it working well, i continue.
Thatβs perfectly fine too :) Iβm just going OTT for my solutions
Honestly for P2 I did that first before I wrote my test
Itβs one of the areas where TDD didnβt work so well for me, because you donβt want to write tests just to find that the assumption is trash
I did just start incorporating tests early in the day myself. Not so bad when you've got the samples and their answers.
does anyone know some good graph libraries for the usual type of AoC graph problems that will appear in the near future? I'm looking for something that handles DFS BFS and potentially shortest path type stuff?
If you mean visualization, then networkx is a popular choice
If you mean one that contains actual implementations of these algos then idk
I opened up a thread in #1035199133436354600 if anyone already did day 3 and would be willing to guide me in where my current logic has gone wrong
You can take a look at my solution: #1180738420272799814 message
If you're around I can look at your code after I finish tonigh's puzzle
I got help, thank you though! I was trying to avoid just looking at solutions and seeing where I might have missed something in my logic, turns out when constructing numbers my program only checked surrounding indices once it hit a non-numeric character, which doesn't work when the number reaches all the way to the end of the line and resets it.
Ah cool. congrats.
After you're done though defintly look at other solutions for new ideas.
GLHF everyone!!
Language Roulette: Day 9
The language is ... Scala
the prophecy
<@&518565788744024082> Good morning! Day 9 is ready to be attempted. View it online now at https://adventofcode.com/2023/day/9. Good luck!
oh wtf it's time?
ooh finite differences
_I still don't even understand the problem and you're done already
_
holy crap still in the middle of the second michael buble song
I can't even understand what the question is asking...
That leaderboard was nice and fast
Spoiler channel?
268/133 ._.
Made a silly mistake that slowed me way down for p1
god damn, can't even look away for 10 minutes
Right? I was modeling the completion time and went, "That means it should be done by 5 minutes past the hour. What time is it? Oh, it's 6 past the hour let's check the lead--it's full."
doesn't this mean the leaderboard didn't meet your expectations?
No, far from it. It means my copy-paste foo is too slow to keep up
i mean sorry if i'm not reading that message right but it appears you thought it would fill in 5 mins but it filled in 6
that was relatively easy
No by the time I finished running the model it was already well past when the leaderboard filled
oh lmao
I was genuinely settling in for a 20-30 minute leaderboard fill time
right? Awesome that it filled so fast but I've been looking forward to predicting the leaderboard filling up, and it's just been too quick most of the time
The times to fill each day have been so variable compared to prior years. Difficulty is all over the place
It's a weird balance of parsing and math (granted I've only got one star this year so I've been mostly watching comments on it) but it's nifty to see how this year feels different
Yes. Top 1000 for part2.
When doing part1, assumed I'd need to get 100000'th value for each row or something, which would require something more efficient. As such, ||I decided not to bother with the supplied algorithm, switched to python, and used numpy.polynomial to derive the formula, which would give me an easy time in part2||
result: ||I was wrong about what we'd have to do. Still, managed part2 in 30 seconds (would have been less but reran it on sample input after gave suspiciously small answer before submitting||
The difference between getting the first star and the second star each day is really wild
Today's is like, the same though
And it's interesting that the person who got global 1st on Part 1 didn't even place for Part 2
Yeah that should have been part 2 βΉοΈ
thats sort of what i was expecting too
Or it could be easy again, who knows
Weekends (utc-5 time) tend to be harder than weekdays. For people many time zones ahead like myself, that tends to be Sunday and monday.
Spent 40 minutes debugging the problem only to figure out I didn't handle ||negatives|| in input parsing 
I did abs(b-a) instead of b-a while debugging and forgot to remove it
yeah. i'm surprised too, but then again Day 5 Part 2 is a real PITA
today was probably the most uninteresting part 2
I almost feel disappointed. I thought today would be a hard day, I blocked 2-3 hours for today's problem, and this is the problem that came up
I don't know how they even comprehended the problem statement that fast.
Dont worry, you wont be dissapointed anymore one of these days
π
how about use the rest of the free time to solve past year AoC
- unless you've done all
Yeah, doing that right now π
I know.. but I blocked some time today for aoc you know..
Same. But I'm too slow of a reader in general, I know I'll never read fast enough to keep up with the global leader board so I've made a made of modeling the leaderboard instead
Yeah you can use the rest of your time to solve past puzzles or optimize your current ones
I didn't even finish reading and comprehensing the puzzle and the leaderboard was already filled
Maybe we need a leaderboard for mortals.
There are various leaderboards. There's 2 for reddit, 1 for discord I'm on, And another one I think is for streamers or something I'm not sure why I'm on it.
I only recognize my name and jp
Have you finished past years already, I can give you a past year probelm that was harder
beacons or snail math were both a lot of fun
does anyone here know any java?
i cant do day 7
well, im just getting the wrong answer
but i really think it should be working
Why are you asking about java in a python server?
i mean, a lot of people can do two languages, i thought it might be worth asking lol
Well, dang. Never thought I'd have this much difficultly on the day 1 of the advent puzzle, lol and I'm trying something new I guess to learn, outside of doing my main project that I'm kinda stuck on.
Dang, I really should have gone for trying 15 minute projects and slowly build up, rather than just go for major ones but advent of code seems fun
I only know the basics, but the people at https://discord.gg/WEnkdVMQ will know much more
oh bet
what are you stuck on? whats your approach
usually the puzzles get harder as the advent goes on but this year the difficulty is a bit all over the place
Right now, I'm looking at puzzle input, and I've converted entire thing into a rows of string to be put inside a variable, and I'm working out the best way to pull the numbers from the list of strings and then using sum to get the final number that I can input to get into 2nd day.
If my approach is wrong, then sigh, I'll figure out a different way. I'm googling all over the place without using ChatGPT
Feel free to post your code in #aoc-solution-hints if you want help
Will do after much headscratching and if I can't find a solution.
which year and day is it? let me know
Googling "advent of code [thing]" will get you the right puzzle most of the time, beacons and snailfish numbers are 2021 day 19 and 2021 day 18 respectively
thanks
https://adventofcode.com/2021/day/18 snails!
https://adventofcode.com/2021/day/19 beacons!
nice
At some point I need to transfer my account to another one (next year perhaps)
my username looks a little silly next to everyone else on my work leaderboard
I'm almost certain no one at work authenticated through Reddit lol
I'll probably switch to Github
you have a work leaderboard?
yup
majority of people have like a proper name, and then there's me with my Reddit account lol
reddit/email usernames are easily in the top regrets of anyone
I'm still π₯΄ about using my proper name for stuff online
but it'd probably be good for finding work
wait really?
if only 450 stars on aoc was enough to get a job
didnt know AoC has employability value
nah lol - but it's something you can use to show off programming skills
right
and it helps get practice for actual interviews too
you might be asked these kinds of questions
true but everyones grinding away on platforms like leetcode
its kinda sad that leetcode type questions have become the standard for interviews, but understandably theres probably no other easy / short / objective method to evalutate candidates
I wish I was more interested in leetcode/dsa in general, but tbh I just hate it
dsa is actually interesting, its the grind part that i dont like
Yeah I agree, I'm fine with dsa but I'm not really into competitive programming
same
I'm somewhat into competitive programming, but that might just be my interest for maths leaking into it
I suck at cp anyways so 
although i see leetcode like some sort of puzzles to solve just like AoC
I'm not really into competitive programming but I do enjoy AoC
But aoc is more fun π
agreed
difficulty is nicely scaled and I enjoy the community around it during Xmas
yeah I like aoc/codewars style puzzles more
I like well made codewars ones
so relatable
I get to write my own answer, and then I enjoy code review and debugging other solutions too
Yeah, it's like leetcode but more casual
wow
it's a shame I'm always on holiday during december
I avoid jetting abroad during Dec
my family is overseas so I kinda have to
tho this trip is different
we even have a .challenge command on sir-lancebot for it
is someone tyring to send code lol
Seems like it
graduated aus hs, and it's a tradition over here to go on a trip with ur school friends after that
sure, i'll take a look into it
Is this related to Advent of Code?
#βο½how-to-get-help to get help
k
You could ask in #1035199133436354600 , but don't expect people to write code for you
!rule 8
8. Do not help with ongoing exams. When helping with homework, help people learn how to do the assignment without doing it for them.
I've just learned about the rule not to share your puzzle input on github, I had to do a quick purge π°
ideally you should remove it from git history too
how do I do that
I forget lol
apparently according to SO you should use the third-party tool git-filter-repo
then when you install it you do you git filter-repo --invert-paths --path <path to the file or directory>
...or if you don't care about history just transfer to a new repo and start again
let me look at mine wait
251mil d7p2
it's pretty close to p1
oh day7 sorry
perhaps you mean d8 p2 which is a more reasonable day to ask such a question
what, my P1 was in tens of thousands
no i mean D7
wait
todays the eight
yes, i do mean D8, im sorry
(yesterday's the eight)
okay so I was right π part 1 tens of thousands, part 2 tens of trillions
aanyway yes d8 is in the tens of trillions for part 2 and tens of thousands for part 1
okay, thanks
today was so easy people be discussing about previous days
I still don't know a satisfying solution to d5p2.
are there any people from global leaderboard here?
they might be onto something... right?
range splitting
calculating intervals is pretty satisfying to me
is that the only way?
bruteforcing is possible
but that isn't "satisfying" per se, is it?
I meant day 3, oops
apart from bruteforce ofc
I think some people also said something about dfs from the back?
Honestly d5p2 felt really easy to me
ah
If I knew how to write Multiline functions in APL, I would be done fairly quickly
I think the name numbers and combine them -> iterate over gears method was pretty satisfying
from what i've seen, part 2 solution is always a not-so-major change to your part 1 solution if you had chosen the right method from the beginning
That's what I did in Haskell, but it didn't really feel great. I would want a solution that finds them without duplicates in the first place, not one that just removes them.
i honestly don't understand what i did there π¬
i anchored around the gears, which made things easy
It wasn't difficult per se, though my code was pretty horrid. Just felt inelegant
for each gear, detect all numbers within a certain span??
i feel like im doing AoC wrong
i made a grid object which held references to every cell, and part that cell belonged to
did you anchor around numbers?
No
ah
I kind of want to try doing it with a proper graph kinda thing
I used a 2D array and the entire file for day3 was around 100 lines of Go
oh yeah, I didn't have a lot of code either.
I think a neat solution would be systematically 'melting' away numbers and gears as you iterate over gears
tho that wouldn't quite work for p2
my idea was to have almost an undirected grid graph, but merge digit nodes into one big number node
then both p1 and p2 get trivial
I want to try my cursed convolution method for p2 sometime in the future
ahh yes, that does sound satsifying already
never thought about convolution
my d5 is almost entirely convolution (though it is like fancy APL convolution, not the basic multiply and sum)
there's the neat method with convolution where you preprocess and pack numbers together and then convolve
and then there's my method which operates on the array with minimal preprocessing (turn the symbols into numbers, and have a shift of +1 and set empty spaces to 0)
but has 12 convolutions and a whole bunch of masks afterwards on the convolved arrays
okay, day 9 was super easy, i need to return to day 5 today and possibly finish it
best of luck! let us know if you need any assistance
Well that algorithm choked 2 hours out of me
lucky for you it was only 2 hours
took me something like 3-4
The majority of the time was spent looking for when things went wrong
ditto
Cause the ranges got splintered more and more after each mapping
I had a really fun time doing that day actually
it took me like 1-2 hours as well but I really enjoyed it
Yeah I really enjoyed the first hour too
But past that and it started to get stale for me
I found it quite fiddle-y which gets annoying after a while
I figured out the range stuff resonably quickly, but then I ended up adding some of the splits into the wrong list and that sent me on a 6hour-long journey of rewriting everything only to realise I had to change one variable name and I would have been done -.-
surely fiddle-y stuff is your forte, right?
apparently not!
agreed
I was spending forever trying to remember how to do CRT before I saw that everyone was already done
and then was like oh, what
luckily I had spoiled myself by looking at code golf chat earlier that day
saw them using lcm
and was kinda confused how they did it
I didn't know that math had an lcm function, so wrote my own broken version -- luckily it worked π
Lol
that seems quite nontrivial
I guess it's not
You can do two numbers at a time I guess
you write it for 2 numbers and then you map it onto (previous result, next number)
Yeah I thought it was nontrivial for a sec because lcm(a, b, c) != abc/gcd(a, b, c)
well, i factorized the numbers (poorly) and found the common prime factors
but if you just fold then it's trivial so
ah yeah that works
well that's just gcd
I wonder what the relation actually is
what does this mean? I can't get 50th star because I didn't solve previous days? Is it usually like this?
Yeah it's always like that
Last year I lost a point on Day 25 because I choked and someone clicked the button faster than me
oh I guess it's lcm(a, b, c) = abc/gcd(ab, bc, ac)
I just realized you are one of the top coders in the leaderboard. Could you please let us know how do you guys solve a problem before us humans can't even finish reading the problem?
Took me 2 hours to realize
Then a couple more mins to solve it since I recycled part 1
π€ͺ
People going for the leaderboard have done a lot of prep writing a bunch of functions for stuff they expect to see come up
Thereβll also be code to programmatically retrieve the input and post the answer
I mean, these don't really help unless you're actually good at problem solving
Well yes they have that as well :)
the guy that solved today's questions as 3rd is copy-pasting the input manually π
still, solving these in 2 minutes is incomprehensible to me
Maybe they could have gotten second if they used aoc-lube :P
hey i used to do that
I still do it...
I'm hopping between two laptops while working on the solutions and I want all of my random envs to be able to run the solutions, so I never installed aoc-lube
I could just set my stuff up better but π€·ββοΈ
I donβt use it either tbh
I never go for lb anyway since puzzles open at 5am for me
western europe gang (I guess some of Africa would be the same timezone?)
I prefer to go for most verbose solution instead
for me it's 1pm, you might say it's convenient but actually not really since I might have existing schedules at the time
Yeah, Morocco is UTC+1 for example
I donβt think thatβs convenient for the majority of people lol
But at least you can get started on it quicker after your existing schedules
West Europe is one of the worst cos if itβs a weekday then I have to wait all day to complete it, if I donβt want to get up at 5am
kind of reminds me of the last guy from here
I am 100% the guy at the top lol
Lol today's part 2 was just ||reverse input||
I'm above the guy on the top π¦
that awkward moment when the 200k/year in an eastern european country is in a currency that is 1:30 weaker than euro
Ive completed the first 4 days, but got busy with work so havent done the rest. How brutal are the next 5
I had a good laugh reading these π
don't let 5 prevent you from trying the rest π
i am 50% the top guy
the only changes are that i use notepad and print() instead of a full IDE and a debugger
How comes you use print instead of a debugger ?
works in notepad
and terminal
Yeah I worked a 12 hour day, opened day 5 and decided my time was better spend asleep
Even in terminal you can use a debugger - such as pdb
But it might be good to use VS Code or PyCharm (or another editor of your choice) and use a debugger for that
i don't know how to use pdb
print() usually works well enough
You do you, but debuggers are amazing
Donβt know how I lived without them
Itβs basically print without actually having to type print all the time
i know
but i had a problem with speed in the IDE i used
in another different language
doing a different thing
what's your go-to debugger for vscode?
Here, have a free βskip a dayβ pass π³
I believe you just install the Python extension and then youβll able to use the debugger inside the app
Personally I use PyCharm which has that all set up though
well i have some issue with PyCharm debugger's stuff
ah I see, I have to set it up somehow...
my friend likes pycharm, I should probably switch but I already got used to vscode
May i know which edition you use for PyCharm
Just community.
Curious - what issues do you have?
the debugger just wont work
Both are excellent choices - use the one you prefer
Hmm - could be a few issues why that is. Hit me up in #editors-ides if you want to go over it more
well I'm off to work for an hour in the middle of a storm... it's not like I needed a weekend to rest or anything
On AOC or actual work?
actual work π₯²
waiiiit WHAT
i totally forgot
it didn't cross my mind at all
banned
nooooooooooo
yo guys, rlly quick question - how do i increment a global scope total variable from inside a function?
you declare total as global
OMG YEAH TY
like so:
total = 0
def some_func():
global total
total = 1
there are probably other better alternatives but
global total at the top of the function
Global total
YES THANKS GUYS
Ah my eyes
is it that bad π
what--- why--
Itβs a gratuitous global so yes !
Eric, the author of AOC, has requested people not to do it
Multiple inputs is one way he prevents people ripping off his content
where did u find it
wow that makes sense
Can I copy/redistribute part of Advent of Code? Please don't. Advent of Code is free to use, not free to copy. If you're posting a code repository somewhere, please don't include parts of Advent of Code like the puzzle text or your inputs. If you're making a website, please don't make it look like Advent of Code or name it something similar.
thanks