Day14
Copyright(c) Eric Mertens 2021
LicenseISC
Maintaineremertens@gmail.com
Safe HaskellNone
LanguageHaskell2010

Main

Description

https://adventofcode.com/2021/day/14

Build a huge polymer chain and compute how many of each element it contains.

This problem requires memoization as the size of the resulting polymer would be humungous!

Synopsis

Documentation

main :: IO () Source #

>>> :main
2068
2158894777814

solve :: Ord a => Map (a, a) (Map (a, a) Int) -> Integer -> [a] -> Int Source #

tableToRule :: Ord a => [(a, a, a)] -> Map (a, a) (Map (a, a) Int) Source #

Generate a replacement rule map from a list of input productions

>>> tableToRule [('L','R','M')] -- LR -> M
fromList [(('L','R'),fromList [(('L','M'),1),(('M','R'),1)])]

applyRule :: (Ord a, Ord b) => Map a (Map b Int) -> Map a Int -> Map b Int Source #

Apply a replacement rule to a map of counts.

>>> :set -XOverloadedLists
>>> applyRule [('a', [('b',1),('c',2)]),('z',[('y',1)])] [('a',10)]
fromList [('b',10),('c',20)]