8 ms·
I really enjoyed the early part of this last year, but I got to Day 19 and suddenly it became "if you memorized some mathematical concepts and an obscure algor
by bussierem 5y ago
I really enjoyed the early part of this last year, but I got to Day 19 and suddenly it became
"if you memorized some mathematical concepts and an obscure algorithm and also recognize that this exact algorithm is the only efficient solution to the problem then you can solve this in 5 seconds, otherwise it will never finish running with any other algorithm".
I immediately quit. I'm not doing these to prove I'm smarter than other people or memorized random math concepts, I'm doing this to practice writing code or to learn a new language.
Not sure if this is indicative of other years (This is the farthest I've persisted in the 3 I've tried) but it was EXTREMELY demotivating, and killed every desire to continue or to even try it again next year.
*EDIT*: Apologies, I was incorrect on the Day where this happened. It was actually Day 13, with the Chinese Remainder Theorem being the solution. I must have copy/pasted a solution in frustration and continued past that point. My mistake.
- petercooper 5y agoAt the time, I had the same thought process as you. I did eventually come back and do the rest of the days though which were surprisingly trivial in comparison! I seem to recall some people did manage to solve that day using brute force with a non modular approach though.
- bussierem 5y agoI'm quite surprised, I spent hours on multiple different solution and every single one was brutally slow.
- petercooper 5y agoMy memory is hazy, but I seem to recall it involved a lot of parallelization and running it for a couple of days on high end gear along with luck. So definitely not the intended approach! :)
- TYMorningCoffee 5y agoFor Day 13, I played around with the numbers and eventually noticed that you could increment by the product of the numbers you consumed so far.
- jstx1 5y agoI see it as on opportunity to expose yourself to a bunch of things in mathematics and computer science. Also, I'm pretty sure that you could get to the solution you're referring to without knowing any number theory at all.
- tyingq 5y agoLink to last year's Day 19: https://adventofcode.com/2020/day/19 https://adventofcode.com/2020/day/19 I didn't read it in depth, but it feels like you could build regexes on the fly to solve it. Perhaps I missed something crucial. Edit: Ahh, day 13: https://adventofcode.com/2020/day/13 https://adventofcode.com/2020/day/13
- CastFX 5y agoI loved day 19 because I managed to use some Automata theory I studied at uni. Something like, I cannot simply use a regex because it's a context-free grammar. Then I learned about recursive regexes and how they could be used to parse a cfg. Aaah fascinating, really.
- Jtsummers 5y agoPart 2 complicated it, but yes. I just built regexes on the fly for Part 1. I wonder if they mean Day 13. The underlying math is based on the Chinese Remainder Theorem, but it is solvable without knowing it (or, in my case, "knowing" it, once I saw others mention it it came back but my math degree was a long time ago). A solution could be discovered incrementally without knowing the math by trying to optimize the naive version.
- bussierem 5y agoI did mean Day 13, thank you -- I updated my post accordingly. Sorry about the confusion!
- bussierem 5y agoApologies, I updated my post. It was Day 13 where this happened. Not sure why I stopped at Day 19, tbh.
- ZiiS 5y agoDay 13 you really needed to know of Chinese remainder theorem; I would say this was probably the only day in the last couple of years so dependent on non-trivial maths. I would still recommend AoC though.
- hu3 5y agoI had the same feeling about https://projecteuler.net/ https://projecteuler.net/ but PE is very clear about being math focused so that's on me. I wish Advent of Code puzzles were strictly algorithm focused without relying on specifics of mathematics. Skipping puzzles is demotivating for the completionist in me that lacks time to re-read math books.
- Buttons840 5y agoWe should avoid certain questions because they're demotivating to some people? Perhaps a compromise would be to start with an easy input that any pile of if statements can handle, then give a longer input that will break all but the best algorithms as a bonus.
- bussierem 5y agoI think it's more that the puzzles should avoid having a "correct solution" in the form of a known algorithm. If the puzzle can basically only be solved by remembering a specific algorithm, and any other algorithm (or attempt) will grind for hours, then the puzzle isn't about algorithms, or about coding, it's about whether or not you memorized a part of a math textbook and can recognize that it applies to the problem. Granted, I don't know the process of AoC in terms of vetting and building their puzzles, but it seems that the person/people involved all share very similar levels and domain of knowledge. Having more people reviewing or involved in the process that have a wider range of skillsets might avoid these situations. Example from what I was talking about before: Day 13 of AoC2020 was basically "the answer is the Chinese Remainder Theorem". If you remembered that...great you could solve this in 10 seconds (hell some languages have a _function_ for that theorem!). If not....well good luck finding a solution that runs in under 6h. That has nothing to do with _programming_. Its just math, there wasn't even programming involved (literally some solutions were just "parse the input and pass it to mathlib.chinese_remainder()"). That's not satisfying to solve for the majority of people, I feel (opinion, I know).
- Joker_vD 5y agoIs this CRT? Not exactly sure, but it does not run for six hours: result = 0 addend = 1 for divisor, desired_offset in [(7, 0), (13, 1), (59, 4), (31, 6), (19, 7)]: # keep trying numbers until we find the one that, with # the desired offset added to it, would divide without # remainder while (result + desired_offset) % divisor != 0: result += addend # adding another addend should not break previous results # so make it divisible by all previous divisors addend *= divisor result %= 7*13*59*31*19 # Is it really needed? Eh. print(result)
- estomagordo 5y agoI'm sorry you were coerced into thinking :(
- Buttons840 5y agoDoes every problem need to be solvable by everyone? Project Euler used to say something along the lines of "not everyone can solve every problem, and that's OK". Looks like they've removed that statement though. I remember encountering it early in my career and realizing some problems I cannot solve, even though others can.
- vbezhenar 5y agoIt's pretty daunting when you're invested into something, spent a plenty hours only to realize that you're not in those 5% who's going to complete this challenge. IMO AoC should strife to be completable by 80% of programmers (number is out of thin air, but you got the idea). Project Euler is a different beast. Of course that's just my opinion.
- Epitom3 5y ago> IMO AoC should strife to be completable by 80% of programmers What would be the point then, it will be just another leetcode
- auxym 5y agoFor what it's worth, I'm not a (professionnal) programmer, and I can usually solve 80% of the AoC problems intuitively. That's OK for me. For the other 20% where I don't even know where to start, I look up a solution on reddit, try to understand it and re-implement it myself, and learn something new. The 2020 day 13 problem mentioned by GP was indeed one of those for me last year.
- ollien 5y agoHonestly, I didn't even understand how the CRT applied even after knowing it was required. This visualization[1] is what eventually helped me solve it. [1]: https://www.reddit.com/r/adventofcode/comments/kcl7d2/2020_day_13_part_2_buses_in_a_slot_machine/ https://www.reddit.com/r/adventofcode/comments/kcl7d2/2020_d...
- progbits 5y ago
- justinsaccount 5y ago> if you memorized some mathematical concepts and an obscure algorithm and also recognize that this exact algorithm is the only efficient solution to the problem then you can solve this in 5 seconds, otherwise it will never finish running with any other algorithm well that's just not true at all. I had no idea WTF the Chinese Remainder Theorem was and just worked out the issue iteratively. All you had to know was that if you are trying to find some large number that is divisible by other prime numbers, the deltas between the candidates will be the product of the numbers. as in, if you are trying to find a number that is divisible by both 37 and 41, you really just need to find numbers divisible by 1517. I forget what the name for this mathematical concept is, but it's far less obscure than the CRT.
- boutell 5y agoYes, I worked it out similarly and I saw comments on the twitters recently from others who did. Also usually the tough stuff is in the second part of each day, which I feel is pretty fair and provides a way to feel reasonably good about your result if you're not completely successful.
- justinsaccount 5y agoYeah, I always liked how I could generally solve something a "dumb" way for part 1, but would likely need to refactor it to be a bit smarter to solve part 2.
- shever73 5y agoYep, that's pretty much how I solved it too. I had (and still have) no idea how to apply the Chinese Remainder Theorem. Looking back at my solution, I just iterated through the input, which I'd mapped to a Python list.
- Someone 5y agoNitpick: there’s no way to apply the Chinese Remainder Theorem. It merely states that “if one knows the remainders of the Euclidean division of an integer n by several integers, then one can* determine uniquely the remainder of the division of n by the product of these integers, under the condition that the divisors are pairwise coprime.”* (https://en.wikipedia.org/wiki/Chinese_remainder_theorem https://en.wikipedia.org/wiki/Chinese_remainder_theorem) It doesn’t say how to determine that number. https://en.wikipedia.org/wiki/Chinese_remainder_theorem#Computation https://en.wikipedia.org/wiki/Chinese_remainder_theorem#Comp... describes a few algorithms for doing that.
- Strilanc 5y agoInteresting. I think one of the main benefits of AoC is it tends to teach you things. So I would have gotten stuck, read peoples answers on the subreddit the next day, and the problem would have stuck in my memory as one that taught me something new. I also wouldn't consider knowing properties of the GCD to be a "random math concept". It shows up in a reasonably large number of contexts. For example, in public key cryptography. A specific case is that at one point someone realized they could just collect hundreds of millions of RSA public keys and crack low entropy ones by checking for common divisors. Doing this naively by checking each pair would have been very costly, but they used properties of the GCD to massively reduce the cost by pooling keys [1]. [1]: Page 7 of https://www.quintessencelabs.com/wp-content/uploads/2020/03/Keyfactor-Research-Report-Factoring-RSA-Keys-in-the-IoT-Era.pdf https://www.quintessencelabs.com/wp-content/uploads/2020/03/...
- _pmf_ 5y ago> Not sure if this is indicative of other years It is.
- LandR 5y agoI solved day 13, both parts, and I'm pretty far from an algorithm wiz, I also never used Chinese Remainder Theorem. Part 1 runs in ~0.5 msecs Part 2 runs in ~2 msecs
- Joker_vD 5y agoExcuse me, what? You don't need to know CRT or indeed anything about the number theory except that you can divide numbers, the solution is simply: for each ID in list: next_departure = round_up_to_next_integer(earliest_time / ID) * ID delay[ID] = next_departure - earliest_time nearest_bus = ID with lowest delay return nearest_bus * delay[nearest_bus] That's it. I can think of only two other algorithms: the one that replaces division on the second line by repeated subtraction, and the one that uses repeated increments and checking whether the result is divided by the ID without a remainder. How do you even use CRT to solve this?
- Jtsummers 5y agoAre you looking at part 1 or part 2? GP is talking about part 2.
- Joker_vD 5y agoCan't find part 2 on the site, had to google... result = 0 addend = 1 for divisor, desired_offset in [(7, 0), (13, 1), (59, 4), (31, 6), (19, 7)]: # keep trying numbers until we find the one that, with # the desired offset added to it, would divide without # remainder while (result + desired_offset) % divisor != 0: result += addend # adding another addend should not break previous results # so make it divisible by all previous divisors addend *= divisor print(result % (7*13*59*31*19)) This algorithm self-evidently works and is indeed "fast enough" if done by the computer.
- Jtsummers 5y agoThe key insight that many people, particularly those without the stronger math background, miss is that you can increase the addend like you (and I, in my solution) have done. So they either leave it at 1 (and the solution is around 1-2 trillion, IIRC, so that's not happening quickly) or they do one optimization which is to set it to the first divisor (7 in your example, which still leaves you with hundreds of billions of loop executions), but don't adjust it with each newly matched bus line. And instead of talking down to people, it can be more productive if you walk through a solution instead of stating "This algorithm self-evidently works" like a jerk. Also, the last modulo isn't needed.
- smcl 5y agoI was the same as you for a few minutes - I was demotivated and when I found out what was behind it I thought "huh I never learned this and I'm not sure how I would have ever learned this" and felt a little bit defeated. But then I read a little bit on the subreddit, read the wiki on CRT, put together a solution and moved on. It's meant to be a bit of fun, if you have to skip one challenge (or cut a couple corners) it's no big deal - you can always come back to it later :) It can be demotivating if you check the number of people who solved it quicker you, but just pretend they all cheated off one really really smart person and you'll feel much better :D
- Strilanc 5y agoIt actually was on day 19, it's just that puzzle #13 was the 19th puzzle given out [1]. I'm not sure why the numbers didn't come in order last year. [1]: https://adventofcode.com/2020 https://adventofcode.com/2020 shows the number order
- mercurywells 5y agoIf you look at the 'map' on the left side and also follow the plot in the puzzle descriptions, you can see that you were island hopping, so top to bottom is not the order the puzzles came out in.
- Strilanc 5y agoOh yeah, that's right.
- matsemann 5y agoI often find that part1 can be solved by most, but part2 sometimes needs a clever trick, experience or some knowledge. Doing only part1 or skipping some day is perfectly fine, though. So I don't really get your anger. I actually like when it teaches me something new. If you get stuck you could always google for the concepts you need and learn of them, or go to the subreddit and get hints but still solve the programming part yourself.
- deleted 5y ago[deleted]
- karmanyaahm 5y agofwiw the Chinese Remainder Theorem is taught in basic cryptography courses. ig it could be obscure for someone outside the field though
- lostdog 5y agoLast year I figured it out from first principles, like some of the other commenters, but that problem was one of the hardest for me (like the tile rotating problem, which was excellent). This year, my rule is that if it looks like the Chinese remainder theorem, then I can just look it up. There's no need to stay stuck on something that's supposed to be fun.
- Planktonne 5y agoI like AoC because it is the least 'know the specific maths trick' of the various coding challenges out there; there are normally a couple of problems like that each year, but most can be worked out if you can think even if you don't have a huge body of maths knowledge.