| ▲ | WJW 7 hours ago |
| I like to use Haskell, because parser combinators usually make the input parsing aspect of the puzzles extremely straightforward. In addition, the focus of the language on laziness and recursion can lead to some very concise yet idiomatic solutions. Example: find the first example for when this "game of life" variant has more than 1000 cells in the "alive" state. Solution: generate infinite list of all states and iterate over them until you find one with >= 1000 alive cells. let allStates = iterate nextState beginState # infinite list of consecutive solutions
let solution = head $ dropWhile (\currentState -> numAliveCells currentState < 1000) allStates
|
|
| ▲ | taolson 5 hours ago | parent | next [-] |
| Yes, there are some cool solutions using laziness that aren't immediately obvious. For example, in 2015 and 2024 there were problems involving circuits of gates that were elegantly solved using the Löb function: https://github.com/quchen/articles/blob/master/loeb-moeb.md |
|
| ▲ | jvuygbbkuurx 5 hours ago | parent | prev | next [-] |
| Does this solution copy the state on each iteration? |
| |
| ▲ | WJW 4 hours ago | parent [-] | | Haskell values are immutable, so it creates a new state on each iteration. Since most of these "game of life" type problems need to touch every cell in the simulation multiple times anyway, building a new value is not really that much more expensive than mutating in place. The Haskell GC is heavily optimized for quickly allocating and collecting short-lived objects anyway. But yeah, if you're looking to solve the puzzle in under a microsecond you probably want something like Rust or C and keep all the data in L1 cache like some people do. If solving it in under a millisecond is still good enough, Haskell is fine. | | |
|
|
| ▲ | lkuty 6 hours ago | parent | prev [-] |
| Do you plan to share your solutions on Github or something similar ? |
| |
| ▲ | WJW 6 hours ago | parent [-] | | I actually plan on doing this year in Gleam, because I did the last 5 years in Haskell and want to learn a new language this year. My solutions for last year are on github at https://github.com/WJWH/aoc2024 though, if you're interested. |
|