advent of code 2020 day 8
day 8 was pretty easy
https://github.com/undergroundmonorail/advent-of-code-2020/tree/main/day%208
you can tell i like functional stuff more than the average python user because i had to write this:
def first_true(it):
for e in it:
if e:
return e
i thought i could use any() for that, since it's basically just applying or over an iterable and or short circuits when it gets a truthy value, but any() returns a literal True or False while i actually needed the truthy object
advent of code 2020 day 9
catching up on aoc
day 9 solutions kinda suck but here they are. they do work i just feel like they're very naive
https://github.com/undergroundmonorail/advent-of-code-2020/tree/main/day%209
advent of code 2020 day 10
so this was a weird one
i read part 1 over and over again because i was like "i must be missing something, there's no problem here. where is the programming challenge" but no it's just... nothing. it kinda tries to confuse you with stuff like your adapters being rated for a difference of 3 jolts but since you know every adapter has to be used, that's completely irrelevant to you. the jolts can never go down so you just sort the list.
i still managed to overcomplicate my part 1 solution but you could write it in a much simpler way. i just chose not to
my part 1 and 2 answers are almost nothing alike
https://github.com/undergroundmonorail/advent-of-code-2020/tree/main/day%2010
advent of code 2020 day 10
in part 2 i didn't bother to stick around and see if a naive recursive solution would ever finish. i let it go for a couple seconds to see and after that it wouldn't even respond to ^C, i had to close the whole powershell window
luckily it runs instantly when you just put the functools.cache decorator on the naive recursive solution
advent of code 2020 day 10
so this is probably what was intended for part 2
but i did make it completely unreadable
https://github.com/undergroundmonorail/advent-of-code-2020/blob/main/day%2010/part2_alternate.py
unfortunately, as clever as the idea behind this solution is (i didn't come up with it lmao), i just threw a cache on the recursive function and it worked just as quickly
this one works without a cache though
advent of code 2020 day 11
advent of code 2020 day 12
extremely simple day. only thing that gave me trouble was just forgetting that the waypoint starts at (10, 1) for part 2
i didn't get to reuse any of the actual computation code though, just input parsing
https://github.com/undergroundmonorail/advent-of-code-2020/tree/main/day%2012
advent of code 2020 day 13
i want to say something like
maybe you only have to check "near" multiples of the LCM? for whatever "near" means. but that doesn't seem right
maybe something like subtracting out the offsets, finding the LCM, then adding the offsets back in somehow? no, that doesn't make sense either
advent of code 2020 day 13
no it's too hard to do it in my head, i'm going to do it here
the chinese remainder theorem lets you find x for a system like
x = n_1 % a_1
x = n_2 % a_2
x = n_3 % a_3
etc
let's say i have an input of something like `5,x,7`. that means i have to find a timestamp where timestamp % 5 = 0 and timestamp % 7 = 5 (i.e. -2)
but if timestamp % 7 = 5, that means (timestamp + 2) % 7 = 0
so in this case i'm looking for numbers that satisfy
0 = (x + 0) % 5
0 = (x + 2) % 7
which is *so close*
advent of code 2020 day 13
i want to just like
do it
like can i just...
0 = (x + n) % bus_n
-x = n % bus_n
...no that doesn't make sense. n % bus_n is just going to be n pretty much all the time, and -x means something completely different when it's congruent to something modulo whatever so when you resolve that they'll all be different again
advent of code 2020 day 14
yeah yeah i haven't finished day 13 yet, shut up i'll get to it
https://github.com/undergroundmonorail/advent-of-code-2020/tree/main/day%2014
easy day, i put in more effort than was actually required but it was fun. while solving part 2 i got an idea in my head like "could i write a recursive function that handles the floating bits at the same time as the conversion from binary to decimal" and sure enough, here we are. took a couple swings at it even after i got one working and i'm proud of how it came out
advent of code 2020 day 13 2: electric boogaloo
going back to this
after talking to emi it turns out i was extremely close to what i wanted
for a bunch of busses with offsets and ids, i had
0 = (x + bus_offset) % bus_id
and was struggling to get x on its own
the problem was that i was thinking of modular arithmetic from the way it's used as an operation in programming, not the way it's used in math: a fact about the entire congruence
so the way i get x on its own is just...
x = -bus_offset % bus_id
oops
advent of code 2020 day 13 2: electric boogaloo
okay i solved it
it involved an algorithm that i understand the broad strokes about why it works but don't really get the details of exactly, and it's a very naive implementation of that algorithm (i'm sure there are nicer ways to do it in python but... you'd need to understand the details exactly)
but it's done https://github.com/undergroundmonorail/advent-of-code-2020/blob/main/day%2013/part2.py
re: advent of code 2020 day 15
@monorail no
re: advent of code 2020 day 15
@noiob oh
...oh you know what i did
i just replaced "2020" in the loop in my part 1 solution with "30000000" and then replaced the body with a = 'test', just to see
but it completely escaped me that my loop was while len(spoken) < [my number]:
whoops
re: advent of code 2020 day 15
@monorail lol