Copyright | (c) Eric Mertens 2023 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
https://adventofcode.com/2023/day/12
This problem asks us to find the number of unqiue rows that satisfy the grouping constraint. The question mark characters are wildcards.
A naive enumeration solution won't work here, there are far too many possible assignments in part 2. This solution uses a boxed array to implement a dynamic programing solution to the problem.
Because the array is boxed we can lean on laziness to resolve all of the data dependencies entailed by the dynamic programming approach implicitly. By indexing on Ints representing the suffix instead of suffixes as Map keys we get a performance speedup.
To break the problem into increasingly smaller components we solve it for all the suffixes of the input pattern and group constraint.
>>>
:{
:main + "???.### 1,1,3 .??..??...?##. 1,1,3 ?#?#?#?#?#?#?#? 1,3,1,6 ????.#...#... 4,1,1 ????.######..#####. 1,6,5 ?###???????? 3,2,1 " :} 21 525152