sln_2023_12
Copyright(c) Eric Mertens 2023
LicenseISC
Maintaineremertens@gmail.com
Safe HaskellNone
LanguageHaskell2010

Main

Description

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
Synopsis

Documentation

main :: IO () Source #

Parse the input sequences and print out answers to both parts.

>>> :main
6871
2043098029844