3 ms·
Generally, such edge-cases usually make the solution ugly and the process unpleasant. The aim of such puzzles should be a pleasant process culminating with a b
by zerr 3y ago
Generally, such edge-cases usually make the solution ugly and the process unpleasant.
The aim of such puzzles should be a pleasant process culminating with a beautiful solution.
- randomifcpfan 3y agoThe potential for overlapping numbers was the thing that tripped up many developers. But a simple “find the first number searching from each end, just like the puzzle instructions asked” implementation just worked. The lesson is to read the puzzle instructions carefully and avoid solving more general problems.
- b3orn 3y agoThis is what I did and then was confused why everyone else I talked to thought it was a hard problem.
- codr7 3y agoSame here, I also didn't use the replace-strategy nor regexes.
- berkes 3y agoI did not use regexes, so as said, the most common edge case did not hit me. What hit me was stupid, but also not covered in the example. It was rather implied and obvious from the example, though. SPOILER ALERT In my mistaken implementation `one2three1` would find "1, 2, 3" but not the second case of 1. Now, while the description never explicitly mentioned this, it's still obvious that it should be "11" and not `13`. Though my example, derived by TDD-ing from the example, gave `11`. Only after I diffed my output with that of a known working solution did I find a few lines (there were several of them, though not that much) that made my issue clear: I missed the second case of a number appearing. So "one1one1one" in my solution would only find the first one.
- williamcotton 3y agoPerhaps for some puzzles, but I find this solution to be pretty elegant! https://github.com/williamcotton/fs_playground/blob/ffbc57ac72e821ce5b94742d78ffd2ff1f1c210d/advent23/Day1.fsx#L34-L59 https://github.com/williamcotton/fs_playground/blob/ffbc57ac...
- elteto 3y agoFor part 2 there is an elegant and very simple solution that doesn't use regex and doesn't need to work around edge cases... you just have to find it ;)
- berkes 3y agoI'm rather on the opposite end. The real world is ugly and full of edge-cases and noise and ever-changing-requirements. So encoding that, and keeping a solution elegant and "beautiful" is what I strive for. Finding elegance in mathematically pure setups, is, I guess, very rewarding too for many. But not for me. I find pleasure in abstractions, algorithms and architecture that embraces the ugliness and inconsistency of "The Real World" to make it workable (over decades). I hardly ever manage in this though. Most code somehow still ends up in deeply nested if-elses-foreaches and whatnots.