diff options
author | Julien Dessaux | 2024-12-24 00:40:31 +0100 |
---|---|---|
committer | Julien Dessaux | 2024-12-24 00:40:31 +0100 |
commit | cc7e97348b2553b25928177b1ea158112b20171d (patch) | |
tree | dafcd442ef836aa9c360804b388cfedcdd0ba4af /2024/19-Linen_Layout | |
parent | 2024-18 in haskell (diff) | |
download | advent-of-code-master.tar.gz advent-of-code-master.tar.bz2 advent-of-code-master.zip |
Diffstat (limited to '2024/19-Linen_Layout')
-rw-r--r-- | 2024/19-Linen_Layout/example | 10 | ||||
-rw-r--r-- | 2024/19-Linen_Layout/first.hs | 42 | ||||
-rw-r--r-- | 2024/19-Linen_Layout/input | 402 | ||||
-rw-r--r-- | 2024/19-Linen_Layout/second.hs | 48 |
4 files changed, 502 insertions, 0 deletions
diff --git a/2024/19-Linen_Layout/example b/2024/19-Linen_Layout/example new file mode 100644 index 0000000..29648be --- /dev/null +++ b/2024/19-Linen_Layout/example @@ -0,0 +1,10 @@ +r, wr, b, g, bwu, rb, gb, br + +brwrr +bggr +gbbr +rrbgbr +ubwu +bwurrg +brgr +bbrgwb diff --git a/2024/19-Linen_Layout/first.hs b/2024/19-Linen_Layout/first.hs new file mode 100644 index 0000000..8ffe838 --- /dev/null +++ b/2024/19-Linen_Layout/first.hs @@ -0,0 +1,42 @@ +-- requires cabal install --lib megaparsec parser-combinators heap vector +module Main (main) where + +import Control.Monad (void, when) +import Data.Functor +import qualified Data.List as L +import Data.Maybe +import Data.Void (Void) +import Text.Megaparsec +import Text.Megaparsec.Char + +exampleExpectedOutput = 6 + +type Input = ([String], [String]) -- patterns, designs + +type Parser = Parsec Void String + +parseInput' :: Parser Input +parseInput' = (,) <$> some (some letterChar <* optional (string ", ")) <* eol <* eol + <*> some (some letterChar <* eol) <* eof + +parseInput :: String -> IO Input +parseInput filename = do + input <- readFile filename + case runParser parseInput' filename input of + Left bundle -> error $ errorBundlePretty bundle + Right input' -> return input' + +compute :: Input -> Int +compute (stripes, designs) = length . filter id $ map compute' designs + where + compute' :: String -> Bool + compute' [] = True + compute' design = or $ map compute' $ catMaybes $ map (\s -> L.stripPrefix s design) stripes + +main :: IO () +main = do + example <- parseInput "example" + let exampleOutput = compute example + when (exampleOutput /= exampleExpectedOutput) (error $ "example failed: got " ++ show exampleOutput ++ " instead of " ++ show exampleExpectedOutput) + input <- parseInput "input" + print $ compute input diff --git a/2024/19-Linen_Layout/input b/2024/19-Linen_Layout/input new file mode 100644 index 0000000..888f62d --- /dev/null +++ b/2024/19-Linen_Layout/input @@ -0,0 +1,402 @@ +wubr, uwbu, ugwru, wwgrgwbu, brwwuuwb, wgu, rw, rgb, ugr, gwuurww, rrb, ugwg, wwgb, rwr, wuw, wwbb, wwgrwuw, gruggu, ggb, wrrgww, gwuu, bwb, wbbubwb, urwgggg, bubwu, wbb, rurrgwgg, rub, urr, uwrgrgwu, gwgb, wbwb, gur, brw, bg, gugrwb, ub, ugwgu, wubbg, bubgrw, wgb, wgruu, bgg, bbuubbr, rbbw, ww, grgrb, urw, rug, wbwrgw, brr, bbgrguw, rwb, bbguu, gwbbg, bubg, wwuwwb, urggwu, bbwg, bbbwbbr, wwb, brgwbuw, wwrr, bwu, urbu, wguuw, grb, urbrbbu, rwg, urguw, wbg, uuru, uburw, bbbwrb, urwbur, guu, rbg, gwgwwrr, rbwu, r, wbw, gb, wgwg, ubw, bb, rbgru, rrbuwg, uwb, wuub, uurrub, wuu, bub, uwww, wug, grwguwu, bwgggbrw, uwu, wb, rrbgwubw, wubu, urbrg, wrbw, gruw, rrgwg, bbrub, ugu, gbu, gburu, wgbru, ubwu, brggw, wurr, bgwwgu, wggw, ugbgur, gwruww, wuwww, rbbbrug, wgw, gggu, rgrww, wgwwrg, wuugbw, rggb, brurrg, rbuu, ruu, wrrb, wwwb, gbguuuu, ruubur, gbwrw, gbgu, rbw, ubbb, wr, buwug, grw, wrbu, guwwwur, guw, urggurbu, uwg, grrwwwr, gbb, ruuw, ugww, guurw, grguu, gwrwrr, uwrwr, ubrb, wrrw, burbru, gugg, ubg, rwbu, rruwbru, ugbwu, gbr, ggwwg, rubbugg, wuwb, rrgw, rrbuu, rggbu, gbguu, ggr, wwwbgu, gbrw, bbbug, wrwwbb, wrg, buu, gwub, brrgugw, brg, rwggg, wuuuuugb, guwu, wgbbb, urur, wrr, wugwggu, uubgg, gbg, wgub, grru, uu, gbgbw, wubrg, wwrb, urrgb, wbuurrb, bw, bbw, rugbuw, bwbu, wbu, rrgwgbru, ggurrrb, grr, rrgug, rgw, rr, gbwbbww, ubbru, uuw, ruwbwwr, gwu, ugw, gbw, ruw, grww, ubbwrgrg, wgg, rwwr, ggwur, buuru, bbg, ruwgg, ururu, wrb, b, wbbubwgr, uub, brgr, wbbrrb, bru, wbbub, ggbbrg, wgrwbwr, gwrg, ubwruw, rurrb, brug, wu, bug, wwrruuu, uuu, wurgbu, u, bbr, wwrwu, wru, wbgr, ru, rwgguw, wwu, ggbg, ggrgu, wgwurw, ruwrwu, ggg, wggggbu, rbugggg, wwbbu, w, rwru, bgr, gr, bwwb, uggwbwuw, grg, uur, wbwrrugb, wbwg, ggww, wwg, rbwg, gub, bbb, gugbu, ugg, rurrg, brb, guggww, bugb, ubrwww, bbwr, ur, wwr, uru, uuurrw, wgwwbb, bgbbr, gugu, bwrrgrrw, bgw, gbgw, ubgrgr, wrw, grug, ugggww, wbbwg, rbwb, ubr, wgwb, brbwbgwu, gubwgr, bruugggg, wgggu, rgr, ugwwgbgr, bgrurr, wgr, gwb, gwgrr, ggw, gurrb, wuwubw, brbbgw, ububrbw, ubbrw, ububu, ubrbub, bggu, rwrgb, burwg, wrru, rg, rrbww, rrww, wrwb, uuwwu, bwuwr, gwbr, urruwrg, rubgbr, gwgbw, rbru, wrrubw, bgwugbr, uguurg, wwrg, bwr, rwrr, uwugr, uug, wwgu, wwrububg, www, bgb, urg, wg, gu, rwu, rbb, gwgw, grggguuw, rbuwrru, gwug, bgu, burgb, bwrubu, uww, wur, rurr, rrr, wwbrr, wwbbrw, urww, buwugwr, rbuurb, wub, bbbw, gwr, wwbgru, ubu, uugrg, rbu, rrg, gggg, gww, ubgbb, wbr, ururbwu, wugr, uugub, br, bgbb, grbgrw, gru, bgur, bbu, rru, ug, wwgugub, uuwgg, wguubw, urwbruw, gbbb, wrwuw, wguw, gbwgrbw, rwwwu, brgru, bu, rur, rbr, wrguugu, bbrr, wbgb, ugwbwu, wrbuwr, ubgr, uwbw, uwwuwrrb, gwugr, ggrr, uurgru, brbrb, brwbrr, bbru, ruwub, rrwgu, buw, ggu, rggbbr, brgw, bguwr, wwbgu, rgu, bur, urrgbu, uw, uwrbuw, wrubbw, wubw, bww, gubgb, rww, bbuwggg, bwgr, brwb, rgg, rb, urb, bgrw, wgurgrr, bgwuur, bbbu, wbwrgg, uwr, ugb, rwbg, gbubbuw + +guuggwbugbrrwgwgrwuburuggwwguwbgrrbbguugrbgwugu +gwguggrrbbwwgwugugwbrbwbgwuuuuwwrbwrbbbgrwwrwwbbwbgww +gwgggggwwwbuwwburbbrrguugrgruurggwburgruruguurwwuruguggr +gwggwuwwwwbuwrubbwrbwgrggruwgbuuwwbbgwrubwbrgu +gggbgrbuguwwgrggbrrwrrgburgbrubgbubrrbrbgguurgwburggrwwbub +gwggbbrrbbwrrwbbubwgrrbwbwbbburrrgurrggwrrr +gbuwrwrrgruurwuwwwrgurbbubgururbbuuwbbgggrwrgb +gwgggwrggrrwbwrwwgbbrgbbwggwwgurrubrrrwggbuwrrrrwrugrbw +brurbrgbubuugbwrrubwwwbgbwbuurwurgrggrrbrbuuwbbw +gwgrwbbwrwbuurrgubrgbrrgbwwugrwgrwgwuwrbruwwbwgugrbbbbbrgwb +wruubwrwwbbrugbwwbbrbbrrbubwrbggwrbugburbggubuu +bwgrbbuwwugggwgrrwwwrgwuwwgbbwbggububbrugwbbruubggrb +gwggbrgrburwbbwurrbuugwbgbgrbrwurrbuurgwbgugbrbbgr +gbwguuuuwrbwwgwgwuurwbrugrbrgugrrgrgwrwgwrwurgg +gwgruugubrbwbruwbbruwbgrbugubbbwrwurgbgbburwguw +gwgrggwgbwbuuwubgrggbguurrruwuururuubbbguwuwrbbruguu +rwrwbrubbbbrrrwrwgrgwuwbgrrbbwbrubggwubrwwguwb +gwguuubuwwbbubggugrugwubbbrbwgbugbwgwbbruuwwuwgugbbwwwwrugr +ggrgwggrwuggwwrbrggbbrurwguwuubrubrwwguburbbrubgwubgg +gugbrggrrrguuwubgbwrwbrgbrrugwwrruruuggurrgbrwrwru +bwuwgugbgrwgurbbgrgbrrgubbguwbburrwwwbgguwwgrggwwrbgwuwbww +gwggbwwubbbbbrgrgwgrbburgrwgbbruubgrgwgwwugwbbrubggwgbb +bbburbgugrguurubwwwwurbuubrgwwuururuuwbbuurwubrggrwbuubw +gggbrrwwurwubrrgrburgruwwuwrrguurbruwrugrwbuwrwrggguwrggw +rgbrguurrrbrgguurwrbbwuubwgrbguwgbugbwuwbbgg +gwgubbruwwgwugrwuugwuruuwrwbbubugugguwwguurrruruwbg +bbgwugurbuwgburbrrrrgrwwrrggggwuwbgbwrguwwgurgwuggrburrwgg +gwrrgbwgugugrgrrggggrwugwbwgrrgwugurbwrbbwwrwggubrwbur +rrwgrgwwwbbugrgwrbubuguwgggrgwguugurgurwrggburguwugr +gwgugbrguwrbbuggrgbrwubgwubwwwrwrrrbbgbbw +ruwgwuwugrrbrgwbgbbgbwugwuggruwuwurgbuubbruwubburbguw +rwrugrgwbwuwgbwrbbwrrruubgubbwrugggugbwggbgrbuuwruwrrrgbuu +wuwbgwgwggwwrbgrbuwbwrbugwgbrugrggggrggwuwuggwgubgu +rbrgrwwrubuubuwuwwrgubggubrbrgggwrwrwrgwuu +gwgururwgbwruwwggbwuwwwggugwwwwrgwbuwrrbbbgrgbgbrwurwbrwgw +bgbrbgbwguwgrubggugrwrbwrgrwgubgruggrbburrbgwubwuguuw +rguggurbgwrgurwurggwwgrwugbwgwbbbrbrurwggg +gwgrgrgbbwrbgrwubwbbuwruuwurwgwwrwuruubrwgburbgwgbu +uuubwbgruwbrwrubwguwbugbgggwguggrwubgbbbuurrguu +gwgggwrbbgbrgbrwrbrwggrbrrwbuububwgrrrrggru +gwgguwgurrrrbwwwrwrgwbbgurrwurrbubwbgbruw +uwrwubgwuwbwggbgrgugbbwrwwbbbubwgrwbrubuuggggrwrrwwgrb +grrwruuguuurgurwgwwgbrwwburwbuubrbggggrbrgu +urgrruurbgurubrrbbrrrrgwrbbwguwrrbrgburwwrbwbrgugbugbgg +rggbbrbbbgbburwrwrguwrwbwruwubrbgugrgugwbwbrwuggbgwbr +wurbgbwbbwgubbburbrgbuugugguwbgrwggrruburugrb +gwggubbgbgggwbbwurburwwguwbwbrggbubuuggwwr +wrbrrbwrburbrgrubbwubbrgbbbuwrurrrrurubrbuuwwwubrbrrbr +buggburbubbwrbbrbbwwwgwgrbugguuuugbgguuwrrgwrrbbrrgrwwgbru +gwgugubwgbgrururgbbuguwwwbwrrugbbgrubrwrwuuwb +buwrugurwgrbguwwrwgruwrgbbbwwruubugrubrbbwuub +rwgwwbugbbrgwwrwrrrrrwgrugrbruurrgrggrrgbbruub +ubguwwrgurguwwgbbbbbwwbburrurbuwwrgbwbbgrgbwwrbubbggbr +urgwwrbbwggrwguugguurgugbuurrubrgbbuwbrwgwrwbuwuuw +gwguwbgrggwugrrgrwbwrbugwgwgbubguurggrbrurugub +ubgrbuwgguwgrbgrbguruwrgrgwuwgggrgurbwggbgbg +wrgugrgggubbuwgggwbgubwwrwbgbuwgwgbbwguubgbwbr +bwgguuuggrguwrubbruwbrbrgburrguwrrbrggwwbb +gwggwggbrrgwgbruubwruwguwbugwrwrwrrwbwwu +ugbuwrrwgwbruwurubbgruuuwrrwgbgwugbuubgwwugbu +gwgugrgrrurrwgburbwbbwuugwruwrubrrbgbrrrrrrbguugbwb +wubrrbuubugwrbburrrbbwwbgrwgbuuururgrruwbgrguwbwubgbu +wurbruwuwrwggwuwrubrggwbbuwbgbggbbrwwwbuugbwrguwugwuugggub +grrubugurbbbuuwrrrugggrbggurbbuuwrwbggubuugugwgrbguggggbw +buwgrgwuugguurbubrwurgugbbwrgwgguubwgwgwwbu +uggrwgggwgwwugbbrrgrurgbggwbgrbwwgugrwwgwr +bbggrugwrbwggggbgbbwwrwbbgwgwwugugwbuwrugbg +bubugwbwguwububwwwuwguwurbwwbbgurugwwuwurwbbbugbwrrgggb +bggurgwbgggwbguubgwurubgrwbrwuwwgwubwbrguwwwuuuug +rubguugrwrubwguuwrgwurbguuugurgbburrruwwrgwrggbggwruubwr +wbbbruuwuwubbwrburugguurbggwwgbbrwwwbrggggwwu +gwggrwbrbgrrbuwwgwuubrwgrwguruwrrgrbrbruwrgrgwu +gggrbwrruuuuwruubgrgubrgrgwuwgbrwbrwgurgugbgugbruubrrgwwb +bbwbbubgguwrbwbwubwgrbwurrbuwgurrwuuubggrbwwrwgbrwbuwrbuub +gbggguuruugwrbuuuwgbwbububwbwrrwwubrrrwwbubrbwugbrug +buuwgggurgbgbguwrruubruubbuwugbrggbrbruubwgb +brwbrrrwrgurwgbugurubbguubbuwubrgbuwrgwbbgbwrbbwwg +rbgwbuwuugbruurrbwbggrurguuwwgwbbubwgrgugbbwburbuggbwuwrru +uggbruuuwwrurrwurwbwgbgwugwbgbwuwrwrwuuwubbrwruguug +rrrwguwuwbbgrgrrgggwubbwrgrggrrwrrbgwbbrwgruugbgwrwwuugwr +gwwbbwbgbrurgwbwwggurwrwgwbbrwugugubwwuwwbwbw +wbgrwbbgwuuruwbbrurubgruwgwggbruggggbrrubggrwgbrgwuuwuwrbb +gwggbbwgggwgrwubrguugugrururrwurrwuwbwuubuwrwuwuurgrbuub +ubuggrwbubrrbggbgrbubbburgrugwurbbuwgwbwrwwgbwugubgwuu +urgubgwwwwrubwwuuuwbbwwgwwrgwwwwwuuwbrgruugwrrrwuggw +bwuwruurgrrgbbgrugrwrugbrbburbrwbugrbgrbrgug +gwgugrrgbuwuwgrbrurbbuwgrububbrurrrwrugbbbrrruubuw +gwrrbwwwburubbrgbwbugbuubuwwbwgwgubrburruruwgbbgurbgb +gwguruwwuwrrbwggrbubbubwrurbwggwgurrbbubgbbggbr +uwgubbwuggwubwbbwbwwrburbuuururuuwrrugwgurwrrrrbrbwwuubuw +wbrbbbgwrgrurbrugrgwgggrgbggrruggbggwbwbwruggrurwu +urgrbbwggrguurgrwwugbrrbwruwgwbbuwbuuwggwbgrguurgbwrgwb +gwguwwrrrwgrgubbgrgbbbruuwgbugggbggurgrbwwwrrb +gwgrgrwurrwggwwgbwubwburwbgubbwrgwurrwgwbruubburwbrwrwwww +gwgubwugwugguwbrgwwbggguruburggrugwwgruurbrgrwwrwbrbgbwgw +rbuurbuwurwrrggrbbburwwuugwbwrbbwgwbuwrrbu +uuubrbwrguwuwubwgrrgrrubuwbrwwbbrrburwrbwgbwuwbru +wbubuwbrgwubggbrrgwugwwuwbgwrrrgwgbruuwgggwgggurgrgr +gwbgwggrgbbgwwwwgbrbwguurwbwgwgugrwrrrgrbwrgggbgr +urrwurrwrurrgbwrbwguwbgbrrrububgbguuubbbwb +uuwwrbbubruwuwrwwwrubrrbbrbbwwbuwbburbgbgrgrrbuwburuwbugr +rrwggurbubbwbugwuuwuwggugwwwwugrrbgwbrwrbgburgbbrwu +bwwgrugurwwbuwrrggubgrurgrwbwrrbggurgugwgrrguubwugw +bwbbubbgbbruwrwuwrwugwbrrwgbgrbrruruubwuwwggg +gwgrbwgwbuggbwbbggububbuwbuuuwrrurwwbbgrb +gwgugwgrbbgwbbrwwbbwurguwwrgubuwbbbgrrurugbbw +gwgrwbbbgbbbwgrrubrurbuurgbgggububurbwbrrgggwwr +gwggbgrurgugwwburgwwrububguurwurrwuwwwbgwguruggbgwwrw +rggwbwgbugrbwbwbwwburruwrurubuggwubrurbbguguwrwuwrg +uurrggwugrrbuubwgwwgbrbuuuwugggguubuwbbwgggrrburggruwg +gwggggrgbwwwrrrgwbgrbggwbwrgbrurgwgbwgbwwuwgrbgrwugbg +wuurgrrgguuwbgugubrwwubuurbbuburrwgwugugwggbwrggurrurrb +rwgwwgbgbwbbrggrwwrwgbuuuugbwbururgugwurwrubuuuuw +gwgguurruuugbbrguuggbrgwgrbgbgbwrrurruwwwurggrg +brurruwgwgrugbgruwgrrwwbrbuugugrrbgrwrburggurrwuuruubrwbu +buurbrbgrrbrgwrgwrrwguugubrwwuuwbgwgruwuwgurrwurbrrwb +gwguwbgwbuwrbggbururbrbuwugwwguwrurgwgbgbgrbruur +ggguwuruwuwgggwwbrbbwuugrwgggbrgwbwwburrbbbuwuwbgwgw +gwgubbrrgrrwgurggbwbgbbbrwggwgwruuwbwgggbrwgwwrrurbwgbgg +rrgwubrurrrrwuurrrwuubrwrwgbgrwbgwubwwwbbbwgrwwrwb +gwguwuuugbgbgugbbwgruruwbugrgwbrwbuwbuuggggwrwrurbbrgrbu +gwgurggbwrrgbwwguggwugrurgugrurgwggbuubbwr +uwurgugguwbbrugwrguugrwuwwgrgwguuggrbuwrbwgww +gbruwggubuwrwrgubugrgbuwgubrgrugwbbwbwbbuwgrgrgwwbrub +wbbgubguubwbbguwrwrbruuwbguwbubbruuggrubbwurbrbbguggb +guguwbgbbrugbugwbbbuwrrugubwrwwrgguruwrgggrgurrbu +uguggugbugwurrrbgurbbugrgwrwbwrrwwbuuggbrubrgbrrr +wgurguwrgrrrwgbbgrbgbrbubrwbgbbbgguwrrwgbbrgbw +bugbwburwrbuuurgwrubgbwurwrruurbgwgbwgwgwbruuruu +gwguruwwwgbwrgrbrgubbrguugrgrgugggrurbbwubrwwuwwguggr +ugbwbgbwubrwwgbwrbwrgwrgbwbrrrburgwggggruwb +gwgugwgbwrugrugugwwuwwugwrrwbuugbwbbgbbggwuubrgwgw +wwwrrbwuuuwurrrrgbgruwgbburgrrrrrbrbrrwrrwbgrgburw +bbrgwgruguwgwwbrgruubbrrwbgburrrubgguubrubbwgb +wbuuuubwggbbggwuggbwwrbubgrrurrwbugrwgbbubgrbrwbrgwbgwru +grbgggbgbubgubggrrubugggrrugrbbubruwgrrbub +gwggbubggrwrbgrwbrguugrggguuwggwgrwuubwggrw +gwgguruggggwbbbrubgbwwbbgurggrurugrruguuuwuu +rbbgwwuurgurwbbbrbbwrwbwwbwbbbrruuwruwwbbwgubgbrrwuugrw +gurbwuggwgurbuwwggugwbgbwrrubgbbbrgbwwrbwurwburburruwgb +gwgruuwugugwugwbbbgrwwwbrgugbgrwuwggguggugwwgbgrr +grbrbbwbwugruugbrubggubguruubuurgwwbwbwrrugbbbguw +bggbbuugruggrgwgurugrurugbgubbgrbbugbrwuururwruugwbrrbr +gwbgwguugwggbrrbgugbuwwbwbuwururwgurrrgurrug +bggrggbguguugbrwuuwuuwburubgwrbbrbbgbbruwww +bgwwgbggurbbrbwrbbwuurrurbggubrrwubwbbwgwwrrur +burwugwwbwruwrubgbwbuubbbbrbrgwgugruwrubwrur +gwgggrrwbrbrbgguugbuwgruwgugwgbruuggggwuuuwwrwgrbggubu +brwuguubburburubrubrugbbbgurwubugrugwwgwbrgrg +ruugurrbbbbwrbrwurbbbuwwbgrggwuwwwubrgwuggggwbwuwgwrrrbgb +wgurggurbububbgrgguwguurruwbbbbgbggwburgbgrgwrwgbrurr +bwubrrbuwbrbbwbwgwwgwrrubwwbbwbbwwbwugrgwuwu +wbwrbgbwwrwburwgububrwgbbbwwgbwuwbwgbwgbwb +wurgrurrwrbgrwbbrrrgbwuwugububugrbugwggbbrguu +uurgwrrgrgbrwwbugurubwwwrgbrwrrwuuugrbrbgruguugbgbbbub +brrrrrguurrwgbbuwrgbwubwgrgbgrbbwgwbwbruguwu +rggubgrgwwgggggwurrbgbrwgbubrwbbrbwubgbuggggrbw +ugbbwbrruburbwgubbwbwwwrugbgwugwubrbururgubugrbbrrbggwrb +wrgbgugrgburuugugbrbrruurwbbbbwuuguwugrwrubgwbwubwwguguubr +wgbuurbwgrgwwuubwbbgggbburbwbrbgrrrwgbwbbwrgu +gwguwrwwbbugbbgbbwubuugruurbuuruuwgugwrrguu +wwubburgwurbrrbrbwuguugwrrwurrgrrwwuubrwubuuwgbbb +guuwrgrwbugbwubrbubrgrrbwuwburbrugrbuggugwwrbgrwwr +brrgurrugwbrbruuurwubwbgrbbrbrbwbuwuugwuuwgwurururgu +buwgurgbrrrwbgwbbbrrbrurwuwrbbbgrrbbgwwgrrbw +bbuwbwgbuurugbbwgurwwbbwguggbrguwrwggbubuwuggwrwugbwburwwu +wrrrruwuwrbuugbwgguugbrurgrgwbuwbbbbgggrgwuwgruggwgubgwr +brgbguuugwwrwugbwbrbwrurwbuubbrbbgruubgrrgg +ubgwgggwbuugrbwgwrgbwwrgbrbrrgbrrgburbbrurrubrugbgwu +gbubwgbgbruwrgububrbwbwgggbrwrrbbrgbrggwwuwbbbgww +rwwrrubwrrrbgbrbbbgrgbbbuggubbwburugbwbwubbgwggg +gwgruuguguggruugwrwbugwbrgrwbwwbubbwuwbgb +gwgurrgrwgwgbrgwgrgwgubwbwrwguwbggwgwrwggbwrgwwuuuububgwgb +rbrrwwbbuwgrbrgwrwbbgbugbrgggguwrrrrugwbwgurrgu +bgbwggwuwrrrubbbgbwrrgrrwrurrgwwwrrrbwrubuubbbrg +wggwbugbrrrwggwgbwwugugrwggwwwguugwruggwbwuwggrrrwrwub +ubrurgbgwubbrwwruubuuwbwgrruwwwubguwugwwgbgrgubrgw +ruggbwbubgubugugwggububuurrwgrwuwbuwwugurbu +guburggbwgwuggrbbbguwgurbguwrrrwguwwwgrbwgubrg +bbbgbbbrrrrbwrgbuuguwrgrwwbbgrbuububrggguwrgr +buwgrrwgubwugrwwrbbgbbwrbwbbrubuwbbbgwbbgbru +bbrrbuguwwbbbrgwuugrguuwwwggwrwgbbguurwwbuugurwurgbubgbu +gwggguburgrrwrgwbgurbbbrwwuuwbubbguwwuugrugbg +bwbwrbuwwrruuuurrubbrubwrggruuugwururwwgbwbuwrbgbwuwwgb +gwgugbrurggbbwurwwburgrbuwgbbwugrgwuuwgbrrurgbwrwurgwgbuwwb +wgggrgbwgrubguuubrwurrrwwbrugbbbubrgbgrrwgb +wbrrgbgrgrugwwgugbrbgbugrwgrwwgguwwgrgwuruwrgu +rwugrbrgurbrubburbbgwugwwubguurrruwbuurgrgurgwgrwggub +urrwguwrrrbrrrgrrruuwuwubrgbrbbwwburgwrwrbruugggggb +ruugbwwbwbgguuuugurwbbrrwruugwgrwwbrgwuugb +gwgrbguugwbururbwuwurbuubrurgwrwgurwwugrubbwbuwbgwgubrrrrb +wwwwwgbbugurggrubbububwugbwbguwrgbbgrwrrrbbrbrbrruwwrr +gwgrgrbrbwrwuuugbuwrwuuwwwrwbubwrbwwgbuwbbrbbrrubugb +gwgruggbrrrbgwubwwggbgurgwruuuurrrgrgurrrbrrrgggrr +rugggwgrbubgwgrgguugwgbbggugwrbbbwgbgwburrwggbbbbg +gggrrugwbbgruubgbwrrwrubwrggwgrrubgwwwuurwubwwrurrw +gwgurrrggrggrguguurgubgrgwrbbrbrugggwubgruggburwrb +urrugbrgbubrrgbbugggguuwwgbruuwuubgubbrbrwrbbrbwbb +gwgugubwrgbrubbbggubbgwrrbwuggwububrurgw +rurgwwwrgwruubwurbuggwugburrrgwrburbgbrbubwu +gwgrwgruwgrbwwurrwgggruwbbrrurgwgubwburbgrugrwgbwruuwguurugw +rwrwuwruguwgbwubwuugwggguwrgruwgrubwwrrwrbbuwrgguubwg +buwuwgurwuruubguwgugbwbgggbrurwwggrgubbuwuggrbu +rbrbgwrrgbbwwwwrgwbwrurwbrrruwurburgrrwgbwrwwurbrrbbg +wwgbwrbggguwwwwwbgwruruubgrwurgbuugurruwbwrrg +rrbrwbwrwugubrrgbuwbrggrgrrwrgrrwwbubguggrugggrw +gwbuubguwgurwbbwwgbgruwgwwgwwrggbrrbgubrubwgbggu +gwguugrbggwuwwgbrwugubbgwrrrgwbwrrruuwrugguubgwbrggwgwb +rgwuuubrgurbwbrgwubbuububgurwgubgguruuggbwbg +bbguruwrruggwuwuguwrgrbwugguwuwrrrrrwuwgurrwrruwwbrbu +ruuuwwwrugbuwuwurbubrwrugwbubbubwruguggrbrrwguwrwugwugbbw +wrwgbbwrgwgwrwwbgbruuggugrwgwwrbwgbuguuwbbg +wwbwurrgwugrbrbgrgwugbugrbbbubrgugwrggwwug +ububggururwrubwrguwruwuwbrwuwurrwrwwgwrguwwgwgur +gugwggbwgbgrrwwwrgbggwrwgugbuuwbgrburrgrbgrwwbbrwbrbwurgw +gwgurwbgbrguwgbrwrwbwuwgrwrurwguubbrrbwrbwgru +wuubbugguugrwwgwrggwbubwugggurwruguwgbrubgwwwbwggubuub +grwrwrbugbgbwwbbbuuwrrggwwwubbbgbuguwwbuugrbrwbu +ggugbgbwbgbuwbburubrrgbwrwbuugurgwuwbrrubrrrrbbbwruruwwwwr +rbgrwbugwurwbgbuwrgggwubuwwrwwwguuggrugwuruwgbg +rrwugwbbwbbwubgbubwbgbgbgbbwggwbwgrurrgwggub +bgwgrwuruuwbrrrwwwwggguwubwggwrrrwgruwuwuu +rwuwwwwwuuwwrggrbrrgugwubuggwwwrbbbubgurbur +uubrgurbgbruuguwwbbgwbrrgrrruuwrugrubwwgguwu +bguugbbgbguwbggwubggugugrrgrubwrgwwwwurrrw +wwwrwrbruburwrrwgugwwrbuubguwuwgubuwwuwrrbgbrbw +grgwuubrgbruwuwrrguuuwuwggbwrrrgurgrbgrbww +gwgrbuburuurrbuwggrrgrbgurbbwggrwuurwggbggwgwgrgrwugurrwrgu +rwwwbbuwwwbrgggguubbwuggwgwubbwwbwwwgbuwrrruwrbrrug +gwggugwubbwrgrgwrugbrbbrurubwbbrgrwrbwggbggrgrru +grrrwwbggrgwgbgurgwrggwwwrgrggwuuggbbgguugw +gwgurbuubwwbbrwbgbggrrwrubwrbgwbbwgruurgguugwggrrrwbburugrbg +gwgggggggwbwguuuwgggggwgwbuggwburburrgwrbu +ugbruwuwrgurbgbwrrgugwrbbrubggubbwwwbgwgbugurbgbrg +rbrgwggbwrugbbrrruggbwuruwgwbgbwruurgwwwgbwg +gwgrbbgwubwwgbbuubrwwuwugbggwbbbuubrbggu +gwrubwgbgwwububrrgruggbgwbuwgwuwuggwbbrrbgguwrrgrrubuwuu +bgububbrgrrurbugbgwggbwrwugurrrbburbbgggbwubwbubgwrwuuuub +rguuuggbbrrurrbrgburrggwguuwbrruggrrbggrwgwgrgwgwuw +uwrrrgubgbgrubuurbwbruuurrbrwggwwgrwrguubgrww +rwwuuuuguwwbuwbgrggubbgwbbguguururrubwwgggruuwgwwgbg +rurrbububwwrgurrbgggurggggbbuggbbbrbgruwrbwbubuuwbwg +rwugugugugruburbubwrrgrgugbrbgburrrgrbbwgwuwu +ubgbwrwbrbwrggrubbbgbbuwrgurwwbrwwgrgwbuwwrgrggggb +ubbbbggwgwguruwrbbwrwwrbrubbwgwwbgrgwgwgrubbrurugbwrgrrrww +gwgubggbuwbgwrwrrruugbbwrbbbwbruwbwubrgrgwbwu +gwgurwrwrruwbwgwrbrrubbgbrwbgugbgugwrrgwrubgwbguuwbw +rrbwurbrrwwrurrugwbugwbuuggbwbwugrwguurwrwrurgbgg +ubbgwubuurgwwwuuwugrgwwbbwubwbrbbrbrguburgbrbggrg +gwgrwrwwggwgggubbuurrugwubbwugrrbrwwrruuwbuubugwrgrg +wrbgbgrrbuwrwrwbgurrwuugurgbwubgrgurgwgwgb +rbgbgbrwubuwggrwwwbrgubbruwwbbwbrbuwwgrbuwgwwur +wubwwguwgrbrwwgrgwwwubgwrgggubwruwgrbgbrrbwbwbbuwuu +uubrwbbubwbbguwgbububrgbrbuwrbruruuguuggbwu +ruwgbrbbwwbwbuuwwbuwuwugggrbwggwwwbrrrrgubugggurrbwrbbugu +gwguuruburgubgggrgrrwururubbwbgbwgrwrwrrggg +uuwgrrbrurwrgbwwbbrbbwwrwubgrwwrububgbbuuuruwgrwruur +ugggwrubgbubuubwwbbbbuuubbbuuubgurbburuubrrruwrwuw +gwggbbuubwbrubwubbwruurrgugbubuurrrrgbgrbguubu +burbrwwrrbwrrgruurggbwggrwwbbggwbbuururbrrguwbwbwrbuwbgrrg +rurguwggbrgubwbbrruugubgburwbgrwruggurgugguurwrrrwuwguruww +ggwgwggwggwwrbuwgrbuurbruggrrrwgubuggbrrrbggwbrggrwbbgrb +gwggbuuwwwbgurgbgubgwrrrbrbgwrbbbbgrbruuww +gwgurrrrrrwurbgbubgbbrbrwwggbubbbwguwwgguu +gwggurrwbbbugguwbrwgwrwgubruruuggwbwggwwrrbuwwurwwbrbu +bubuurbgrurwwuwwgubgurwwrgggrgbuurgbwuruwbugbgwbu +gwgruwggrgurwrruwburuwgbbgrwbubggrrwrgbwwwgruwr +gugwgubbbruggwbrgwurgrgrggrrbwgruwwwuggurbggbbrbburubuububu +rrburugbgwgugbgwgbbgwggrggguuwurggubrbggwub +bruuuwbrbwbgwugwgurubwgbwbrugrrrbgurggwburwrwurwuwrbbuwr +brruuwugrgrgrbwwgugbwruwrwugugugrbuubugburwbwur +ubbwbbwbuurbrugubgrwwruwbwurrbbgrgbwrbuuubw +rrubbubwrbbbgbrwgbuguwbuwwrbwbbwwugubrugbwwbbrbuwwu +gwgggbubrrwwbrwbbuwrguwuwuwrwuwbrrgrwwur +gugwbgwguurbbrwwgruuguugbuwrwrwuggwbwuwbbwuuuggrwgurugwuuru +gbwuurggurbuuguurwbgbgubugggwubgwgruggubbbwgguurwubbwrg +gguwugurgbbuuwrbggwrugugwrguwbugwgurrwrrwrub +ubgwrwrgbuwrrrurbrbwrbbgrrwgbwrbgugwwuuwguu +bwurburrwrgrgwbbwrrbgggwrurggwgbwrubwbrwbuwgbbubr +grggubbwwrwrbbburgwguubrwurgugwurbuurgbugr +ruurrguwgbwwuwuurrbrbggbgwgrubugwwbbrgwrwrrw +grububbgruwrbgrbrgrbwwbuuuwrbbwruuuggwbbbgwugbwb +gwgubbrrubugrgwgbbuwbwwurbuuugubuwgubbubruw +gwguwurgbguuruurbugubwrgrrrbuubguwggbruburrwwwbgw +bubbrwwburwwwbwbbrurrwugwrugbuuwwwuwbwbgrbggrbwwurgurwww +gwggburwgwguuuguugrbgwrrubbwwwwrurwrrgwubrbrwuwububwg +gwggbbwbbrwgrugrurrgwggggggrwugguruwbgrwgrwwgbbrburub +gwggbwrbwbwuggbbbwrbgubgwwbgubruwrururgbruwrgbuwrubwrwuwwug +gwguuwwgrwrwubbgrgrrwuurbgburrururguuwgrwugubggubrbugug +uggurbbwwggbgwwrbrwuwwrwwrrwrgrurggubrguuruwuuwrgruubw +ugwrbbwgggwuwbgrrwwwggrwbgbgwrwgrbubrwubgburggugw +gwgugwgwbbrrwbrubuuuurwuuuuugbbbrgwwgugwruwrrwg +gugwgrgbwuurbggwrwurrbrrgrrwrgrrwrruguwuwb +wbgrrgwuwrrwbgwbbbwgrwrbrrgugbgbgbugurggrbrrgrwrugbbbr +wrbguubwwwrgrgugrrbwbbwwurugrrwurubguurrrgruuwr +gugwgurbwrrgrgbrurrurwgrurbbrrgwuguugwrgrgrg +gwgruugrrbbrguwubuwuwwgbggubgurbwwbgrbgrrrg +ugrugrbrwbgubbwbbguurwwuuwbubgrwggbgrrwwburu +ggrggubrrbgruuwurwbbbbrbubrrrgbbgubwbwwgbwuwurbbrruug +gwggggrwguuwgwubgrwwurgurgguwwbrrrwwbrgwguwrugwwrugggwrbrw +wrwuuburuwwggbrwgubgwgrwrgwgwwrwwruwbuwgrbuurburgubwurbw +uugugwbgbuuwubguggwbugbwwguuwggrrggurbwggugbbugggururwgwuu +uwrbbugggwgurbugubbggwurwbbbwggbgrrgrgbgrbuwgbruwugubrw +gwgggurrurrburgugguuruuuuguuwbuguuuwrbbu +brgbwruurrggbrwguwbgrwwurwwrbwbwrrgwrwwwrrguuwubwubr +rubugwrurrgwgwbbrrrgguwguuwwgubrubuuuwrggwwwrbbrgrbgu +bwruuwwgruubgurbgbrgwrgwbugruwrbbwbrrugrww +gwguuubwwurbbrubbbrggwwwruguruurwuurwbgbuwwbwwguwg +rrbgrrugbrrwwgbruggbrrrguubbrgwwgguurgrwrrgu +wruwwuwrwgruuggwgbbuuwwgbrugbrwwbwbuwuggwwuuuu +ubgbwrwgrrrbwrrrwrbuwgruwgbrurrwrrurgbbwwrubg +gugwgguwwrrwrbggwrgggbwuwubrbuuggrubuggrwrggbbwbgbgwrbuu +ugbwbbrbgbbgburrwrgbwbwugwwbubggruwuwrurwgrbrbbw +gwguwrwgrubwgbwbrubguwwurrugrwurrgburrbuguuruuwbbwrwu +buugwwwbugwrrrgubwwbwgguwurwuuwwrbwrubggwgrrugw +gwgrbgwwgurgurgbgruwuuwwwbrbubburggggwbr +gwgrbrrruuugrggwbrbrbburgbugwrrgurbuggbubrrbrrubgwbguug +ubuwgwuggbgrrubguwbbwwrwggrbrwrggwwubguuwur +gwggwbwrrgrrwgrggurrugwbwbguubwbwgbuwbwurrwur +wbrrwubuwbuubgurbuububbbbwwuwwuubuubgwbugubrwbwrrugwgrb +gwgrwwgwubggruwrggwbrbwrwbwrbbuwwbuuwgrrguurrwgu +bguguwrbuuubwugggrwrwbgrbgbbgbwbrubgwubgwuurwwuugwgggwuu +gwuurubuwrgbgrubwwrrwbbwrguubwrrwrwwrbggrguwugg +gwgugwrgrgggbruwbrwwguwbwrbbbruwgwbrwubwwwwrrgurbwwwwbbbgrw +bguugbwbrbwwwbbuwuwruwgbgbbwrbwwgbrurrurwuwg +gwguwbwwgubrrurbubrurgrbbrrggrrgwubruurburwbrwurubbubwbwb +rwwwururrbwubgurbgbgbbgrrwgwuuuuugbwbbrubwrrbgwbbu +gwgrgrurrrurgbrwubgurgwwbggbwwurwguwggugugg +gwguuuwguwwubruwubbugwwuwwrubrururgbrguwgr +urrbuwurwbggugrwrwgurbgggwuuwbrrrububguwruuuwrruwrbgbu +gwgubgrguubbbbrbrguwgbwrbbubggbwwuubrbugrgbgrbwuwgbuwrgbrgu +ggwgwgbgwgrgbbuggrubbbgugbrgrgwrbrgurwurggwu +gruuugrbbbwwrrubgguwbwgrrurggrubrbbuwbugbguwrrw +gwguwrbbubrrgwggrrbuguwbwrrgbwgggggrgbwwgrgb +urrrugrbugwwurwuuwwwgbbbbgrgbuwbgguwugrwrubr +gwggwubgrwrrgbwurwrgwwggurrburgwbuurgbruuuubgbuwrugrwruwr +brbbrbwwrruguruuwrburrwuubbrbwurwgbggbgbuugwrgbw +gwggbwbbugwgwgrwwuggbbugwwgubbuwugbrgbbuurg +gwrrguuguuggbbbwuwrrwwwrwuwrwwgbuwbbrbgrwwgurubrubrrbuuw +gwgubugrbbrbuwugwwubrrwwbwgugbuwwgguurruurbwbbugr +wgbwwgbuwurggurrgbrrurwwbgwbugrgbwubgggbrbbruwg +ugwgrrggwbugwbrugrggwubbbggrrruggwuuuggwrwugbuubuubuwrugr +rbubguguubuwgwgwgbuwurwburuwwwguwbubbruguwuu +gwgurugbrugggrurrburgrgubguwbwwgbrgrbruguguuubwwrgur +bwwrrbwrruwgbgwgrubruugwrrwgrrbruwwwuwbuwuuwuwr +gwggwwbggruurbuwbbugrrwwgrgrrrububgrbbgr +gwggubggbwgwubruubgubugurrrrrurubwrruuuwuurugrubr +gwgggurrrggbgruggrbgwuwrguwrgwbbgwrubwuuwrgguurwwwrbbgbgbur +bwurgbbbgwguruugwurgrrbwggbwrrwrburugurbur +wbggwubggwwwbugwgrggwbuwubwgrwggbbgbuwbbwb +grurwgbgruggguguwbrugggwubbugrgbugrbbgbguruwwrbgbgwwggbrbb +wrguuggubwwurwuububgruwubggwburbwgwuubbwwgrrgbgrbwubrwgbg +uwrrwurrugwbrgwbuwbwwrwggbwwbuguwbwbbwwgrw +wbwwurwrgbrugbbwbubuwbwwwgrbbwugbguggwgwggww +wbwgbgbgbbbgrbgurwgurwwrggbbwuwbgrwubwbgwgr +rurrwuwugbgwbrwwguuuurrwgbuwbbwbubwburgwruwurggwbrr +uwubrbgubruuubruurbbwwrwgwuuwrbwguwgubrrrgruubw +rwruubbuuwwbbbbbwggwgbwuguuuuwwuuubuubgggbgbbrguwuwg +gwguubrwuuuwwgugugbgbuwbuwgwrbrbuuuwgrgbgubbr +rwrrugugubwbbgugrbwurgbwguwrbuggrwbubbrugruggrbbbrubrgwgwr +gwgurwrwrubuwgrwwugugguwgrwbgggwrubbrbwwgbrgrur +wubguuwwgrggbrwwbgrgugugrguwrubggugwwuwrbrggwwww +gwgrwwwrbgrrbwgrbgrugbbggbbbgugbbwwwgbuggr +gwgrubrrugrwwgurbbububurrbbbwrgwwrguuugbuuwwbuwwbbbgbbwurgrb +gwgrbuugugbgwurgwrruwbuguububuwgbbbwrbgrwbbrurwbbrbuwrr +gwggwuuuuurrrurwwurugwwwgggwurbgbbrwrgwgwug +rwbguuwgggbwwuwwwugurwrwuwbrwwgbgwwwbbuubrw +gwgurggurbugrwrwguwugwbwguubggruurwurwurubuurwgwbwuwg +grwgwrbwbgwrbrgwuururwurbbubrubrwwwgbrbrbbw +gwgrugurwguwwrgurwugwurbruuwbuuuwurbrgwwuuwgbg +wrwgwgrwwwwrrggugbbwwbgwwbgbbwgrbgugurbwguw +bbubrbrrubwggurruwrggwuurgwgwbwbrbububwbwurrrwbggbur +wwrwwbrgrrrgburwuwwgurubrwguwbgurbwrrwbwwgwwrbbwrrwwww +uruuurgbgbuwuwgwgbubbrgrwggbbgrbwuwgubrgurgrgburrwrgb +gwggrgwbgrrugugwugwgwguuwwuuwwgrgwbuurrgw +gwgubgwguwwbugbgwgrurrgurgwwggbggbugrrgwrbwwwwguugbgubrbwgb +wggbrubwuurbrggwgwwuurggwbubggrbggrgwwwuug +gwggbburgbbrwwbrrbuuuwwbrugbbwwrrwrguwwubuwwuurruru +uwgggwgrwruwwgburrwwbggwgbrurrrgubrrwrrwbbuuuwuwugrgg +gwrggwwrrbwrrubbwrurbgwrwuwuwggrbbbbgrbubg +gwburgrgugwwuurrwuuwuuuuburbbwgrruuubruururgwruubrubrugu +wbwwbubwburwgbbgwgbubuubrguwgbwwggbuwbguurgurbbwuwbugrrb +gwgurwrurggwwguburuwgbgrrrgruwwggrruruwruuwrggrrbu +gugwgrggburwgbwbwbgbuuwwbbwrwgwbwurwgrbbbu +gwgrrwgugbubrrrgrwwbrrggwrrrgurgwgrbbuggwru +wbruwbbgbuwbrwwwbrrrwuwugwbggrrbuuwgubwrrwuwurggruurrgw +gwguubbuuubgrwbuubwbuwgwwgwgubrrrbburggubwwugr +ggrrguggbbbrggbgwwuubbwrrrrrbwruguuggrbbggrbgwr +rgbubuguwggwrrwgwugrgggwuwwbwbwubbruubrgru +ggggrrwgubrbrwuggbrubbrwwuugbuwrwrurgwgwwbbwugbrurbg +ggbggbrwrurrurubrruuggurwwguwrguurrbgrrgru +gwgrwuugbgwrbwbgrwwrgurrruwgbbrggwrrrruruug +gwggrgbbwwrwrrggbbbgggburuubbbbguruurbgwbrbrwgg +gwguuwuubuurwuububbgubwugurrgurrwurwubgbrugbwbwrbuwwrwrurg +wguwwwrrrwguwrrbuguuubguurggrwbbbwrugggruuggrbu +rrwgwgbugbwbrbbgrbbbbrgbbuuugruwbgbwwbrwwrw +rwggbggwbrruwruubwrgrwrwuggubuwwbbubrbwbrwbuuurgggggburb +gwggugbguwubgrwruwwuuuggbrbbubbububbwrbwbggguruwbru +uuuurbuurwbgwuuuuuurwuuugwugrgwwrrbrrwbrrgbgwbuwbggw +ugburrwuwbggrwuuruuwbrrrgbrubwguguwbugwbuwbbbgru diff --git a/2024/19-Linen_Layout/second.hs b/2024/19-Linen_Layout/second.hs new file mode 100644 index 0000000..a102f3d --- /dev/null +++ b/2024/19-Linen_Layout/second.hs @@ -0,0 +1,48 @@ +-- requires cabal install --lib megaparsec parser-combinators heap vector +module Main (main) where + +import Control.Monad (void, when) +import Data.Functor +import qualified Data.List as L +import qualified Data.Map as M +import Data.Maybe +import Data.Void (Void) +import Text.Megaparsec +import Text.Megaparsec.Char + +exampleExpectedOutput = 16 + +type Input = ([String], [String]) -- patterns, designs + +type Parser = Parsec Void String + +parseInput' :: Parser Input +parseInput' = (,) <$> some (some letterChar <* optional (string ", ")) <* eol <* eol + <*> some (some letterChar <* eol) <* eof + +parseInput :: String -> IO Input +parseInput filename = do + input <- readFile filename + case runParser parseInput' filename input of + Left bundle -> error $ errorBundlePretty bundle + Right input' -> return input' + +type Memo = M.Map String Int + +compute :: Input -> Int +compute (stripes, designs) = snd $ L.foldl' compute' (M.empty, 0) designs + where + compute' :: (Memo, Int) -> String -> (Memo, Int) + compute' (memo, c) [] = (memo, c + 1) + compute' (memo, c) design = case M.lookup design memo of + Just c' -> (memo, c + c') + Nothing -> let (memo', c') = L.foldl' compute' (memo, 0) $ catMaybes $ map (\s -> L.stripPrefix s design) stripes + in (M.insert design c' memo', c + c') + +main :: IO () +main = do + example <- parseInput "example" + let exampleOutput = compute example + when (exampleOutput /= exampleExpectedOutput) (error $ "example failed: got " ++ show exampleOutput ++ " instead of " ++ show exampleExpectedOutput) + input <- parseInput "input" + print $ compute input |