3 ms·
> there are two types of solutions you end up with: ones that can calculate the answer in a couple of milliseconds and the ones that would take years to finish
by ragona 8y ago
> there are two types of solutions you end up with: ones that can calculate the answer in a couple of milliseconds and the ones that would take years to finish
This is of course a bit of an overstatement, but I generally agree that (depending on the language you're using, and the problem you're solving), there are quick solutions and slow ones. However, based on the videos he posted, the author seems to have stopped just before the Advent of Code problem most likely to make his CPU cry! Day 14 didn't have an obvious optimal solution, so there were quite a lot of correct solutions that took seconds, not milliseconds. (If you're curious, check out this awesome post from /u/askalski [1] on getting it to run truly fast.)
Humans seem to be naturally inclined to pick the "best" option, and naturally frustrated by the fact that best changes so often depending upon the situation. In almost any situation as a programmer, you're deciding between several competing priorities. There's your speed as a programmer, your code's speed for the target hardware, your ability to get people to help you with the code, either via hires or online documentation, etc.
With regards to Advent of Code (which I also completed this year, and really enjoyed!), the "right" solution in Python could often be hundreds of times slower than the right solution in C or Rust -- just check out the benchmarks for similar toy problems [2]. That doesn't mean the solution is wrong, it just means that the author has decided that a couple seconds of the CPU's time are worth the benefit of using a higher level language, which is often a reasonable choice.
1: https://www.reddit.com/r/adventofcode/comments/a6wpwa/2018_day_14_breaking_the_1_billion_recipes_per/ https://www.reddit.com/r/adventofcode/comments/a6wpwa/2018_d...
2: https://benchmarksgame-team.pages.debian.net/benchmarksgame/faster/python3-gcc.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/...