├── .ghcid ├── .github └── workflows │ └── haskell.yml ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── advent2019.cabal ├── common ├── Advent.hs └── Advent │ ├── Coord.hs │ ├── PQueue.hs │ ├── Queue.hs │ ├── Search.hs │ └── Visualize.hs ├── doctests.hs ├── execs ├── Day01.hs ├── Day02.hs ├── Day03.hs ├── Day04.hs ├── Day05.hs ├── Day06.hs ├── Day07.hs ├── Day08.hs ├── Day09.hs ├── Day10.hs ├── Day11.hs ├── Day12.hs ├── Day13.hs ├── Day14.hs ├── Day15.hs ├── Day16.hs ├── Day17.hs ├── Day18.hs ├── Day19.hs ├── Day20.hs ├── Day21.hs ├── Day22.hs ├── Day23.hs ├── Day24.hs ├── Day25.hs └── IntcodeConsole.hs └── inputs ├── input01.txt ├── input02.txt ├── input03.txt ├── input04.txt ├── input05.txt ├── input06.txt ├── input07.txt ├── input08.txt ├── input09.txt ├── input10.txt ├── input11.txt ├── input12.txt ├── input13.txt ├── input14.txt ├── input15.txt ├── input16.txt ├── input17.txt ├── input18.txt ├── input19.txt ├── input20.txt ├── input21.txt ├── input22.txt ├── input23.txt ├── input24.txt └── input25.txt /.ghcid: -------------------------------------------------------------------------------- 1 | --command="cabal v2-repl --repl-options=-fno-break-on-exception --repl-options=-fno-break-on-error --repl-options=-v1 --repl-options=-ferror-spans --repl-options=-j --repl-options=-Wall" 2 | -------------------------------------------------------------------------------- /.github/workflows/haskell.yml: -------------------------------------------------------------------------------- 1 | name: Haskell CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v2 12 | - uses: actions/setup-haskell@v1 13 | with: 14 | ghc-version: '8.10.2' 15 | cabal-version: '3.2' 16 | - name: Install dependencies 17 | run: | 18 | cabal update 19 | cabal install --only-dependencies 20 | - name: Build 21 | run: | 22 | cabal configure --enable-tests --write-ghc-environment-files=always 23 | cabal build 24 | - name: Run tests 25 | run: cabal test 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | dist-*/ 3 | .HTF/ 4 | log/ 5 | .cabal-sandbox/ 6 | .stack-work/ 7 | cabal-dev 8 | *# 9 | *.aux 10 | *.bundle 11 | *.chi 12 | *.chs.h 13 | *.dSYM 14 | *.dylib 15 | *.dyn_hi 16 | *.dyn_o 17 | *.eventlog 18 | *.hi 19 | *.hp 20 | *.o 21 | *.a 22 | *.prof 23 | *.so 24 | *~ 25 | .*.swo 26 | .*.swp 27 | .DS_Store 28 | .hpc 29 | .hsenv 30 | TAGS 31 | cabal.project.local 32 | cabal.sandbox.config 33 | codex.tags 34 | docs 35 | stack.yaml 36 | tags 37 | wiki 38 | wip 39 | .ghc.environment.* 40 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # This Travis job script has been generated by a script via 2 | # 3 | # haskell-ci 'advent2019.cabal' 4 | # 5 | # To regenerate the script (for example after adjusting tested-with) run 6 | # 7 | # haskell-ci regenerate 8 | # 9 | # For more information, see https://github.com/haskell-CI/haskell-ci 10 | # 11 | # version: 0.10.3 12 | # 13 | version: ~> 1.0 14 | language: c 15 | os: linux 16 | dist: xenial 17 | git: 18 | # whether to recursively clone submodules 19 | submodules: false 20 | cache: 21 | directories: 22 | - $HOME/.cabal/packages 23 | - $HOME/.cabal/store 24 | - $HOME/.hlint 25 | before_cache: 26 | - rm -fv $CABALHOME/packages/hackage.haskell.org/build-reports.log 27 | # remove files that are regenerated by 'cabal update' 28 | - rm -fv $CABALHOME/packages/hackage.haskell.org/00-index.* 29 | - rm -fv $CABALHOME/packages/hackage.haskell.org/*.json 30 | - rm -fv $CABALHOME/packages/hackage.haskell.org/01-index.cache 31 | - rm -fv $CABALHOME/packages/hackage.haskell.org/01-index.tar 32 | - rm -fv $CABALHOME/packages/hackage.haskell.org/01-index.tar.idx 33 | - rm -rfv $CABALHOME/packages/head.hackage 34 | jobs: 35 | include: 36 | - compiler: ghc-8.10.2 37 | addons: {"apt":{"sources":[{"sourceline":"deb http://ppa.launchpad.net/hvr/ghc/ubuntu xenial main","key_url":"https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x063dab2bdc0b3f9fcebc378bff3aeacef6f88286"}],"packages":["ghc-8.10.2","cabal-install-3.2"]}} 38 | os: linux 39 | before_install: 40 | - HC=$(echo "/opt/$CC/bin/ghc" | sed 's/-/\//') 41 | - WITHCOMPILER="-w $HC" 42 | - HADDOCK=$(echo "/opt/$CC/bin/haddock" | sed 's/-/\//') 43 | - HCPKG="$HC-pkg" 44 | - unset CC 45 | - CABAL=/opt/ghc/bin/cabal 46 | - CABALHOME=$HOME/.cabal 47 | - export PATH="$CABALHOME/bin:$PATH" 48 | - TOP=$(pwd) 49 | - "HCNUMVER=$(${HC} --numeric-version|perl -ne '/^(\\d+)\\.(\\d+)\\.(\\d+)(\\.(\\d+))?$/; print(10000 * $1 + 100 * $2 + ($3 == 0 ? $5 != 1 : $3))')" 50 | - echo $HCNUMVER 51 | - CABAL="$CABAL -vnormal+nowrap" 52 | - set -o pipefail 53 | - TEST=--enable-tests 54 | - BENCH=--enable-benchmarks 55 | - HEADHACKAGE=false 56 | - rm -f $CABALHOME/config 57 | - | 58 | echo "verbose: normal +nowrap +markoutput" >> $CABALHOME/config 59 | echo "remote-build-reporting: anonymous" >> $CABALHOME/config 60 | echo "write-ghc-environment-files: always" >> $CABALHOME/config 61 | echo "remote-repo-cache: $CABALHOME/packages" >> $CABALHOME/config 62 | echo "logs-dir: $CABALHOME/logs" >> $CABALHOME/config 63 | echo "world-file: $CABALHOME/world" >> $CABALHOME/config 64 | echo "extra-prog-path: $CABALHOME/bin" >> $CABALHOME/config 65 | echo "symlink-bindir: $CABALHOME/bin" >> $CABALHOME/config 66 | echo "installdir: $CABALHOME/bin" >> $CABALHOME/config 67 | echo "build-summary: $CABALHOME/logs/build.log" >> $CABALHOME/config 68 | echo "store-dir: $CABALHOME/store" >> $CABALHOME/config 69 | echo "install-dirs user" >> $CABALHOME/config 70 | echo " prefix: $CABALHOME" >> $CABALHOME/config 71 | echo "repository hackage.haskell.org" >> $CABALHOME/config 72 | echo " url: http://hackage.haskell.org/" >> $CABALHOME/config 73 | install: 74 | - ${CABAL} --version 75 | - echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]" 76 | - | 77 | echo "program-default-options" >> $CABALHOME/config 78 | echo " ghc-options: $GHCJOBS +RTS -M6G -RTS" >> $CABALHOME/config 79 | - cat $CABALHOME/config 80 | - rm -fv cabal.project cabal.project.local cabal.project.freeze 81 | - travis_retry ${CABAL} v2-update -v 82 | # Generate cabal.project 83 | - rm -rf cabal.project cabal.project.local cabal.project.freeze 84 | - touch cabal.project 85 | - | 86 | echo "packages: ." >> cabal.project 87 | - echo 'package advent2019' >> cabal.project 88 | - "echo ' ghc-options: -Werror=missing-methods' >> cabal.project" 89 | - | 90 | - "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | (grep -vE -- '^(advent2019)$' || true) | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done" 91 | - cat cabal.project || true 92 | - cat cabal.project.local || true 93 | - if [ -f "./configure.ac" ]; then (cd "." && autoreconf -i); fi 94 | - ${CABAL} v2-freeze $WITHCOMPILER ${TEST} ${BENCH} 95 | - "cat cabal.project.freeze | sed -E 's/^(constraints: *| *)//' | sed 's/any.//'" 96 | - rm cabal.project.freeze 97 | - travis_wait 40 ${CABAL} v2-build $WITHCOMPILER ${TEST} ${BENCH} --dep -j2 all 98 | - travis_wait 40 ${CABAL} v2-build $WITHCOMPILER --disable-tests --disable-benchmarks --dep -j2 all 99 | script: 100 | - DISTDIR=$(mktemp -d /tmp/dist-test.XXXX) 101 | # Packaging... 102 | - ${CABAL} v2-sdist all 103 | # Unpacking... 104 | - mv dist-newstyle/sdist/*.tar.gz ${DISTDIR}/ 105 | - cd ${DISTDIR} || false 106 | - find . -maxdepth 1 -type f -name '*.tar.gz' -exec tar -xvf '{}' \; 107 | - find . -maxdepth 1 -type f -name '*.tar.gz' -exec rm '{}' \; 108 | - PKGDIR_advent2019="$(find . -maxdepth 1 -type d -regex '.*/advent2019-[0-9.]*')" 109 | # Generate cabal.project 110 | - rm -rf cabal.project cabal.project.local cabal.project.freeze 111 | - touch cabal.project 112 | - | 113 | echo "packages: ${PKGDIR_advent2019}" >> cabal.project 114 | - echo 'package advent2019' >> cabal.project 115 | - "echo ' ghc-options: -Werror=missing-methods' >> cabal.project" 116 | - | 117 | - "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | (grep -vE -- '^(advent2019)$' || true) | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done" 118 | - cat cabal.project || true 119 | - cat cabal.project.local || true 120 | # Building... 121 | # this builds all libraries and executables (without tests/benchmarks) 122 | - ${CABAL} v2-build $WITHCOMPILER --disable-tests --disable-benchmarks all 123 | # Building with tests and benchmarks... 124 | # build & run tests, build benchmarks 125 | - ${CABAL} v2-build $WITHCOMPILER ${TEST} ${BENCH} all 126 | # Testing... 127 | - ${CABAL} v2-test $WITHCOMPILER ${TEST} ${BENCH} all 128 | # cabal check... 129 | - (cd ${PKGDIR_advent2019} && ${CABAL} -vnormal check) 130 | # haddock... 131 | - ${CABAL} v2-haddock $WITHCOMPILER --with-haddock $HADDOCK ${TEST} ${BENCH} all 132 | # Building without installed constraints for packages in global-db... 133 | - rm -f cabal.project.local 134 | - ${CABAL} v2-build $WITHCOMPILER --disable-tests --disable-benchmarks all 135 | 136 | # REGENDATA ("0.10.3",["advent2019.cabal"]) 137 | # EOF 138 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2019 Eric Mertens 2 | 3 | Permission to use, copy, modify, and/or distribute this software for any purpose 4 | with or without fee is hereby granted, provided that the above copyright notice 5 | and this permission notice appear in all copies. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 8 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 9 | FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 10 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 11 | OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 12 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 13 | THIS SOFTWARE. 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Advent of Code 2019 2 | 3 | These are my Advent of Code 2019 solutions. I try to focus on making clean and documented Haskell solutions to each puzzle. 4 | 5 | We'll be chatting about AoC on IRC all December. You can find AoC discussion on [freenode](https://freenode.net)'s `##adventofcode` and `#haskell` ([webchat](https://webchat.freenode.net/#haskell,##adventofcode)) 6 | 7 | ## Building 8 | 9 | I recommend installing `ghc` with `ghcup`. 10 | 11 | ``` 12 | $ curl https://get-ghcup.haskell.org -sSf | sh 13 | ``` 14 | 15 | I'm using `GHC 8.8.1` this year 16 | 17 | ``` 18 | $ ghcup install 8.8.1 19 | $ ghcup set 8.8.1 20 | ``` 21 | 22 | `cabal-install-3` is the best way to get things built 23 | 24 | ``` 25 | $ cabal update 26 | $ cabal build 27 | ``` 28 | 29 | ## Running solutions 30 | 31 | All the solutions take an optional command line argument that can be an input file name or `-` to read the input from `stdin`. 32 | 33 | ``` 34 | $ cabal run Day01 35 | ... 36 | 3188480 37 | 4779847 38 | ``` 39 | 40 | ## Intcode Interpreter 41 | 42 | A few of my solutions rely on a Intcode interpreter library that I have extracted from this repository now that the contest is complete: [Intcode.hs](https://github.com/glguy/intcode/blob/master/src/Intcode.hs) 43 | 44 | ## Common libraries used 45 | 46 | * **containers** - Almost all of the solutions will benefit from having access to `Map` and `Set` types from this package. 47 | * **megaparsec** - Each problem features a simple text-file format input. Parser combinators make it easy to define the simple parser needed to consume these inputs. 48 | * **doctest** - Having checked examples in the documentation makes it easier to understand what code does and easy to add unit tests. 49 | -------------------------------------------------------------------------------- /advent2019.cabal: -------------------------------------------------------------------------------- 1 | cabal-version: 2.4 2 | name: advent2019 3 | version: 0.1.0.0 4 | category: None 5 | synopsis: Advent of Code 2019 Solutions 6 | description: These are my cleaned-up solutions to the Advent of Code 7 | programming game. 8 | license: ISC 9 | license-file: LICENSE 10 | author: Eric Mertens 11 | maintainer: emertens@gmail.com 12 | copyright: 2019 Eric Mertens 13 | homepage: https://github.com/glguy/advent2019 14 | bug-reports: https://github.com/glguy/advent2019/issues 15 | build-type: Simple 16 | tested-with: GHC==8.10.2 17 | 18 | source-repository head 19 | type: git 20 | location: https://github.com/glguy/advent2019 21 | 22 | common intcode 23 | build-depends: intcode ^>= 0.3, 24 | 25 | library 26 | hs-source-dirs: common 27 | default-language: Haskell2010 28 | 29 | exposed-modules: 30 | Advent 31 | Advent.Coord 32 | Advent.PQueue 33 | Advent.Search 34 | Advent.Queue 35 | Advent.Visualize 36 | 37 | build-depends: 38 | base ^>= 4.14, 39 | containers ^>= 0.6, 40 | JuicyPixels ^>= 3.3.2, 41 | megaparsec ^>= 9.0, 42 | 43 | 44 | test-suite doctests 45 | type: exitcode-stdio-1.0 46 | ghc-options: -threaded 47 | main-is: doctests.hs 48 | default-language: Haskell2010 49 | 50 | build-depends: 51 | base, 52 | doctest ^>= 0.17, 53 | directory ^>= 1.3, 54 | filepath ^>= 1.4, 55 | 56 | common day 57 | build-depends: advent2019, base 58 | hs-source-dirs: execs 59 | default-language: Haskell2010 60 | 61 | executable IntcodeConsole 62 | import: day, intcode 63 | main-is: IntcodeConsole.hs 64 | ghc-options: -threaded 65 | build-depends: transformers, containers, megaparsec, ansi-terminal 66 | 67 | executable Day01 68 | import: day 69 | main-is: Day01.hs 70 | 71 | executable Day02 72 | import: day, intcode 73 | main-is: Day02.hs 74 | 75 | executable Day03 76 | import: day 77 | main-is: Day03.hs 78 | build-depends: containers 79 | 80 | executable Day04 81 | import: day 82 | main-is: Day04.hs 83 | 84 | executable Day05 85 | import: day, intcode 86 | main-is: Day05.hs 87 | build-depends: containers 88 | 89 | executable Day06 90 | import: day 91 | main-is: Day06.hs 92 | build-depends: containers 93 | 94 | executable Day07 95 | import: day, intcode 96 | main-is: Day07.hs 97 | build-depends: containers 98 | 99 | executable Day08 100 | import: day 101 | main-is: Day08.hs 102 | build-depends: containers 103 | 104 | executable Day09 105 | import: day, intcode 106 | main-is: Day09.hs 107 | build-depends: containers 108 | 109 | executable Day10 110 | import: day 111 | main-is: Day10.hs 112 | build-depends: containers 113 | 114 | executable Day11 115 | import: day, intcode 116 | main-is: Day11.hs 117 | build-depends: containers 118 | 119 | executable Day12 120 | import: day 121 | main-is: Day12.hs 122 | 123 | executable Day13 124 | import: day, intcode 125 | main-is: Day13.hs 126 | build-depends: containers 127 | 128 | executable Day14 129 | import: day 130 | main-is: Day14.hs 131 | build-depends: containers 132 | 133 | executable Day15 134 | import: day, intcode 135 | main-is: Day15.hs 136 | 137 | executable Day16 138 | import: day 139 | main-is: Day16.hs 140 | build-depends: vector 141 | 142 | executable Day17 143 | import: day, intcode 144 | main-is: Day17.hs 145 | build-depends: containers 146 | 147 | executable Day18 148 | import: day 149 | main-is: Day18.hs 150 | build-depends: containers, array 151 | 152 | executable Day19 153 | import: day, intcode 154 | main-is: Day19.hs 155 | 156 | executable Day20 157 | import: day 158 | main-is: Day20.hs 159 | build-depends: containers, array 160 | 161 | executable Day21 162 | import: day, intcode 163 | main-is: Day21.hs 164 | 165 | executable Day22 166 | import: day 167 | main-is: Day22.hs 168 | build-depends: mod 169 | 170 | executable Day23 171 | import: day, intcode 172 | main-is: Day23.hs 173 | build-depends: containers, transformers 174 | 175 | executable Day24 176 | import: day 177 | main-is: Day24.hs 178 | build-depends: containers 179 | 180 | executable Day25 181 | import: day, intcode 182 | main-is: Day25.hs 183 | -------------------------------------------------------------------------------- /common/Advent.hs: -------------------------------------------------------------------------------- 1 | {-# Language OverloadedStrings #-} 2 | module Advent 3 | ( module Advent 4 | , satisfy, anySingle, sepBy, manyTill 5 | ) where 6 | 7 | import System.Environment 8 | import Text.Printf 9 | import Data.Foldable (toList) 10 | import Text.Megaparsec (setInput, anySingle, satisfy, parse, Parsec, eof, sepBy, manyTill) 11 | import Text.Megaparsec.Char (newline) 12 | import Text.Megaparsec.Char.Lexer (decimal, signed) 13 | import Text.Megaparsec.Error (errorBundlePretty) 14 | import Data.Void 15 | import Data.List 16 | import qualified Data.Set as Set 17 | import Data.Map (Map) 18 | import qualified Data.Map as Map 19 | 20 | -- | Get the input for the given day. 21 | -- 22 | -- If a filename is provided in the command line that will be used as the 23 | -- input file. 24 | -- 25 | -- If the filename is @-@ the stdin will be used as the input file. 26 | -- 27 | -- Otherwise the input text file corresponding to the day number will be used. 28 | getRawInput :: Int {- ^ day number -} -> IO String 29 | getRawInput i = 30 | do args <- getArgs 31 | case args of 32 | [] -> readFile (printf "inputs/input%02d.txt" i) 33 | "-":_ -> getContents 34 | fn:_ -> readFile fn 35 | 36 | inputFileName :: Int -> FilePath 37 | inputFileName = printf "inputs/input%02d.txt" 38 | 39 | getInputLines :: Int -> IO [String] 40 | getInputLines i = lines <$> getRawInput i 41 | 42 | type Parser = Parsec Void String 43 | 44 | getParsedInput :: Int -> Parser a -> IO a 45 | getParsedInput i p = 46 | do input <- getRawInput i 47 | case parse p "input" input of 48 | Left e -> fail (errorBundlePretty e) 49 | Right a -> return a 50 | 51 | -- | Run a parser with 'parseLines' on the input file. 52 | getParsedLines :: Int -> Parser a -> IO [a] 53 | getParsedLines i p = 54 | do input <- getRawInput i 55 | either fail return (parseLines p input) 56 | 57 | -- | Run a parser on each line of the input file. Each line will be parsed 58 | -- in isolation. The parser must consume the whole line. 59 | -- 60 | -- >>> parseLines (Control.Applicative.many anySingle) "12\n34\n" 61 | -- Right ["12","34"] 62 | -- >>> parseLines number "12\n34\n" 63 | -- Right [12,34] 64 | parseLines :: Parser a -> String -> Either String [a] 65 | parseLines p input = 66 | case parse (traverse parse1 (lines input)) "input" input of 67 | Left e -> Left (errorBundlePretty e) 68 | Right a -> Right a 69 | where 70 | parse1 x = setInput x *> p <* eof <* setInput "\n" <* newline 71 | 72 | -- | Count the number of elements in a foldable value that satisfy a predicate. 73 | count :: Foldable t => (a -> Bool) -> t a -> Int 74 | count p = foldl' (\acc x -> if p x then acc+1 else acc) 0 75 | 76 | 77 | -- | Return true when the whole list is comprised of equal elements. 78 | -- 79 | -- >>> same [1,1,1] 80 | -- True 81 | -- >>> same [] 82 | -- True 83 | -- >>> same [1] 84 | -- True 85 | -- >>> same [1,1,2] 86 | -- False 87 | same :: Foldable t => Eq a => t a -> Bool 88 | same xs = all (head (toList xs) ==) xs 89 | 90 | -- | Returns a list of ways to select an element from a list without 91 | -- replacement. 92 | -- 93 | -- >>> pickOne [] 94 | -- [] 95 | -- >>> pickOne [1] 96 | -- [(1,[])] 97 | -- >>> pickOne [1,2,3] 98 | -- [(1,[2,3]),(2,[1,3]),(3,[1,2])] 99 | pickOne :: [a] -> [(a, [a])] 100 | pickOne xs = [ (x, l++r) | (l,x:r) <- zip (inits xs) (tails xs) ] 101 | 102 | -- | Parse a signed integral number 103 | number :: Integral a => Parser a 104 | number = signed (return ()) decimal 105 | 106 | -- | Implementation of 'nub' that uses 'Ord' for efficiency. 107 | ordNub :: Ord a => [a] -> [a] 108 | ordNub = go Set.empty 109 | where 110 | go _ [] = [] 111 | go seen (x:xs) 112 | | Set.member x seen = go seen xs 113 | | otherwise = x : go (Set.insert x seen) xs 114 | 115 | 116 | -- | Compute the minimum element of a list or return Nothing if it is empty. 117 | -- 118 | -- >>> minimumMaybe [] 119 | -- Nothing 120 | -- >>> minimumMaybe [2,1,3] 121 | -- Just 1 122 | minimumMaybe :: Ord a => [a] -> Maybe a 123 | minimumMaybe xs 124 | | null xs = Nothing 125 | | otherwise = Just $! minimum xs 126 | 127 | -- | Compute the number of occurrences of the elements in a given list. 128 | -- 129 | -- >>> cardinality "bababc" 130 | -- fromList [('a',2),('b',3),('c',1)] 131 | cardinality :: Ord a => [a] -> Map a Int 132 | cardinality xs = Map.fromListWith (+) [ (x,1) | x <- xs ] 133 | 134 | -- | Compose a list of functions together 135 | -- 136 | -- >>> compose [ (1:), (2:), (3:) ] [] 137 | -- [1,2,3] 138 | compose :: [a -> a] -> a -> a 139 | compose = foldr (.) id 140 | 141 | chunks :: Int -> [a] -> [[a]] 142 | chunks _ [] = [] 143 | chunks n xs = 144 | case splitAt n xs of 145 | (a,b) -> a : chunks n b 146 | 147 | memoryParser :: Parser [Int] 148 | memoryParser = number `sepBy` "," 149 | 150 | getIntcodeInput :: Int -> IO [Int] 151 | getIntcodeInput i = getParsedInput i (memoryParser <* newline <* eof) 152 | -------------------------------------------------------------------------------- /common/Advent/Coord.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Advent.Coord 3 | Description : Row-major coordinates 4 | Copyright : (c) Eric Mertens, 2018 5 | License : ISC 6 | Maintainer : emertens@gmail.com 7 | 8 | -} 9 | {-# Language BangPatterns, TypeFamilies, TypeOperators, DeriveGeneric #-} 10 | module Advent.Coord where 11 | 12 | import Data.Foldable 13 | import Data.Ix 14 | import Data.Map (Map) 15 | import qualified Data.Map as Map 16 | import GHC.Arr 17 | import GHC.Generics 18 | 19 | data Coord = C !Int !Int 20 | deriving (Read, Show, Ord, Eq, Generic) 21 | 22 | coordRow, coordCol :: Coord -> Int 23 | coordRow (C row _) = row 24 | coordCol (C _ col) = col 25 | 26 | instance Ix Coord where 27 | unsafeIndex (C lorow locol, C _hirow hicol) (C row col) = 28 | (row - lorow) * (hicol - locol + 1) + (col - locol) 29 | 30 | inRange (C lorow locol, C hirow hicol) (C row col) = 31 | lorow <= row && row <= hirow && 32 | locol <= col && col <= hicol 33 | 34 | range (C lorow locol, C hirow hicol) = 35 | [ C row col | row <- [lorow..hirow], col <- [locol..hicol]] 36 | 37 | above, below, left, right :: Coord -> Coord 38 | above (C y x) = C (y-1) x 39 | below (C y x) = C (y+1) x 40 | left (C y x) = C y (x-1) 41 | right (C y x) = C y (x+1) 42 | 43 | turnLeft, turnRight, turnAround :: Coord -> Coord 44 | turnLeft (C y x) = C (-x) y 45 | turnRight (C y x) = C x (-y) 46 | turnAround (C y x) = C (-y) (-x) 47 | 48 | -- | Compute the Manhattan distance between two coordinates 49 | manhattan :: Coord -> Coord -> Int 50 | manhattan (C x y) (C u v) = abs (x-u) + abs (y-v) 51 | 52 | -- | Compute the 4 cardinal neighbors of a coordinate: north, south, east, west 53 | cardinal :: Coord -> [Coord] 54 | cardinal c = c `seq` [above c, left c, right c, below c] 55 | 56 | -- | Compute the 8 cardinal neighbors and diagonal neighbors 57 | neighbors :: Coord -> [Coord] 58 | neighbors c = c `seq` [above c, left c, right c, below c, 59 | above (left c), above (right c), 60 | below (left c), below (right c)] 61 | 62 | boundingBox :: Foldable t => t Coord -> Maybe (Coord, Coord) 63 | boundingBox t = 64 | case toList t of 65 | [] -> Nothing 66 | C y x : cs -> go y x y x cs 67 | where 68 | go loy lox hiy hix [] = Just (C loy lox, C hiy hix) 69 | go loy lox hiy hix (C y x : cs) = go (min loy y) (min lox x) (max hiy y) (max hix x) cs 70 | 71 | origin :: Coord 72 | origin = C 0 0 73 | 74 | north :: Coord 75 | north = C (-1) 0 76 | 77 | addCoord :: Coord -> Coord -> Coord 78 | addCoord (C y x) (C v u) = C (y+v) (x+u) 79 | 80 | drawCoords :: Map Coord Char -> String 81 | drawCoords pixels = unlines [[pixel (C y x) | x <- [minx .. maxx]] | y <- [miny .. maxy]] 82 | where 83 | pixel c = Map.findWithDefault ' ' c pixels 84 | Just (C miny minx, C maxy maxx) = boundingBox (Map.keys pixels) 85 | 86 | coordLines :: [String] -> [(Coord, Char)] 87 | coordLines rows = [(C y x, z) | (y,row) <- zip [0..] rows, (x,z) <- zip [0..] row] 88 | -------------------------------------------------------------------------------- /common/Advent/PQueue.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Advent.PQueue 3 | Description : Int-priority min queue 4 | Copyright : (c) Eric Mertens, 2018 5 | License : ISC 6 | Maintainer : emertens@gmail.com 7 | -} 8 | {-# Language PatternSynonyms, ViewPatterns, DeriveTraversable #-} 9 | {-# Options_GHC -Wno-name-shadowing #-} 10 | module Advent.PQueue 11 | ( PQueue(Empty, (:<|)) 12 | 13 | -- * Construction 14 | , singleton 15 | , fromList 16 | 17 | -- * Insertion 18 | , insert 19 | 20 | -- * Query 21 | , Advent.PQueue.null 22 | , view 23 | , viewWithPriority 24 | ) where 25 | 26 | import Data.IntMap (IntMap) 27 | import qualified Data.IntMap as IntMap 28 | 29 | -- | Priority queue. No guarantees are made regarding the order 30 | -- entries with the same priority are returned in. 31 | newtype PQueue a = PQ (IntMap [a]) -- invariant: all values non-empty 32 | deriving (Functor, Foldable, Traversable) 33 | 34 | -- | Show a 'PQueue' using 'fromList' 35 | -- 36 | -- >>> show (singleton 1 'a') 37 | -- "fromList [(1,'a')]" 38 | instance Show a => Show (PQueue a) where 39 | showsPrec prec (PQ q) 40 | = showParen (prec >= 11) 41 | $ showString "fromList " 42 | . shows [ (p,v) | (p, vs) <- IntMap.toList q, v <- vs ] 43 | 44 | instance Read a => Read (PQueue a) where 45 | readsPrec prec 46 | = readParen (prec >= 11) $ \str -> 47 | do ("fromList", str) <- lex str 48 | (xs, str) <- reads str 49 | return (fromList xs, str) 50 | 51 | {-# Complete Empty, (:<|) #-} 52 | 53 | -- | Empty priority queue 54 | pattern Empty :: PQueue a 55 | pattern Empty <- (Advent.PQueue.null -> True) 56 | where 57 | Empty = PQ IntMap.empty 58 | 59 | -- | Pattern for extracting an element with the minimum priority 60 | -- from the queue. See also: 'view' 61 | pattern (:<|) :: a -> PQueue a -> PQueue a 62 | pattern v :<| q <- (view -> Just (v,q)) 63 | 64 | -- | Test if a queue has no elements. 65 | null :: PQueue a -> Bool 66 | null (PQ q) = IntMap.null q 67 | 68 | -- | Construct a priority queue from a single priority and value. 69 | singleton :: Int {- ^ priority -} -> a {- ^ value -} -> PQueue a 70 | singleton p v = PQ (IntMap.singleton p [v]) 71 | 72 | -- | Insert a new value into the queue given a priority. 73 | insert :: Int {- ^ priority -} -> a {- ^ value -} -> PQueue a -> PQueue a 74 | insert k v (PQ q) = PQ (IntMap.alter aux k q) 75 | where 76 | aux Nothing = Just [v] 77 | aux (Just vs) = Just (v:vs) 78 | 79 | -- | Match the lowest priority entry in a queue returning the corresponding 80 | -- value and queue without that entry. See also: (':<|') 81 | view :: PQueue a -> Maybe (a, PQueue a) 82 | view (PQ q) = 83 | do ((k,xs),q1) <- IntMap.minViewWithKey q 84 | case xs of 85 | [] -> error "Advent.PQueue.view: Malformed queue" 86 | [x] -> Just (x, PQ q1) 87 | x:xs -> let q2 = PQ (IntMap.insert k xs q1) 88 | in q2 `seq` Just (x,q2) 89 | 90 | -- | Match the lowest priority entry in a queue returning the corresponding 91 | -- priority, value and queue without that entry. 92 | viewWithPriority :: PQueue a -> Maybe (Int, a, PQueue a) 93 | viewWithPriority (PQ q) = 94 | do ((k,xs),q1) <- IntMap.minViewWithKey q 95 | case xs of 96 | [] -> error "Advent.PQueue.view: Malformed queue" 97 | [x] -> Just (k, x, PQ q1) 98 | x:xs -> let q2 = PQ (IntMap.insert k xs q1) 99 | in q2 `seq` Just (k,x,q2) 100 | 101 | -- | Construct a priority queue from a list of priorities and values. 102 | fromList :: [(Int, a)] -> PQueue a 103 | fromList xs = PQ (IntMap.fromListWith (++) [ (p, [v]) | (p, v) <- xs ]) 104 | -------------------------------------------------------------------------------- /common/Advent/Queue.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Advent.Queue 3 | Description : Banker's queue implementation 4 | Copyright : (c) Eric Mertens, 2018 5 | License : ISC 6 | Maintainer : emertens@gmail.com 7 | 8 | -} 9 | {-# Language PatternSynonyms, ViewPatterns #-} 10 | {-# Options_GHC -Wno-name-shadowing #-} 11 | module Advent.Queue (Queue(Empty, (:<|)), (|>), singleton, fromList, snoc, pop, appendList) where 12 | 13 | import Data.Foldable (Foldable(..)) 14 | import Data.Monoid (Dual(..)) 15 | import Data.Coerce (coerce) 16 | 17 | -- | FIFO Queue implementation 18 | data Queue a = Queue [a] !Int [a] !Int 19 | 20 | {-# COMPLETE (:<|), Empty #-} 21 | 22 | -- | Empty queue 23 | -- 24 | -- >>> Empty :: Queue Char 25 | -- fromList "" 26 | pattern Empty :: Queue a 27 | pattern Empty <- Queue [] _ _ _ 28 | where 29 | Empty = Queue [] 0 [] 0 30 | 31 | -- | Pattern for 'pop' 32 | -- 33 | -- >>> let x :<| xs = fromList "abc" in (x, xs) 34 | -- ('a',fromList "bc") 35 | pattern (:<|) :: a -> Queue a -> Queue a 36 | pattern x :<| xs <- (pop -> Just (x, xs)) 37 | 38 | -- | Add an element to the end of a queue. See: 'snoc' 39 | -- 40 | -- >>> fromList "abc" |> 'z' 41 | -- fromList "abcz" 42 | (|>) :: Queue a -> a -> Queue a 43 | q |> x = snoc x q 44 | 45 | -- | Fold over elements in the order they would be returned by pop 46 | -- 47 | -- >>> toList (fromList "abc") 48 | -- "abc" 49 | instance Foldable Queue where 50 | toList (Queue l _ r _) = l ++ reverse r 51 | foldr f z (Queue l _ r _) = foldr f (foldl (flip f) z r) l 52 | foldMap f (Queue l _ r _) = foldMap f l <> getDual (foldMap (coerce f) r) 53 | 54 | -- | Renders using 'fromList' syntax. 55 | -- 56 | -- >>> show (fromList "example") 57 | -- "fromList \"example\"" 58 | instance Show a => Show (Queue a) where 59 | showsPrec p q 60 | = showParen (p >= 11) 61 | $ showString "fromList " 62 | . shows (toList q) 63 | 64 | -- >>> read "fromList \"example\"" :: Queue Char 65 | -- fromList "example" 66 | instance Read a => Read (Queue a) where 67 | readsPrec prec 68 | = readParen (prec >= 11) $ \str -> 69 | do ("fromList", str) <- lex str 70 | (xs, str) <- reads str 71 | return (fromList xs, str) 72 | 73 | -- | Construct a queue from a single element. 74 | -- 75 | -- >>> singleton 'a' 76 | -- fromList "a" 77 | singleton :: a -> Queue a 78 | singleton x = Queue [x] 1 [] 0 79 | 80 | -- | Construct a queue from a list. The head of the list will 81 | -- be the first element returned by 'pop' 82 | fromList :: [a] -> Queue a 83 | fromList xs = Queue xs (length xs) [] 0 84 | 85 | -- | Internal smart constructor for building queues that maintain 86 | -- the invariant that the rear component is never longer than the 87 | -- front component. 88 | mkQueue :: Queue a -> Queue a 89 | mkQueue q@(Queue f lenF r lenR) 90 | | lenR <= lenF = q 91 | | otherwise = Queue (f ++ reverse r) (lenF + lenR) [] 0 92 | 93 | -- | Add a new element to the end of a queue. 94 | -- 95 | -- >>> snoc 'z' (fromList "abc") 96 | -- fromList "abcz" 97 | snoc :: a -> Queue a -> Queue a 98 | snoc x (Queue f lenF r lenR) = mkQueue (Queue f lenF (x:r) (1+lenR)) 99 | 100 | -- | Append many items onto a queue. The items will pop from the queue 101 | -- in the same order as they are in the given list. 102 | -- 103 | -- >>> appendList "abc" (fromList "xyz") 104 | -- fromList "xyzabc" 105 | appendList :: [a] -> Queue a -> Queue a 106 | appendList xs q = foldl' (|>) q xs 107 | 108 | -- | Remove an element from the front of a queue and a new queue 109 | -- without that element. 110 | -- 111 | -- >>> pop (fromList "abc") 112 | -- Just ('a',fromList "bc") 113 | pop :: Queue a -> Maybe (a, Queue a) 114 | pop (Queue (x:f) lenF r lenR) = Just (x, mkQueue (Queue f (lenF-1) r lenR)) 115 | pop _ = Nothing 116 | -------------------------------------------------------------------------------- /common/Advent/Search.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Main 3 | Description : Generalized search functions 4 | Copyright : (c) Eric Mertens, 2019 5 | License : ISC 6 | Maintainer : emertens@gmail.com 7 | 8 | -} 9 | module Advent.Search where 10 | 11 | import qualified Advent.PQueue as PQueue 12 | import qualified Advent.Queue as Queue 13 | import Data.Foldable 14 | import qualified Data.Set as Set 15 | import qualified Data.IntSet as IntSet 16 | 17 | {-# INLINE dfs #-} 18 | dfs :: Ord a => (a -> [a]) -> a -> [a] 19 | dfs = dfsOn id 20 | 21 | dfsOn :: Ord r => (a -> r) -> (a -> [a]) -> a -> [a] 22 | dfsOn rep next start = loop Set.empty [start] 23 | where 24 | loop _ [] = [] 25 | loop seen (x:xs) 26 | | Set.member r seen = loop seen xs 27 | | otherwise = x : loop seen1 (next x ++ xs) 28 | where 29 | r = rep x 30 | seen1 = Set.insert r seen 31 | 32 | {-# INLINE bfs #-} 33 | bfs :: Ord a => (a -> [a]) -> a -> [a] 34 | bfs = bfsOn id 35 | 36 | -- | Enumerate the reachable states in breadth-first order 37 | -- given a successor state function and initial state. 38 | -- 39 | -- States are compared for equality using the representative 40 | -- function. If the representatives are equal the state is 41 | -- considered already visited. 42 | {-# INLINE [0] bfsOn #-} 43 | bfsOn :: 44 | Ord r => 45 | (a -> r) {- ^ representative function -} -> 46 | (a -> [a]) {- ^ successor state generator -} -> 47 | a {- ^ initial state -} -> 48 | [a] {- ^ reachable states -} 49 | bfsOn rep next start = bfsOnN rep next [start] 50 | 51 | {-# INLINE [0] bfsOnN #-} 52 | bfsOnN :: 53 | Ord r => 54 | (a -> r) {- ^ representative function -} -> 55 | (a -> [a]) {- ^ successor state generator -} -> 56 | [a] {- ^ initial state -} -> 57 | [a] {- ^ reachable states -} 58 | bfsOnN rep next start = loop Set.empty (Queue.fromList start) 59 | where 60 | loop _ Queue.Empty = [] 61 | loop seen (x Queue.:<| q1) 62 | | Set.member r seen = loop seen q1 63 | | otherwise = x : loop seen1 q2 64 | where 65 | r = rep x 66 | seen1 = Set.insert r seen 67 | q2 = Queue.appendList (next x) q1 68 | 69 | {-# RULES "bfsOn/Int" bfsOn = bfsOnInt #-} 70 | {-# INLINE bfsOnInt #-} 71 | bfsOnInt :: (a -> Int) -> (a -> [a]) -> a -> [a] 72 | bfsOnInt rep next start = loop IntSet.empty (Queue.singleton start) 73 | where 74 | loop seen q = 75 | case q of 76 | Queue.Empty -> [] 77 | x Queue.:<| q1 78 | | IntSet.member r seen -> loop seen q1 79 | | otherwise -> x : loop seen1 q2 80 | where 81 | r = rep x 82 | seen1 = IntSet.insert r seen 83 | q2 = Queue.appendList (next x) q1 84 | 85 | {-# INLINE astar #-} 86 | astar :: Ord a => (a -> [(a,Int,Int)]) -> a -> [(a,Int)] 87 | astar = astarOn id 88 | 89 | {-# INLINE astarOn #-} 90 | astarOn :: 91 | Ord b => 92 | (a -> b) {- ^ state characterization -} -> 93 | (a -> [(a,Int,Int)]) {- ^ step function (new state, step cost, distance heuristic) -} -> 94 | a {- ^ starting state -} -> 95 | [(a,Int)] {- ^ list of states visited -} 96 | astarOn rep nexts start = go Set.empty (PQueue.singleton 0 (0,start)) 97 | where 98 | go seen work = 99 | case work of 100 | PQueue.Empty -> [] 101 | (cost,x) PQueue.:<| work1 102 | | Set.member r seen -> go seen work1 103 | | otherwise -> (x,cost) : go seen' work2 104 | where 105 | r = rep x 106 | seen' = Set.insert r seen 107 | work2 = foldl' addWork work1 (nexts x) 108 | addWork w (x',stepcost,heuristic) = 109 | let cost' = cost + stepcost 110 | in cost' `seq` 111 | PQueue.insert (cost' + heuristic) (cost', x') w 112 | -------------------------------------------------------------------------------- /common/Advent/Visualize.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Advent.Visualize 3 | Description : Module for visualizing components of the solutions 4 | Copyright : (c) Eric Mertens, 2018 5 | License : ISC 6 | Maintainer : emertens@gmail.com 7 | 8 | -} 9 | module Advent.Visualize 10 | ( Image 11 | , PixelRGB8(..) 12 | 13 | , writePng 14 | , writeAnimation 15 | , generateImage 16 | 17 | , coordsImage 18 | 19 | , colorWheel 20 | ) where 21 | 22 | import Advent.Coord 23 | import Codec.Picture 24 | import Data.Word (Word8) 25 | 26 | coordsImage :: Pixel p => (Coord, Coord) -> (Coord -> p) -> Image p 27 | coordsImage (C loy lox, C hiy hix) f = generateImage toPixel width height 28 | where 29 | toPixel x y = f (C (loy+y) (lox+x)) 30 | width = hix - lox + 1 31 | height = hiy - loy + 1 32 | 33 | colorWheel :: Word8 -> PixelRGB8 34 | colorWheel i 35 | | i < 85 = PixelRGB8 (255 - i * 3) 0 (i * 3) 36 | | i < 170 = PixelRGB8 0 ((i-85) * 3) (255 - (i-85)*3) 37 | | otherwise = PixelRGB8 ((i-170) * 3) (255 - (i-170)*3) 0 38 | 39 | writeAnimation :: FilePath -> Int -> [Image PixelRGB8] -> IO () 40 | writeAnimation path delay imgs = 41 | case writeGifAnimation path delay LoopingForever imgs of 42 | Left e -> fail e 43 | Right io -> io 44 | -------------------------------------------------------------------------------- /doctests.hs: -------------------------------------------------------------------------------- 1 | {-# language BlockArguments #-} 2 | import Data.Foldable 3 | import Data.List 4 | import System.Directory 5 | import System.FilePath 6 | import System.IO 7 | import Test.DocTest 8 | 9 | main :: IO () 10 | main = 11 | do files <- processFiles <$> listDirectory "execs" 12 | for_ files \file -> 13 | do hPutStrLn stderr ("Testing " ++ file) 14 | doctest ["-icommon", file] 15 | 16 | processFiles :: [FilePath] -> [FilePath] 17 | processFiles 18 | = map ("execs") 19 | . filter (\x -> "Day" `isPrefixOf` takeBaseName x && takeExtension x == ".hs") 20 | . sort 21 | -------------------------------------------------------------------------------- /execs/Day01.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Main 3 | Description : Day 1 solution 4 | Copyright : (c) Eric Mertens, 2019 5 | License : ISC 6 | Maintainer : emertens@gmail.com 7 | 8 | 9 | 10 | Compute fuel costs for a rocket. 11 | 12 | -} 13 | module Main (main) where 14 | 15 | import Advent 16 | 17 | main :: IO () 18 | main = 19 | do inp <- getParsedLines 1 number 20 | print (sum (map fuelCost inp)) 21 | print (sum (map recursiveFuelCost inp)) 22 | 23 | -- | Compute fuel cost given a mass. 24 | -- 25 | -- >>> fuelCost 12 26 | -- 2 27 | -- >>> fuelCost 14 28 | -- 2 29 | -- >>> fuelCost 1969 30 | -- 654 31 | -- >>> fuelCost 100756 32 | -- 33583 33 | fuelCost :: Integer -> Integer 34 | fuelCost x = x `div` 3 - 2 35 | 36 | -- | Compute fuel cost given a mass. 37 | -- 38 | -- >>> recursiveFuelCost 14 39 | -- 2 40 | -- >>> recursiveFuelCost 1969 41 | -- 966 42 | -- >>> recursiveFuelCost 100756 43 | -- 50346 44 | recursiveFuelCost :: Integer -> Integer 45 | recursiveFuelCost = sum . takeWhile (> 0) . tail . iterate fuelCost 46 | -------------------------------------------------------------------------------- /execs/Day02.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Main 3 | Description : Day 2 solution 4 | Copyright : (c) Eric Mertens, 2019 5 | License : ISC 6 | Maintainer : emertens@gmail.com 7 | 8 | 9 | 10 | -} 11 | module Main (main) where 12 | 13 | import Advent (getIntcodeInput) 14 | import Intcode 15 | 16 | main :: IO () 17 | main = 18 | do pgm <- new <$> getIntcodeInput 2 19 | print (startup 12 2 pgm) 20 | print (head [ 100 * noun + verb 21 | | noun <- [0..99] 22 | , verb <- [0..99] 23 | , startup noun verb pgm == 19690720 ]) 24 | 25 | -- | Run the given program after assigning the given noun and verb. 26 | startup :: Int {- ^ noun -} -> Int {- ^ verb -} -> Machine -> Int 27 | startup noun verb 28 | = (! 0) 29 | . runPgm 30 | . set 1 noun 31 | . set 2 verb 32 | 33 | -- | Run the given program starting at the given program counter 34 | -- returning the initial memory value once the program halts. 35 | -- 36 | -- >>> let check = memoryList . runPgm . new 37 | -- >>> check [1,0,0,0,99] 38 | -- [2,0,0,0,99] 39 | -- >>> check [2,3,0,3,99] 40 | -- [2,3,0,6,99] 41 | -- >>> check [2,4,4,5,99,0] 42 | -- [2,4,4,5,99,9801] 43 | -- >>> check [1,1,1,4,99,5,6,0,99] 44 | -- [30,1,1,4,2,5,6,0,99] 45 | -- >>> check [1,9,10,3,2,3,11,0,99,30,40,50] 46 | -- [3500,9,10,70,2,3,11,0,99,30,40,50] 47 | runPgm :: Machine -> Machine 48 | runPgm mach = 49 | case step mach of 50 | Step mach' -> runPgm mach' 51 | StepHalt -> mach 52 | _ -> error "Unexpected step on day 2" 53 | -------------------------------------------------------------------------------- /execs/Day03.hs: -------------------------------------------------------------------------------- 1 | {-# Language OverloadedStrings #-} 2 | {-| 3 | Module : Main 4 | Description : Day 3 solution 5 | Copyright : (c) Eric Mertens, 2019 6 | License : ISC 7 | Maintainer : emertens@gmail.com 8 | 9 | 10 | 11 | -} 12 | module Main (main) where 13 | 14 | import Advent (Parser, getParsedLines, number, sepBy) 15 | import Control.Applicative (liftA2) 16 | import Data.Foldable (asum) 17 | import Data.List (foldl1') 18 | import Data.Map (Map) 19 | import qualified Data.Map as Map 20 | 21 | -- $setup 22 | -- >>> let parse = Data.Either.fromRight undefined . Advent.parseLines parseSteps . unlines 23 | 24 | data Motion = Motion Direction Int 25 | deriving Show 26 | 27 | -- | Directions up, down, left, and right. 28 | data Direction = U | D | L | R 29 | deriving Show 30 | 31 | -- parsing ------------------------------------------------------------- 32 | 33 | -- | Parse a single direction letter. 34 | parseDirection :: Parser Direction 35 | parseDirection = asum [U <$ "U", D <$ "D", R <$ "R", L <$ "L"] 36 | 37 | -- | Parse a direction letter and distance. 38 | parseMotion :: Parser Motion 39 | parseMotion = liftA2 Motion parseDirection number 40 | 41 | -- | Parse a comma-separated list of motions. 42 | parseSteps :: Parser [Motion] 43 | parseSteps = parseMotion `sepBy` "," 44 | 45 | -- coordinates --------------------------------------------------------- 46 | 47 | -- | Coordinates. First component is distance right, second component is distance down. 48 | type Coord = (Int,Int) 49 | 50 | -- | Convert a direction letter unit vector in the given direction. 51 | toUnitVector :: Direction -> Coord 52 | toUnitVector U = ( 0, -1) 53 | toUnitVector D = ( 0, 1) 54 | toUnitVector L = (-1, 0) 55 | toUnitVector R = ( 1, 0) 56 | 57 | -- | Pair-wise addition of coordinates. 58 | -- 59 | -- >>> addCoord (1,2) (3,4) 60 | -- (4,6) 61 | addCoord :: Coord -> Coord -> Coord 62 | addCoord (x,y) (dx,dy) = (x+dx, y+dy) 63 | 64 | -- | Manhattan distance from origin for a given coordinate 65 | -- 66 | -- >>> manhattan (3,4) 67 | -- 7 68 | -- >>> manhattan (-3,-5) 69 | -- 8 70 | manhattan :: Coord -> Int 71 | manhattan (x,y) = abs x + abs y 72 | 73 | ------------------------------------------------------------------------ 74 | 75 | main :: IO () 76 | main = 77 | do (p1,p2) <- answers <$> getParsedLines 3 parseSteps 78 | print p1 79 | print p2 80 | 81 | -- | Given the input file parsed as lists of lists of motions, compute the 82 | -- nearest distance to origin and minimum sum steps to intersection. 83 | -- 84 | -- >>> let check = answers . parse 85 | -- >>> check ["R8,U5,L5,D3","U7,R6,D4,L4"] 86 | -- (6,30) 87 | -- >>> check ["R75,D30,R83,U83,L12,D49,R71,U7,L72","U62,R66,U55,R34,D71,R55,D58,R83"] 88 | -- (159,610) 89 | -- >>> check ["R98,U47,R26,D63,R33,U87,L62,D20,R33,U53,R51","U98,R91,D20,R16,D67,R40,U7,R15,U6,R7"] 90 | -- (135,410) 91 | answers :: [[Motion]] -> (Int, Int) 92 | answers xs = (nearestDistanceToOrigin intersections, minimum intersections) 93 | where 94 | intersections = pathIntersections xs 95 | 96 | -- | Computes the map of path intersections, compute the shortest 97 | -- distance of an intersection to the origin. 98 | nearestDistanceToOrigin :: Map Coord a -> Int 99 | nearestDistanceToOrigin = minimum . map manhattan . Map.keys 100 | 101 | -- | Given a list of paths compute a map of locations that have intersections 102 | -- among all of the paths. The value at each location is the sum of the 103 | -- number of steps taken along each of the paths to get to that point. 104 | -- 105 | -- >>> let check = pathIntersections . parse 106 | -- >>> check ["R8,U5,L5,D3","U7,R6,D4,L4"] 107 | -- fromList [((3,-3),40),((6,-5),30)] 108 | pathIntersections :: [[Motion]] -> Map Coord Int 109 | pathIntersections = foldl1' (Map.intersectionWith (+)) . map distances 110 | 111 | -- | Generate a map of the coordinates a path visits. Each coordinate is 112 | -- indexed by the number of steps it took to get to that location. 113 | -- 114 | -- >>> distances [Motion D 2, Motion R 1] 115 | -- fromList [((0,1),1),((0,2),2),((1,2),3)] 116 | distances :: [Motion] -> Map Coord Int 117 | distances steps = Map.fromListWith min (zip (generatePath steps) [1..]) 118 | 119 | -- | Generate the list of coordinates visited by a list of steps. 120 | -- 121 | -- >>> generatePath [Motion D 2, Motion R 1] 122 | -- [(0,1),(0,2),(1,2)] 123 | generatePath :: [Motion] -> [Coord] 124 | generatePath 125 | = scanl1 addCoord 126 | . concatMap (\(Motion d n) -> replicate n (toUnitVector d)) 127 | -------------------------------------------------------------------------------- /execs/Day04.hs: -------------------------------------------------------------------------------- 1 | {-# Language OverloadedStrings #-} 2 | {-| 3 | Module : Main 4 | Description : Day 4 solution 5 | Copyright : (c) Eric Mertens, 2019 6 | License : ISC 7 | Maintainer : emertens@gmail.com 8 | 9 | 10 | 11 | -} 12 | module Main (main) where 13 | 14 | import Advent 15 | import Data.List 16 | 17 | -- | Parses two numbers separated by a dash. 18 | rangeParser :: Parser (Int, Int) 19 | rangeParser = (,) <$> number <* "-" <*> number 20 | 21 | main :: IO () 22 | main = 23 | do [(lo,hi)] <- getParsedLines 4 rangeParser 24 | let nums = map runs $ filter nondecreasing $ map show [lo..hi] 25 | print (count (any (> 1)) nums) 26 | print (count (elem 2 ) nums) 27 | 28 | -- | Return a list of the lengths of consecutive elements in a list. 29 | -- 30 | -- >>> runs [1,2,3] 31 | -- [1,1,1] 32 | -- >>> runs [1,1,1] 33 | -- [3] 34 | -- >>> runs [1,1,2,2,2,1,1] 35 | -- [2,3,2] 36 | -- >>> runs [] 37 | -- [] 38 | runs :: Eq a => [a] -> [Int] 39 | runs = map length . group 40 | 41 | -- | Predicate for non-decreasing lists. 42 | -- 43 | -- >>> nondecreasing [] 44 | -- True 45 | -- >>> nondecreasing [1,1,2,3] 46 | -- True 47 | -- >>> nondecreasing [3,3,2] 48 | -- False 49 | nondecreasing :: Ord a => [a] -> Bool 50 | nondecreasing xs = and (zipWith (<=) xs (tail xs)) 51 | -------------------------------------------------------------------------------- /execs/Day05.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Main 3 | Description : Day 5 solution 4 | Copyright : (c) Eric Mertens, 2019 5 | License : ISC 6 | Maintainer : emertens@gmail.com 7 | 8 | 9 | 10 | This task expands the virtual machine defined in day 2 11 | adding jumps, conditionals, inputs, and outputs. 12 | 13 | This solution works with the following passes: 14 | 15 | 1. Parse input text file into a list of numbers 16 | 2. Execute op codes to extract the input/output "effects" 17 | 3. Evaluate the effect as a function from a list of inputs to list of outputs 18 | 4. Apply the function to a single input and find the last output. 19 | 20 | >>> intcodeToList [3,12,6,12,15,1,13,14,13,4,13,99,-1,0,1,9] <$> [[0],[10]] 21 | [[0],[1]] 22 | 23 | >>> intcodeToList [3,3,1105,-1,9,1101,0,0,12,4,12,99,1] <$> [[0],[10]] 24 | [[0],[1]] 25 | 26 | >>> :{ 27 | >>> intcodeToList 28 | >>> [3,21,1008,21,8,20,1005,20,22,107,8,21,20,1006,20,31, 29 | >>> 1106,0,36,98,0,0,1002,21,125,20,4,20,1105,1,46,104, 30 | >>> 999,1105,1,46,1101,1000,1,20,4,20,1105,1,46,98,99] 31 | >>> <$> [[7],[8],[9]] 32 | >>> :} 33 | [[999],[1000],[1001]] 34 | 35 | -} 36 | module Main (main) where 37 | 38 | import Advent (getIntcodeInput) 39 | import Intcode (intcodeToList) 40 | 41 | main :: IO () 42 | main = 43 | do inp <- getIntcodeInput 5 44 | let go i = print (last (intcodeToList inp [i])) 45 | go 1 46 | go 5 47 | -------------------------------------------------------------------------------- /execs/Day06.hs: -------------------------------------------------------------------------------- 1 | {-# Language ImportQualifiedPost, OverloadedStrings #-} 2 | {-| 3 | Module : Main 4 | Description : Day 6 solution 5 | Copyright : (c) Eric Mertens, 2019 6 | License : ISC 7 | Maintainer : emertens@gmail.com 8 | 9 | 10 | 11 | -} 12 | module Main (main) where 13 | 14 | import Advent (Parser, getParsedLines, satisfy) 15 | import Control.Applicative (many) 16 | import Data.Map qualified as Map 17 | 18 | parseName :: Parser String 19 | parseName = many (satisfy (')'/=)) 20 | 21 | parseOrbit :: Parser (String, String) 22 | parseOrbit = (,) <$> parseName <* ")" <*> parseName 23 | 24 | main :: IO () 25 | main = 26 | do inp <- getParsedLines 6 parseOrbit 27 | let paths = Map.fromList [(y,x:Map.findWithDefault [] x paths) | (x,y) <- inp] 28 | print (sum (length <$> paths)) 29 | 30 | -- routes from COM leading to YOU and SAN 31 | let t1 = reverse (paths Map.! "YOU") 32 | t2 = reverse (paths Map.! "SAN") 33 | print (part2 t1 t2) 34 | 35 | -- remove the common prefix and then return the length of the remainder 36 | part2 :: Eq a => [a] -> [a] -> Int 37 | part2 (x:xs) (y:ys) | x == y = part2 xs ys 38 | part2 xs ys = length xs + length ys 39 | -------------------------------------------------------------------------------- /execs/Day07.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Main 3 | Description : Day 5 solution 4 | Copyright : (c) Eric Mertens, 2019 5 | License : ISC 6 | Maintainer : emertens@gmail.com 7 | 8 | 9 | 10 | To compute our thrust controller feedback loop I evaluate the 11 | given Intcode program as a function from input values to output 12 | values. Connecting the outputs of one instance of the program 13 | to the inputs of the next is as simple as composing the two 14 | functions together. Thanks to non-strict evaluation I can 15 | pass the output of a composition of these functions back in 16 | as its own input! 17 | 18 | -} 19 | module Main (main) where 20 | 21 | import Advent (getIntcodeInput) 22 | import Data.Function (fix) 23 | import Data.List (permutations) 24 | import Intcode (intcodeToList) 25 | 26 | -- | A function from a list of input values to a list of output values. 27 | type ListFn = [Int] -> [Int] 28 | 29 | main :: IO () 30 | main = 31 | do pgm <- intcodeToList <$> getIntcodeInput 7 32 | print (part1 pgm) 33 | print (part2 pgm) 34 | 35 | -- | Run the given amplitude controller in a feedback loop across 36 | -- all permutations of the settings 0 through 4. Returns the 37 | -- maximum initial thruster output. 38 | -- 39 | -- >>> part1 (intcodeToList [3,15,3,16,1002,16,10,16,1,16,15,15,4,15,99,0,0]) 40 | -- 43210 41 | -- >>> part1 (intcodeToList [3,23,3,24,1002,24,10,24,1002,23,-1,23,101,5,23,23,1,24,23,23,4,23,99,0,0]) 42 | -- 54321 43 | -- >>> part1 (intcodeToList [3,31,3,32,1002,32,10,32,1001,31,-2,31,1007,31,0,33,1002,33,7,33,1,33,31,31,1,32,31,31,4,31,99,0,0,0]) 44 | -- 65210 45 | part1 :: 46 | ListFn {- ^ amplifier controller software -} -> 47 | Int {- ^ maximum initial thruster output -} 48 | part1 = optimize head [0..4] 49 | 50 | -- | Run the given amplitude controller in a feedback loop across 51 | -- all permutations of the settings 5 through 9. Returns the 52 | -- maximum final thruster output. 53 | -- 54 | -- >>> part2 (intcodeToList [3,26,1001,26,-4,26,3,27,1002,27,2,27,1,27,26,27,4,27,1001,28,-1,28,1005,28,6,99,0,0,5]) 55 | -- 139629729 56 | -- >>> :{ 57 | -- >>> part2 (intcodeToList [3,52,1001,52,-5,52,3,53,1,52,56,54,1007,54,5,55,1005,55,26,1001,54, 58 | -- >>> -5,54,1105,1,12,1,53,54,53,1008,54,0,55,1001,55,1,55,2,53,55,53,4, 59 | -- >>> 53,1001,56,-1,56,1005,56,6,99,0,0,0,0,10]) 60 | -- >>> :} 61 | -- 18216 62 | part2 :: 63 | ListFn {- ^ amplifier controller software -} -> 64 | Int {- ^ maximum final thruster output -} 65 | part2 = optimize last [5..9] 66 | 67 | 68 | optimize :: 69 | Ord a => 70 | ([Int] -> a) {- ^ output characterization -} -> 71 | [Int] {- ^ phase available -} -> 72 | ListFn {- ^ phases to outputs -} -> 73 | a {- ^ maximized characterization -} 74 | optimize f phases pgm = maximum [f (thrustController pgm p) | p <- permutations phases] 75 | 76 | -- | Given a amplifier controller software function and a list of 77 | -- phase settings, generate the resulting list of thruster outputs. 78 | -- 79 | -- Once instances of the control software is started for each phase setting, 80 | -- the instances are all sequenced together into a single loop. A starting 81 | -- @0@ element is added as an initial input. 82 | -- 83 | -- >>> thrustController (intcodeToList [3,15,3,16,1002,16,10,16,1,16,15,15,4,15,99,0,0]) [4,3,2,1,0] 84 | -- [43210] 85 | -- >>> thrustController (intcodeToList [3,26,1001,26,-4,26,3,27,1002,27,2,27,1,27,26,27,4,27,1001,28,-1,28,1005,28,6,99,0,0,5]) [9,8,7,6,5] 86 | -- [129,4257,136353,4363425,139629729] 87 | thrustController :: 88 | ListFn {- ^ amplifier controller software -} -> 89 | ListFn {- ^ thrust controller -} 90 | thrustController ctrl phases = tieknot [ctrl << p | p <- phases] 91 | 92 | -- | Create a feedback loop given the initialized controllers 93 | -- and return the thruster outputs. Feed an initial @0@ value 94 | -- into the loop. 95 | -- 96 | -- >>> tieknot [map (2*), map (1+), take 5] 97 | -- [1,3,7,15,31] 98 | tieknot :: 99 | [ListFn] {- ^ initialized amplifier controllers -} -> 100 | [Int] {- ^ thruster outputs -} 101 | tieknot fs = fix (composeLR fs << 0) 102 | 103 | -- | Compose list functions from left-to-right. Inputs go into 104 | -- first function and outputs come from last function. 105 | -- 106 | -- >>> composeLR [(2*),(1+)] 3 107 | -- 7 108 | composeLR :: [a -> a] -> (a -> a) 109 | composeLR = foldl (flip (.)) id 110 | 111 | -- | Feed a single input into a list function. 112 | -- 113 | -- >>> (map (*2) << 10) [5,6,7] 114 | -- [20,10,12,14] 115 | (<<) :: ListFn -> Int -> ListFn 116 | (f << x) xs = f (x:xs) 117 | -------------------------------------------------------------------------------- /execs/Day08.hs: -------------------------------------------------------------------------------- 1 | {-# Language ImportQualifiedPost #-} 2 | {-| 3 | Module : Main 4 | Description : Day 8 solution 5 | Copyright : (c) Eric Mertens, 2019 6 | License : ISC 7 | Maintainer : emertens@gmail.com 8 | 9 | 10 | 11 | -} 12 | module Main (main) where 13 | 14 | import Advent (getInputLines, cardinality, chunks) 15 | import Data.List (minimumBy) 16 | import Data.Ord (comparing) 17 | import Data.Map qualified as Map 18 | 19 | main :: IO () 20 | main = 21 | do [inp] <- getInputLines 8 22 | let layers = chunks (25*6) inp 23 | print (part1 layers) 24 | mapM_ (putStrLn . map render) (chunks 25 (overlayLayers layers)) 25 | 26 | render :: Char -> Char 27 | render '0' = '\x2591' 28 | render '1' = '\x2588' 29 | render '2' = '\x2592' 30 | render _ = error "bad pixel" 31 | 32 | overlayLayers :: [String] -> String 33 | overlayLayers = foldr1 (zipWith overlay) 34 | 35 | overlay :: Char -> Char -> Char 36 | overlay '2' x = x 37 | overlay x _ = x 38 | 39 | part1 :: [String] -> Int 40 | part1 = checksum . minimumBy (comparing (ix '0')) . map cardinality 41 | where 42 | ix = Map.findWithDefault 0 43 | checksum x = ix '1' x * ix '2' x 44 | -------------------------------------------------------------------------------- /execs/Day09.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Main 3 | Description : Day 9 solution 4 | Copyright : (c) Eric Mertens, 2019 5 | License : ISC 6 | Maintainer : emertens@gmail.com 7 | 8 | 9 | 10 | >>> intcodeToList [109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99] [] 11 | [109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99] 12 | 13 | >>> intcodeToList [1102,34915192,34915192,7,4,7,99,0] [] 14 | [1219070632396864] 15 | 16 | >>> intcodeToList [104,1125899906842624,99] [] 17 | [1125899906842624] 18 | 19 | -} 20 | module Main (main) where 21 | 22 | import Advent (getIntcodeInput) 23 | import Intcode (intcodeToList) 24 | 25 | main :: IO () 26 | main = 27 | do inp <- getIntcodeInput 9 28 | let go i = print (head (intcodeToList inp [i])) 29 | go 1 30 | go 2 31 | -------------------------------------------------------------------------------- /execs/Day10.hs: -------------------------------------------------------------------------------- 1 | {-# Language ImportQualifiedPost #-} 2 | {-| 3 | Module : Main 4 | Description : Day 10 solution 5 | Copyright : (c) Eric Mertens, 2019 6 | License : ISC 7 | Maintainer : emertens@gmail.com 8 | 9 | 10 | 11 | -} 12 | module Main (main) where 13 | 14 | import Advent 15 | import Advent.Coord 16 | import Data.List (maximumBy, sortOn, transpose) 17 | import Data.Map (Map) 18 | import Data.Map qualified as Map 19 | import Data.Ord (comparing) 20 | 21 | main :: IO () 22 | main = 23 | do inp <- getInputLines 10 24 | let byAngles = findTheBase [c | (c,'#') <- coordLines inp] 25 | print (Map.size byAngles) -- part 1 26 | let C y x = spiralOrder byAngles !! 199 27 | print (x * 100 + y) -- part 2 28 | 29 | -- Given a list of asteroid locations, the other asteroids 30 | -- arranged by their angle from the best base in order of 31 | -- distance from that base. 32 | findTheBase :: [Coord] -> Map Double [Coord] 33 | findTheBase world = 34 | maximumBy (comparing Map.size) 35 | [sortOn (manhattan i) <$> collectBy (angle . sub i) xs | (i,xs) <- pickOne world] 36 | 37 | spiralOrder :: Map Double [Coord] -> [Coord] 38 | spiralOrder = concat . transpose . Map.elems 39 | 40 | -- 'subtract' but for 'Coord' 41 | sub :: Coord -> Coord -> Coord 42 | sub (C y x) (C v u) = C (v-y) (u-x) 43 | 44 | angle :: Coord -> Double 45 | angle (C y x) = atan2 (- fromIntegral x) (fromIntegral y) 46 | 47 | -- | Given a characterizing function arrange elements that 48 | -- have the same characterization. 49 | collectBy :: Ord k => (a -> k) -> [a] -> Map k [a] 50 | collectBy f xs = Map.fromListWith (++) [(f x, [x]) | x <- xs] 51 | -------------------------------------------------------------------------------- /execs/Day11.hs: -------------------------------------------------------------------------------- 1 | {-# Language ImportQualifiedPost #-} 2 | {-| 3 | Module : Main 4 | Description : Day 11 solution 5 | Copyright : (c) Eric Mertens, 2019 6 | License : ISC 7 | Maintainer : emertens@gmail.com 8 | 9 | 10 | 11 | -} 12 | module Main (main) where 13 | 14 | import Advent (getIntcodeInput) 15 | import Advent.Coord (Coord, turnLeft, turnRight, addCoord, origin, north, drawCoords) 16 | import Data.Map (Map) 17 | import Data.Map qualified as Map 18 | import Intcode (intcodeToList) 19 | 20 | main :: IO () 21 | main = 22 | do inp <- getIntcodeInput 11 23 | let render = putStrLn . drawCoords . fmap paintChar 24 | world1 = runner inp Map.empty 25 | world2 = runner inp (Map.singleton origin 1) 26 | 27 | print (Map.size world1) 28 | render world2 29 | 30 | runner :: 31 | [Int] {- ^ intcode program -} -> 32 | Map Coord Int {- ^ initial world -} -> 33 | Map Coord Int {- ^ final world -} 34 | runner inp world0 = last [w | (_,_,w) <- states] 35 | where 36 | inputs = [Map.findWithDefault 0 here world | (_, here, world) <- states] 37 | outputs = intcodeToList inp inputs 38 | states = (north, origin, world0) : zipWith robotStep states (pairs outputs) 39 | 40 | -- | Apply the robot movement logic to the current robot state 41 | robotStep :: 42 | (Coord, Coord, Map Coord Int) {- ^ vector, location, world -} -> 43 | (Int,Int) {- ^ robot's command -} -> 44 | (Coord, Coord, Map Coord Int) {- ^ vector, location, world -} 45 | robotStep (dir, here, world) (color, turn) = (dir', here', world') 46 | where 47 | world' = Map.insert here color world 48 | dir' = turnFn turn dir 49 | here' = addCoord here dir' 50 | 51 | -- | Compute the turn function given a robot's output. 52 | turnFn :: Int {- ^ robot turn output -} -> Coord -> Coord 53 | turnFn 0 = turnLeft 54 | turnFn 1 = turnRight 55 | turnFn x = error ("Unexpected turn command: " ++ show x) 56 | 57 | -- | Character representation of paint number. 58 | paintChar :: Int -> Char 59 | paintChar 0 = '░' 60 | paintChar 1 = '█' 61 | paintChar x = error ("Unexpected paint color: " ++ show x) 62 | 63 | pairs :: [a] -> [(a,a)] 64 | pairs (x:y:z) = (x,y) : pairs z 65 | pairs _ = [] 66 | -------------------------------------------------------------------------------- /execs/Day12.hs: -------------------------------------------------------------------------------- 1 | {-# Language OverloadedStrings #-} 2 | {-| 3 | Module : Main 4 | Description : Day 12 solution 5 | Copyright : (c) Eric Mertens, 2019 6 | License : ISC 7 | Maintainer : emertens@gmail.com 8 | 9 | 10 | 11 | The stepping function is invertible, so any cycles must include 12 | the starting point. This means to find a cycle we just search 13 | for the starting point rather than remembering all states along 14 | the way. 15 | 16 | -} 17 | module Main (main) where 18 | 19 | import Advent (getParsedLines, Parser, manyTill, satisfy, number, sepBy) 20 | import Data.List (transpose, elemIndex, foldl') 21 | import Data.Char (isAlpha) 22 | 23 | parseMoon :: Parser [Particle] 24 | parseMoon = "<" *> component `sepBy` ", " <* ">" 25 | where 26 | component = newParticle <$ manyTill (satisfy isAlpha) "=" <*> number 27 | 28 | -- | One-dimensional particle with a position and velocity. 29 | data Particle = P !Int !Int -- ^ position velocity 30 | deriving (Eq, Ord, Show) 31 | 32 | -- | Build a stationary particle. 33 | newParticle :: Int {- ^ position -} -> Particle 34 | newParticle x = P x 0 35 | 36 | main :: IO () 37 | main = 38 | do threeD_sim <- getParsedLines 12 parseMoon 39 | let oneD_sims = transpose threeD_sim 40 | print (part1 oneD_sims) 41 | print (part2 oneD_sims) 42 | 43 | 44 | part1 :: [[Particle]] -> Int 45 | part1 oneD_sims = sum (map energy threeD_sim1000) 46 | where 47 | oneD_sims1000 = [ iterate stepParticles sim !! 1000 | sim <- oneD_sims ] 48 | threeD_sim1000 = transpose oneD_sims1000 49 | 50 | 51 | part2 :: [[Particle]] -> Int 52 | part2 oneD_sims = foldl' lcm 1 periods 53 | where 54 | periods = map (repeatLength . iterate stepParticles) oneD_sims 55 | 56 | 57 | -- | Compute the energy of a multi-dimensional particle given 58 | -- its dimensional components. 59 | energy :: [Particle] -> Int 60 | energy ps = sum [ abs x | P x _ <- ps ] * sum [ abs v | P _ v <- ps ] 61 | 62 | repeatLength :: Eq a => [a] -> Int 63 | repeatLength [] = error "repeatList: no cycle" 64 | repeatLength (x:xs) = 1 + n 65 | where Just n = elemIndex x xs 66 | 67 | -- | Advance a particle by its current velocity. 68 | move :: Particle -> Particle 69 | move (P x dx) = P (x+dx) dx 70 | 71 | -- | Single step of a one-dimensional, n-body system. 72 | stepParticles :: [Particle] -> [Particle] 73 | stepParticles ps = [ move (foldl' gravity p ps) | p <- ps ] 74 | 75 | -- | Apply gravity to the first particle based on the second. 76 | gravity :: Particle -> Particle -> Particle 77 | gravity (P x v) (P y _) = P x (v + signum (y-x)) 78 | -------------------------------------------------------------------------------- /execs/Day13.hs: -------------------------------------------------------------------------------- 1 | {-# Language ImportQualifiedPost #-} 2 | {-| 3 | Module : Main 4 | Description : Day 13 solution 5 | Copyright : (c) Eric Mertens, 2019 6 | License : ISC 7 | Maintainer : emertens@gmail.com 8 | 9 | 10 | 11 | -} 12 | module Main (main) where 13 | 14 | import Advent (getIntcodeInput) 15 | import Data.Map (Map) 16 | import Data.Map qualified as Map 17 | import Intcode (Effect(..), new, run, set) 18 | 19 | main :: IO () 20 | main = 21 | do mach <- new <$> getIntcodeInput 13 22 | print (part1 (run mach )) 23 | print (part2 0 0 0 (run (set 0 2 mach))) 24 | 25 | part1 :: Effect -> Int 26 | part1 = Map.size . Map.filter (2==) . getImage Map.empty 27 | 28 | getImage :: Map (Int, Int) Int -> Effect -> Map (Int, Int) Int 29 | getImage m (Output x (Output y (Output t e))) = getImage (Map.insert (x,y) t m) e 30 | getImage m _ = m 31 | 32 | part2 :: Int -> Int -> Int -> Effect -> Int 33 | part2 ball paddle score effect = 34 | case effect of 35 | Output x (Output y (Output t effect')) 36 | | t == 4 -> part2 x paddle score effect' 37 | | t == 3 -> part2 ball x score effect' 38 | | x == (-1), y == 0 -> part2 ball paddle t effect' 39 | | otherwise -> part2 ball paddle score effect' 40 | Input f -> part2 ball paddle score (f (signum (ball - paddle))) 41 | _ -> score 42 | -------------------------------------------------------------------------------- /execs/Day14.hs: -------------------------------------------------------------------------------- 1 | {-# Language ImportQualifiedPost, OverloadedStrings, NumericUnderscores #-} 2 | {-| 3 | Module : Main 4 | Description : Day 14 solution 5 | Copyright : (c) Eric Mertens, 2019 6 | License : ISC 7 | Maintainer : emertens@gmail.com 8 | 9 | 10 | 11 | -} 12 | module Main (main) where 13 | 14 | import Advent (Parser, getParsedLines, number, satisfy, sepBy) 15 | import Control.Applicative (some) 16 | import Data.List (foldl', sortOn) 17 | import Data.Map (Map) 18 | import Data.Map qualified as Map 19 | import Data.Char (isAlpha) 20 | 21 | p2ore :: Integer 22 | p2ore = 1_000_000_000_000 23 | 24 | -- Input file parser --------------------------------------------------- 25 | 26 | type Reaction = ([Component], Component) 27 | type Component = (Integer, String) 28 | 29 | parseChemical :: Parser String 30 | parseChemical = some (satisfy isAlpha) 31 | 32 | parseItem :: Parser Component 33 | parseItem = (,) <$> number <* " " <*> parseChemical 34 | 35 | parseItems :: Parser [Component] 36 | parseItems = parseItem `sepBy` ", " 37 | 38 | parseReaction :: Parser Reaction 39 | parseReaction = (,) <$> parseItems <* " => " <*> parseItem 40 | 41 | ------------------------------------------------------------------------ 42 | 43 | type Step = (String, Integer, Map String Integer) 44 | 45 | -- | 46 | -- :main 47 | -- 751038 48 | -- 2074843 49 | main :: IO () 50 | main = 51 | do inp <- getParsedLines 14 parseReaction 52 | let recipes = arrange inp 53 | 54 | print (oreNeeded divUp recipes 1) 55 | 56 | let optimal = fromInteger p2ore / oreNeeded (/) recipes 1 :: Rational 57 | print $ until (\i -> oreNeeded divUp recipes i <= p2ore) (subtract 1) 58 | $ truncate optimal 59 | 60 | -- | Determine the amount of ORE needed to create the given amount of FUEL 61 | oreNeeded :: 62 | Num a => 63 | (a -> a -> a) {- ^ division -} -> 64 | [Step] {- ^ arranged reaction steps -} -> 65 | a {- ^ fuel amount -} -> 66 | a {- ^ ore amount -} 67 | oreNeeded divide recipes n = 68 | foldl' (doStep divide) (Map.singleton "FUEL" n) recipes Map.! "ORE" 69 | 70 | -- | Use the given reaction step to reduce any of that item needed into 71 | -- simpler components. 72 | doStep :: 73 | Num a => 74 | (a -> a -> a) {- ^ division -} -> 75 | Map String a {- ^ items needed before reaction -} -> 76 | Step {- ^ reaction step -} -> 77 | Map String a {- ^ items needed after reaction -} 78 | doStep divide need (item, makes, needs) = 79 | case Map.lookup item need of 80 | Nothing -> need 81 | Just qty -> Map.unionWith (+) need1 need2 82 | where 83 | reactions = qty `divide` fromInteger makes 84 | need1 = Map.delete item need 85 | need2 = (\i -> reactions * fromInteger i) <$> needs 86 | 87 | -- | Sort the reaction steps topologically so that earlier steps only 88 | -- rely on later steps. 89 | arrange :: [Reaction] -> [Step] 90 | arrange xs = sortOn (negate . depth . key) out 91 | where 92 | key (x,_,_) = x 93 | out = [(rhs, n, Map.fromList [(name,m)|(m,name)<-lhs]) | (lhs,(n,rhs)) <- xs] 94 | depthMap = Map.fromList (("ORE", 0) : [(dst, toDepth src) | (src,(_,dst)) <- xs]) 95 | depth = (depthMap Map.!) 96 | toDepth [] = 0 :: Int 97 | toDepth ys = 1 + maximum (depth . snd <$> ys) 98 | 99 | -- | Integer division that rounds up instead of down. 100 | divUp :: Integer -> Integer -> Integer 101 | x `divUp` y = (x + y - 1) `div` y 102 | -------------------------------------------------------------------------------- /execs/Day15.hs: -------------------------------------------------------------------------------- 1 | {-# Language RecordWildCards, ViewPatterns #-} 2 | {-| 3 | Module : Main 4 | Description : Day 15 solution 5 | Copyright : (c) Eric Mertens, 2019 6 | License : ISC 7 | Maintainer : emertens@gmail.com 8 | 9 | 10 | 11 | -} 12 | module Main (main) where 13 | 14 | import Advent (getIntcodeInput) 15 | import Advent.Coord (Coord, above, below, left, right, origin) 16 | import Advent.Search (bfsOn) 17 | import Intcode (Effect(..), run, new) 18 | 19 | main :: IO () 20 | main = 21 | do intcode <- getIntcodeInput 15 22 | let part1:_ = filter onOxygen (search (newSearchState intcode)) 23 | print (distance part1) 24 | print (distance (last (search part1{distance = 0}))) 25 | 26 | data SearchState = SearchState 27 | { onOxygen :: !Bool -- ^ Is the robot currently on the oxygen 28 | , distance :: !Int -- ^ Commands issued so far 29 | , location :: !Coord -- ^ robot's current location 30 | , effect :: Effect -- ^ robot control program 31 | } 32 | 33 | -- | Initial search state starting from assumed non-oxygen at the origin. 34 | newSearchState :: [Int] {- ^ intcode -} -> SearchState 35 | newSearchState = SearchState False 0 origin . run . new 36 | 37 | -- | Breadth-first exploration of the maze 38 | search :: SearchState -> [SearchState] 39 | search = bfsOn location searchStep 40 | 41 | -- | Generate the list of single steps that can be taken from a particular position. 42 | searchStep :: SearchState -> [SearchState] 43 | searchStep SearchState{..} = 44 | [ SearchState (o == 2) (distance + 1) (move location) e 45 | | (i,move) <- [(1,above),(2,below),(3,left),(4,right)] 46 | , (o,e) <- effectStep i effect 47 | ] 48 | 49 | -- | Give the robot a movement instruction and get the block status 50 | effectStep :: Int {- ^ direction -} -> Effect -> [(Int, Effect)] 51 | effectStep i (Input (($ i) -> Output o e)) | o > 0 = [(o,e)] 52 | effectStep _ _ = [] 53 | -------------------------------------------------------------------------------- /execs/Day16.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Main 3 | Description : Day 16 solution 4 | Copyright : (c) Eric Mertens, 2019 5 | License : ISC 6 | Maintainer : emertens@gmail.com 7 | 8 | 9 | 10 | -} 11 | module Main (main) where 12 | 13 | import Advent 14 | import Control.Applicative 15 | import qualified Data.Vector.Unboxed as V 16 | 17 | main :: IO () 18 | main = 19 | do [inp] <- getParsedLines 16 (many anySingle) 20 | let ns = digits inp 21 | 22 | putStrLn $ concatMap show $ V.toList $ V.take 8 $ iterate (fft 0) ns !! 100 23 | 24 | let offset = read (take 7 inp) 25 | 26 | let ns' = V.concat (replicate 10000 ns) 27 | putStrLn $ concatMap show $ V.toList $ V.take 8 $ V.drop offset $ iterate (fft offset) ns' !! 100 28 | 29 | digits :: String -> V.Vector Int 30 | digits = V.fromList . map (read . pure) 31 | 32 | fft :: Int -> V.Vector Int -> V.Vector Int 33 | fft offset xs = V.generate (V.length xs) one 34 | where 35 | n = V.length xs 36 | ps = V.scanl (+) 0 xs 37 | factors i = takeWhile (\(Region _ a _) -> a < n) (regions i) 38 | 39 | one i 40 | | i < offset = 0 41 | | otherwise = abs $ sum [ m * (ps V.! min n end - ps V.! start) 42 | | Region m start end <- factors i] 43 | `rem` 10 44 | 45 | data Region = Region !Int !Int !Int 46 | deriving Show 47 | 48 | regions :: Int -> [Region] 49 | regions i = go 0 50 | where 51 | n = i + 1 52 | go offset = Region 1 (offset + i) (offset + i+n) 53 | : Region (-1) (offset + i + n*2) (offset + i+n*2+ n) 54 | : go (offset + 4 * n) 55 | -------------------------------------------------------------------------------- /execs/Day17.hs: -------------------------------------------------------------------------------- 1 | {-# Language BlockArguments, ImportQualifiedPost, TransformListComp #-} 2 | {-| 3 | Module : Main 4 | Description : Day 17 solution 5 | Copyright : (c) Eric Mertens, 2019 6 | License : ISC 7 | Maintainer : emertens@gmail.com 8 | 9 | 10 | 11 | -} 12 | module Main (main) where 13 | 14 | import Advent (getIntcodeInput) 15 | import Advent.Coord 16 | import Data.Char (chr, ord) 17 | import Data.List (intersperse, stripPrefix, intercalate, inits, tails) 18 | import Data.Map (Map) 19 | import Data.Map qualified as Map 20 | import Data.Maybe (maybeToList) 21 | import Intcode (intcodeToList, effectList, run, new, set) 22 | 23 | -- 24 | -- >>> :main 25 | -- 7280 26 | -- 1045393 27 | main :: IO () 28 | main = 29 | do inp <- getIntcodeInput 17 30 | let ascii = map chr (intcodeToList inp []) 31 | world = Map.fromList [ (C y x, col) 32 | | (y,row) <- zip [0..] (lines ascii) 33 | , (x,col) <- zip [0..] row, col /= '.' ] 34 | 35 | print (part1 world) 36 | print (part2 inp world) 37 | 38 | part1 :: Map Coord Char -> Int 39 | part1 world = 40 | sum [ coordRow k * coordCol k 41 | | k <- Map.keys world 42 | , all (`Map.member` world) (cardinal k) ] 43 | 44 | part2 :: 45 | [Int] {- ^ intcode program -} -> 46 | Map Coord Char {- ^ world map -} -> 47 | Int {- ^ final program output -} 48 | part2 inp world = last (effectList (run (set 0 2 (new inp))) (map ord input)) 49 | where 50 | start = head [k | (k,'^') <- Map.toList world] 51 | p = path world start north 52 | input = head (search 'A' [] [] p) 53 | 54 | data Dir = L | R deriving (Eq, Show) 55 | type Cmds = [(Dir,Int)] 56 | 57 | -- Determine that path that takes us from the start to the end 58 | path :: 59 | Map Coord Char {- ^ world map -} -> 60 | Coord {- ^ current location -} -> 61 | Coord {- ^ travel vector -} -> 62 | Cmds 63 | path world here dir 64 | | Map.member (addCoord (turnLeft dir) here) world = walk L turnLeft 65 | | Map.member (addCoord (turnRight dir) here) world = walk R turnRight 66 | | otherwise = [] 67 | where 68 | walk cmd f = (cmd, n) : path world endPoint dir' 69 | where 70 | dir' = f dir 71 | steps = takeWhile (`Map.member` world) 72 | $ iterate (addCoord dir') here 73 | n = length steps - 1 74 | endPoint = last steps 75 | 76 | 77 | search :: 78 | Char {- ^ next subroutine name -} -> 79 | [Cmds] {- ^ current subroutines -} -> 80 | [Char] {- ^ reversed main program -} -> 81 | Cmds {- ^ remaining path -} -> 82 | [String] {- ^ program input -} 83 | search _ subs pgm [] = 84 | [ unlines 85 | $ intersperse ',' (reverse pgm) 86 | : take 3 (map instructions subs ++ repeat "L") 87 | ++ ["n"] 88 | ] 89 | search next subs pgm p = oldSub ++ newSub 90 | where 91 | oldSub = [ answer 92 | | (name, sub) <- zip ['A'..] subs 93 | , path' <- maybeToList (stripPrefix sub p) 94 | , answer <- search next subs (name:pgm) path' ] 95 | 96 | newSub = [ answer 97 | | next < 'D' 98 | , (sub,rest) <- tail (splits p), then takeWhile by short sub 99 | , answer <- search (succ next) (subs ++ [sub]) (next:pgm) rest ] 100 | 101 | -- subroutines are limited to be at most 20 characters 102 | short :: Cmds -> Bool 103 | short xs = length (instructions xs) <= 20 104 | 105 | instructions :: Cmds -> String 106 | instructions xs = intercalate "," do (d,n) <- xs; [show d, show n] 107 | 108 | splits :: [a] -> [([a],[a])] 109 | splits xs = zip (inits xs) (tails xs) 110 | -------------------------------------------------------------------------------- /execs/Day18.hs: -------------------------------------------------------------------------------- 1 | {-# Language ImportQualifiedPost, RecordWildCards #-} 2 | {-| 3 | Module : Main 4 | Description : Day 18 solution 5 | Copyright : (c) Eric Mertens, 2019 6 | License : ISC 7 | Maintainer : emertens@gmail.com 8 | 9 | 10 | 11 | Approach: 12 | 13 | 1. Reduce maze to a graph with 'extractGraph' 14 | Nodes: starting points, gates, keys 15 | Edges: shortest direct route between nodes 16 | 17 | 2. Implement 'nextKey' function to find list of reachable keys 18 | for a particular robot. 19 | 20 | 3. Use Djikstra search to search the space of picking a robot to move 21 | from its current position to an unvisited key until 22 | all keys are visited. 23 | 24 | -} 25 | module Main (main) where 26 | 27 | import Advent 28 | import Advent.Coord 29 | import Advent.Search 30 | import Data.Char 31 | import Data.Maybe 32 | import Data.Set (Set) 33 | import Data.IntSet (IntSet) 34 | import Data.Set qualified as Set 35 | import Data.IntSet qualified as IntSet 36 | import Data.Map qualified as Map 37 | import Data.Map (Map) 38 | import Data.Array.Unboxed 39 | 40 | main :: IO () 41 | main = 42 | do inp <- coordLines <$> getInputLines 18 43 | let Just b = boundingBox (map fst inp) 44 | world1 = listArray b (map snd inp) 45 | start = head [k | (k,'@') <- inp] 46 | 47 | -- part 1 48 | print (allKeys world1 [start]) 49 | 50 | -- part 2 51 | let fixups = [(c,'#') | c <- start : cardinal start] 52 | ++ [(f (g start),'@') | f <- [above, below], g <- [left , right]] 53 | world2 = world1 // fixups 54 | start2 = [k | (k,'@') <- assocs world2] 55 | print (allKeys world2 start2) 56 | 57 | ------------------------------------------------------------------------ 58 | -- Search that finds shortest distances to the remaining keys 59 | ------------------------------------------------------------------------ 60 | 61 | data Cell = Start | Gate !Int | Key !Int 62 | deriving (Eq, Show, Ord) 63 | 64 | charToCell :: Char -> Maybe Cell 65 | charToCell x 66 | | '@' == x = Just Start 67 | | isLower x = Just (Key (ord x - ord 'a')) 68 | | isUpper x = Just (Gate (ord x - ord 'A')) 69 | | otherwise = Nothing 70 | 71 | ------------------------------------------------------------------------ 72 | -- Simplify down to starts, keys, gates, and paths between them 73 | ------------------------------------------------------------------------ 74 | 75 | extractGraph :: UArray Coord Char -> Map Coord [(Coord, Cell, Int)] 76 | extractGraph world = 77 | Map.fromList 78 | [ (pos, startSearch world pos cell) 79 | | (pos, char) <- assocs (world :: UArray Coord Char) 80 | , Just cell <- [charToCell char] 81 | ] 82 | 83 | startSearch :: UArray Coord Char -> Coord -> Cell -> [(Coord, Cell, Int)] 84 | startSearch world start startCell = 85 | [ (here, cell, n) 86 | | (here, Just cell, n) <- bfsOn (\(p,_,_)->p) step (start, Just startCell, 0) 87 | ] 88 | where 89 | step (here, hereCell, n) 90 | | here /= start && isJust hereCell = [] 91 | | otherwise = 92 | [ (there, thereCell, n+1) 93 | | there <- cardinal here 94 | , let char = world ! there 95 | , let thereCell = charToCell char 96 | , char /= '#' 97 | ] 98 | 99 | ------------------------------------------------------------------------ 100 | -- Multiple robot search to gather all keys 101 | ------------------------------------------------------------------------ 102 | 103 | data AllKeys = AllKeys 104 | { akKeys :: !IntSet -- ^ keys found 105 | , akLocations :: !(Set Coord) -- ^ robot locations 106 | } 107 | deriving (Ord, Eq, Show) 108 | 109 | allKeys :: 110 | UArray Coord Char {- ^ world map -} -> 111 | [Coord] {- ^ robot locations -} -> 112 | Int {- ^ search states and costs -} 113 | allKeys world start = 114 | select $ astar stepAK $ AllKeys IntSet.empty $ Set.fromList start 115 | where 116 | keyN = count isLower (elems world) 117 | done s = IntSet.size (akKeys (fst s)) == keyN 118 | select = snd . head . filter done 119 | 120 | paths = extractGraph world 121 | 122 | stepAK AllKeys{..} = 123 | [ (AllKeys (IntSet.insert k akKeys) 124 | (Set.insert loc (Set.delete who akLocations)) 125 | , cost {- cost -}, 0) 126 | | who <- Set.toList akLocations 127 | , let Just whoCell = charToCell (world ! who) 128 | , (loc, k, cost) <- nextKey paths who whoCell akKeys 129 | ] 130 | 131 | ------------------------------------------------------------------------ 132 | -- Single robot moves to adjacent, unvisited keys 133 | ------------------------------------------------------------------------ 134 | 135 | nextKey :: 136 | Map Coord [(Coord, Cell, Int)] -> 137 | Coord -> 138 | Cell -> 139 | IntSet -> 140 | [(Coord, Int, Int)] 141 | nextKey paths start startCell keys = 142 | [ (here, k, cost) 143 | | ((here, Key k), cost) <- astarOn fst step (start,startCell) ] 144 | where 145 | step (here, hereCell) = 146 | [ ((loc, cell), cost, 0) 147 | | case hereCell of 148 | Key k -> IntSet.member k keys 149 | _ -> True 150 | , (loc, cell, cost) <- paths Map.! here 151 | , case cell of 152 | Gate i -> IntSet.member i keys 153 | _ -> True 154 | ] 155 | -------------------------------------------------------------------------------- /execs/Day19.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Main 3 | Description : Day 19 solution 4 | Copyright : (c) Eric Mertens, 2019 5 | License : ISC 6 | Maintainer : emertens@gmail.com 7 | 8 | 9 | 10 | -} 11 | module Main (main) where 12 | 13 | import Advent (getIntcodeInput) 14 | import Intcode (intcodeToList) 15 | 16 | main :: IO () 17 | main = 18 | do inp <- getIntcodeInput 19 19 | let p x y = 1 == head (intcodeToList inp [x,y]) 20 | print (length [ () | x <- [0..49], y <- [0..49], p x y]) 21 | print (part2 p 0 100) 22 | 23 | part2 :: (Int -> Int -> Bool) -> Int -> Int -> Int 24 | part2 p x y 25 | | bottomLeft, topRight = x * 10000 + y - 99 26 | | bottomLeft = part2 p x (y+1) 27 | | otherwise = part2 p (x+1) y 28 | where 29 | topRight = p (x+99) (y-99) 30 | bottomLeft = p x y 31 | -------------------------------------------------------------------------------- /execs/Day20.hs: -------------------------------------------------------------------------------- 1 | {-# Language BlockArguments #-} 2 | {-| 3 | Module : Main 4 | Description : Day 20 solution 5 | Copyright : (c) Eric Mertens, 2019 6 | License : ISC 7 | Maintainer : emertens@gmail.com 8 | 9 | 10 | 11 | -} 12 | module Main (main) where 13 | 14 | import Advent (getInputLines) 15 | import Advent.Coord (Coord(C), boundingBox, cardinal, coordLines, above, below, left, right) 16 | import Advent.Search (astar) 17 | import Data.Array.Unboxed (UArray, listArray, assocs, (!)) 18 | import Data.Char (isAlpha) 19 | import Data.Foldable (toList) 20 | import Data.Map (Map) 21 | import qualified Data.Map as Map 22 | import qualified Data.Set as Set 23 | 24 | main :: IO () 25 | main = 26 | do inp <- coordLines <$> getInputLines 20 27 | 28 | let world = toArray inp 29 | labels = findLabels world 30 | links = findLinks labels 31 | jumps = shortcuts world (concat labels) 32 | 33 | Just [start] = Map.lookup "AA" labels 34 | Just [end ] = Map.lookup "ZZ" labels 35 | 36 | outside = mkIsOutside labels 37 | 38 | layerChange p 39 | | outside p = -1 40 | | otherwise = 1 41 | 42 | print (search (const 0) jumps links start end) 43 | print (search layerChange jumps links start end) 44 | 45 | -- | Build predicate for coordinates on outer wall. 46 | mkIsOutside :: 47 | Map String [Coord] {- ^ labeled coordinates -} -> 48 | Coord -> Bool 49 | mkIsOutside labels = \(C y x) -> x == xhi || x == xlo || y == yhi || y == ylo 50 | where 51 | Just (C ylo xlo, C yhi xhi) = boundingBox (concat labels) 52 | 53 | toArray :: [(Coord, Char)] -> UArray Coord Char 54 | toArray xs = listArray b (map snd xs) 55 | where 56 | Just b = boundingBox (map fst xs) 57 | 58 | data Pos = Pos !Coord !Int 59 | deriving (Eq, Ord, Show) 60 | 61 | search :: 62 | (Coord -> Int) {- ^ layer change -} -> 63 | Map Coord [(Coord, Int)] {- ^ maze movements -} -> 64 | Map Coord Coord {- ^ warp links -} -> 65 | Coord {- ^ start position -} -> 66 | Coord {- ^ end position -} -> 67 | Int {- ^ steps to end -} 68 | search delta jumps links start end = 69 | snd $ head $ filter isDone $ astar step (Pos start 0) 70 | where 71 | isDone (p,_) = Pos end 0 == p 72 | 73 | step (Pos here depth) = 74 | -- travel through a warp tile 75 | [ (Pos exit depth', cost + 1, 0) 76 | | (enter, cost) <- Map.findWithDefault [] here jumps 77 | , exit <- toList (Map.lookup enter links) 78 | , let depth' = depth + delta enter 79 | , depth' >= 0 80 | ] ++ 81 | -- finish maze 82 | [ (Pos enter 0, cost, 0) 83 | | depth == 0 84 | , (enter, cost) <- Map.findWithDefault [] here jumps 85 | , enter == end 86 | ] 87 | 88 | -- | Find output destinations for each warp tile. 89 | findLinks :: 90 | Map String [Coord] {- ^ labeled tiles -} -> 91 | Map Coord Coord {- ^ warp links -} 92 | findLinks xs = 93 | Map.fromList 94 | do [p1,p2] <- Map.elems xs 95 | [(p1,p2), (p2,p1)] 96 | 97 | -- | Find labeled coordinates. 98 | findLabels :: UArray Coord Char -> Map String [Coord] 99 | findLabels m = 100 | Map.fromListWith (++) 101 | [ (lbl, [pos]) 102 | | (pos, '.') <- assocs m 103 | , (f1, f2) <- adjFuns 104 | , let lbl = [m ! f1 pos, m ! f2 pos] 105 | , all isAlpha lbl 106 | ] 107 | where 108 | adjFuns = [ (left.left, left) 109 | , (right, right.right) 110 | , (above.above, above) 111 | , (below, below.below) ] 112 | 113 | 114 | 115 | -- | Given a list of starting positions find map of destinations 116 | -- and costs to those destinations. 117 | shortcuts :: UArray Coord Char -> [Coord] -> Map Coord [(Coord,Int)] 118 | shortcuts world targets = Map.fromList [(start, travelFrom start) | start <- targets] 119 | where 120 | targetSet = Set.fromList targets 121 | 122 | travelFrom src = 123 | [ (dst,n) 124 | | (dst,n) <- astar step src 125 | , Set.member dst targetSet 126 | , dst /= src 127 | ] 128 | 129 | step here = [(there, 1, 0) | there <- cardinal here, world ! there == '.'] 130 | -------------------------------------------------------------------------------- /execs/Day21.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Main 3 | Description : Day 21 solution 4 | Copyright : (c) Eric Mertens, 2019 5 | License : ISC 6 | Maintainer : emertens@gmail.com 7 | 8 | 9 | 10 | -} 11 | module Main (main) where 12 | 13 | import Advent (getIntcodeInput) 14 | import Data.Char (ord) 15 | import Intcode (intcodeToList) 16 | 17 | main :: IO () 18 | main = 19 | do inp <- getIntcodeInput 21 20 | let letsGo = print . last . intcodeToList inp . map ord 21 | letsGo part1 22 | letsGo part2 23 | 24 | -- !(A ∧ C) ∧ D # test cases didn't need B to be checked 25 | part1 :: String 26 | part1 = 27 | unlines 28 | [ "OR A J", 29 | "AND C J", 30 | "NOT J J", 31 | "AND D J", 32 | "WALK" ] 33 | 34 | -- !(A ∧ B ∧ C) ∧ D ∧ (E ∨ H) 35 | part2 :: String 36 | part2 = 37 | unlines 38 | [ "OR A J", 39 | "AND B J", 40 | "AND C J", 41 | "NOT J J", 42 | "AND D J", 43 | "OR E T", 44 | "OR H T", 45 | "AND T J", 46 | "RUN" ] 47 | -------------------------------------------------------------------------------- /execs/Day22.hs: -------------------------------------------------------------------------------- 1 | {-# Language RankNTypes, OverloadedStrings, ViewPatterns #-} 2 | {-| 3 | Module : Main 4 | Description : Day 22 solution 5 | Copyright : (c) Eric Mertens, 2019 6 | License : ISC 7 | Maintainer : emertens@gmail.com 8 | 9 | 10 | 11 | >>> let shuffleTest cmds = invert (techsToLinearFn cmds) `withModulus` 10 <$> [0..9] 12 | 13 | >>> shuffleTest [DealNew] 14 | [9,8,7,6,5,4,3,2,1,0] 15 | 16 | >>> shuffleTest [Cut 3] 17 | [3,4,5,6,7,8,9,0,1,2] 18 | 19 | >>> shuffleTest [Cut (-4)] 20 | [6,7,8,9,0,1,2,3,4,5] 21 | 22 | >>> shuffleTest [DealInc 3] 23 | [0,7,4,1,8,5,2,9,6,3] 24 | 25 | >>> shuffleTest [DealInc 7, DealNew, DealNew] 26 | [0,3,6,9,2,5,8,1,4,7] 27 | 28 | >>> shuffleTest [Cut 6, DealInc 7, DealNew] 29 | [3,0,7,4,1,8,5,2,9,6] 30 | 31 | >>> shuffleTest [DealInc 7, DealInc 9, Cut (-2)] 32 | [6,3,0,7,4,1,8,5,2,9] 33 | 34 | >>> shuffleTest [DealNew, Cut (-2), DealInc 7, Cut 8, Cut (-4), DealInc 7, Cut 3, DealInc 9, DealInc 3, Cut (-1)] 35 | [9,2,5,8,1,4,7,0,3,6] 36 | 37 | -} 38 | module Main (main) where 39 | 40 | import Advent (Parser, getParsedLines, number) 41 | import Control.Applicative ((<|>)) 42 | import Data.Semigroup (stimes) 43 | import GHC.Natural (Natural) 44 | import GHC.TypeNats (KnownNat, SomeNat(..), someNatVal) 45 | import Data.Mod (Mod, unMod) 46 | 47 | ------------------------------------------------------------------------ 48 | -- Parsing 49 | ------------------------------------------------------------------------ 50 | 51 | data Technique 52 | = Cut Integer -- ^ cut N cards 53 | | DealInc Integer -- ^ deal with increment N 54 | | DealNew -- ^ deal into new stack 55 | deriving Show 56 | 57 | parseTechnique :: Parser Technique 58 | parseTechnique 59 | = Cut <$ "cut " <*> number 60 | <|> DealInc <$ "deal with increment " <*> number 61 | <|> DealNew <$ "deal into new stack" 62 | 63 | ------------------------------------------------------------------------ 64 | -- Shuffles 65 | ------------------------------------------------------------------------ 66 | 67 | -- | Compute function for a shuffle instruction mapping cards 68 | -- in the shuffled deck to positions in the shuffled deck. 69 | techToLinearFn :: KnownNat n => Technique -> LinearFn (Mod n) 70 | techToLinearFn DealNew = LinearFn (-1) (-1) -- λx. -x-1 71 | techToLinearFn (Cut i) = LinearFn 1 (-fromInteger i) -- λx. x-i 72 | techToLinearFn (DealInc i) = LinearFn (fromInteger i) 0 -- λx. ix 73 | 74 | -- | Construts the linear function corresponding to applying the 75 | -- given shuffles in order from left to right. 76 | techsToLinearFn :: KnownNat n => [Technique] -> LinearFn (Mod n) 77 | techsToLinearFn = foldMap techToLinearFn 78 | 79 | ------------------------------------------------------------------------ 80 | -- Linear functions 81 | ------------------------------------------------------------------------ 82 | 83 | -- | Linear functions: @Linear a b ~ λx. ax+b@ 84 | data LinearFn a = LinearFn !a !a 85 | deriving Show 86 | 87 | apply :: Num a => LinearFn a -> a -> a 88 | apply (LinearFn a b) = \x -> a * x + b 89 | 90 | invert :: Fractional a => LinearFn a -> LinearFn a 91 | invert (LinearFn a b) = LinearFn a' (-b*a') 92 | where a' = recip a 93 | 94 | -- | Reverse-composition of linear functions 95 | -- 96 | -- >>> let f = LinearFn 1 2 97 | -- >>> let g = LinearFn 3 4 98 | -- >>> (f <> g) `apply` 10 99 | -- 40 100 | -- >>> g `apply` (f `apply` 10) 101 | -- 40 102 | instance Num a => Semigroup (LinearFn a) where 103 | LinearFn c d <> LinearFn a b = LinearFn (a*c) (b + a*d) 104 | 105 | instance Num a => Monoid (LinearFn a) where 106 | mempty = LinearFn 1 0 107 | 108 | ------------------------------------------------------------------------ 109 | -- Driver code 110 | ------------------------------------------------------------------------ 111 | 112 | main :: IO () 113 | main = 114 | do techniques <- getParsedLines 22 parseTechnique 115 | 116 | let shuffle :: KnownNat n => LinearFn (Mod n) 117 | shuffle = techsToLinearFn techniques 118 | 119 | print ((shuffle `withModulus` 10007) 2019) 120 | 121 | let iterations = 101741582076661 :: Int 122 | decksize = 119315717514047 123 | print ((stimes iterations (invert shuffle) `withModulus` decksize) 2020) 124 | 125 | withModulus :: 126 | (forall n. KnownNat n => LinearFn (Mod n)) -> 127 | Natural -> Natural -> Natural 128 | f `withModulus` (someNatVal -> SomeNat m) = unMod . asMod m . apply f . fromIntegral 129 | 130 | asMod :: proxy n -> Mod n -> Mod n 131 | asMod _ x = x 132 | -------------------------------------------------------------------------------- /execs/Day23.hs: -------------------------------------------------------------------------------- 1 | {-# Language ImportQualifiedPost, ViewPatterns #-} 2 | {-| 3 | Module : Main 4 | Description : Day 23 solution 5 | Copyright : (c) Eric Mertens, 2019 6 | License : ISC 7 | Maintainer : emertens@gmail.com 8 | 9 | 10 | 11 | -} 12 | module Main (main) where 13 | 14 | import Advent (getIntcodeInput) 15 | import Advent.Queue (Queue(Empty, (:<|)), (|>), singleton) 16 | import Control.Monad.Trans.State.Strict (State, modify', runState) 17 | import Data.IntMap (IntMap) 18 | import Data.IntMap qualified as IntMap 19 | import Data.List (group) 20 | import Intcode (Effect(..), feedInput, run, new) 21 | 22 | main :: IO () 23 | main = 24 | do inp <- getIntcodeInput 23 25 | let events = start (run (new inp)) 26 | print (head [y | SetNat y <- events]) 27 | print (firstDup [y | Stall y <- events]) 28 | 29 | data Packet = Pkt !Int !Int !Int -- ^ destination, x, y 30 | 31 | -- | Map of VM identities to current execution state. 32 | type Network = IntMap Effect 33 | 34 | data Event 35 | = SetNat !Int -- ^ Y value of packet set to 255 36 | | Stall !Int -- ^ Y value of packet used to revive the network 37 | 38 | -- | Given the program that runs on each machine, initialize it with its 39 | -- network address and start the packet routing loop. Produce a list of 40 | -- events generated by this network. 41 | start :: Effect -> [Event] 42 | start eff = routeState (traverse gather net) Empty 0 0 43 | where 44 | net = IntMap.fromList [(i, feedInput [i] eff) | i <- [0..49]] 45 | 46 | ------------------------------------------------------------------------ 47 | 48 | -- | Main network event loop that feeds the network packets from 49 | -- its queue and automatically sends NAT wakeup packets when the 50 | -- queue becomes empty to wake the network. All of the machines 51 | -- stored in the network should be maintained in a stalled state. 52 | route :: Network -> Queue Packet -> Int -> Int -> [Event] 53 | route net Empty x y = Stall y : route net (singleton (Pkt 0 x y)) x y 54 | route net (Pkt 255 x y :<| ps) _ _ = SetNat y : route net ps x y 55 | route net (p :<| ps) x y = routeState (deliver p net) ps x y 56 | 57 | -- helper for running the packet queue through a stateful computation 58 | -- that computes a new 'Network' while emitting packets. 59 | routeState :: State (Queue Packet) Network -> Queue Packet -> Int -> Int -> [Event] 60 | routeState m ps = uncurry route (runState m ps) 61 | 62 | -- | Deliver a packet and then gather all the resulting outputs into the 63 | -- send queue leaving that machine back in a stalled state. 64 | deliver :: Packet -> Network -> State (Queue Packet) Network 65 | deliver (Pkt i x y) = ix i (gather . feedInput [x,y]) 66 | 67 | -- | Get all the packets a machine is ready to send and add them to the 68 | -- send queue. If the machine isn't quite ready try sending a @-1@. 69 | gather :: Effect -> State (Queue Packet) Effect 70 | gather ( Output i (Output x (Output y e))) = modify' (|> Pkt i x y) >> gather e 71 | gather (feedInput [-1] -> Output i (Output x (Output y e))) = modify' (|> Pkt i x y) >> gather e 72 | gather e = pure e 73 | 74 | -- Generic utility functions ------------------------------------------- 75 | 76 | -- | Find first duplicate, adjacent elements in a list 77 | firstDup :: Eq a => [a] -> a 78 | firstDup ys = head [x | x:_:_ <- group ys] 79 | 80 | -- | Run an applicative function on the element found at the given key if it's defined. 81 | -- This is a specific case of @ix@ from the lens package. 82 | ix :: Applicative f => Int -> (a -> f a) -> IntMap a -> f (IntMap a) 83 | ix k f = IntMap.alterF (traverse f) k 84 | -------------------------------------------------------------------------------- /execs/Day24.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Main 3 | Description : Day 24 solution 4 | Copyright : (c) Eric Mertens, 2019 5 | License : ISC 6 | Maintainer : emertens@gmail.com 7 | 8 | 9 | 10 | -} 11 | module Main (main) where 12 | 13 | import Advent (getInputLines) 14 | import Advent.Coord (Coord(..), addCoord, coordLines, cardinal) 15 | import Data.Set (Set) 16 | import qualified Data.Set as Set 17 | import qualified Data.Map.Strict as Map 18 | 19 | main :: IO () 20 | main = 21 | do inp <- bugCoords <$> getInputLines 24 22 | print (biodiversity (findDup (iterate (update (filter inside . cardinal)) inp))) 23 | 24 | let inp3 = Set.map to3 inp 25 | print (Set.size (iterate (update cardinal3) inp3 !! 200)) 26 | 27 | -- | Compute the part 1 biodiversity score. 28 | biodiversity :: Set Coord -> Int 29 | biodiversity m = sum [ 2^(12+(y*5)+x) | C y x <- Set.toList m] 30 | 31 | -- | Apply automata rule to set of bug coordinates. 32 | update :: Ord a => (a -> [a]) -> Set a -> Set a 33 | update adjacents m 34 | = Set.filter rule 35 | $ Set.union m 36 | $ Map.keysSet density 37 | where 38 | rule k = 1 == n || 2 == n && Set.notMember k m 39 | where n = Map.findWithDefault 0 k density 40 | 41 | density = Map.fromListWith (+) 42 | [(d, 1::Int) | c <- Set.toList m, d <- adjacents c] 43 | 44 | -- | Compute the coordinates of the input bugs centered around 0,0 45 | bugCoords :: [String] -> Set Coord 46 | bugCoords xs = Set.fromList [ addCoord (C (-2) (-2)) k | (k, '#') <- coordLines xs] 47 | 48 | 49 | -- | Find the first duplicate element in a list. 50 | findDup :: Ord a => [a] -> a 51 | findDup = go Set.empty 52 | where 53 | go _ [] = error "no duplicates" 54 | go seen (x:xs) 55 | | Set.member x seen = x 56 | | otherwise = go (Set.insert x seen) xs 57 | 58 | -- | Check that a coordinate is contained within the 5x5 region centered 59 | -- around the origin. 60 | inside :: Coord -> Bool 61 | inside (C y x) = abs x <= 2 && abs y <= 2 62 | 63 | ------------------------------------------------------------------------ 64 | -- 3-dimensional recursive board coordinates 65 | ------------------------------------------------------------------------ 66 | 67 | data C3 = C3 !Int !Int !Int 68 | deriving (Eq, Ord, Show) 69 | 70 | to3 :: Coord -> C3 71 | to3 (C y x) = C3 0 y x 72 | 73 | toL, toR, toA :: C3 -> C3 74 | toL (C3 d y x) = C3 d (-x) y 75 | toR (C3 d y x) = C3 d x (-y) 76 | toA (C3 d y x) = C3 d (-y) (-x) 77 | 78 | cardinal3 :: C3 -> [C3] 79 | cardinal3 c = 80 | concat [ above3 c, 81 | map toR $ above3 $ toL c, 82 | map toL $ above3 $ toR c, 83 | map toA $ above3 $ toA c] 84 | 85 | {-# INLINE above3 #-} 86 | above3 :: C3 -> [C3] 87 | above3 (C3 d 1 0) = [C3 (d+1) ( 2) x| x <- [-2..2]] 88 | above3 (C3 d (-2) _) = [C3 (d-1) ( -1) 0] 89 | above3 (C3 d y x) = [C3 (d ) (y-1) x] 90 | -------------------------------------------------------------------------------- /execs/Day25.hs: -------------------------------------------------------------------------------- 1 | {-| 2 | Module : Main 3 | Description : Day 25 solution 4 | Copyright : (c) Eric Mertens, 2019 5 | License : ISC 6 | Maintainer : emertens@gmail.com 7 | 8 | 9 | 10 | @ 11 | #-# #-# 12 | | | 13 | # # 14 | | | 15 | #-#-S-#-#-# 16 | | 17 | #-#-# 18 | | 19 | #-#-#-# 20 | | 21 | # 22 | @ 23 | -} 24 | module Main (main) where 25 | 26 | import Advent (getIntcodeInput) 27 | import Data.Char (ord, chr) 28 | import Data.Foldable (traverse_) 29 | import Intcode 30 | 31 | main :: IO () 32 | main = 33 | do inp <- getIntcodeInput 25 34 | --traverse_ putStrLn (asciiComputer inp direct) 35 | traverse_ putStrLn (asciiComputer inp search) 36 | 37 | asciiComputer :: [Int] -> [String] -> [String] 38 | asciiComputer inp cmds = 39 | lines $ map chr $ intcodeToList inp $ map ord $ unlines cmds 40 | 41 | search :: [String] 42 | search = 43 | [ north, take_ "sand" 44 | , north, take_ "space heater" 45 | , east , take_ "semiconductor" 46 | , west , south, south, east , take_ "ornament" 47 | , east , east , west , west , south, take_ "festive hat" 48 | , east , take_ "asterisk" 49 | , south, east , take_ "cake" 50 | , east {- electromagnet -} 51 | , south, north, west , west , west , take_ "food ration" 52 | , east , north, west , west {- photons -} 53 | , east , north, west , west {- molten lava -} 54 | , west , east , north {- infinite loop -} 55 | , north] ++ graycode west drop_ take_ items 56 | 57 | graycode :: 58 | a {- attempt -} -> 59 | (a -> a) {- action -} -> 60 | (a -> a) {- inverse action -} -> 61 | [a] {- items -} -> 62 | [a] {- search instructions -} 63 | graycode tick f1 f2 xs = foldr step base xs f1 [] 64 | where 65 | base = \_ -> (tick:) 66 | step x go = \f -> go f1 . (f x :) . go f2 67 | 68 | items :: [String] 69 | items = 70 | [ "cake" 71 | , "sand" 72 | , "asterisk" 73 | , "ornament" 74 | , "festive hat" 75 | , "food ration" 76 | , "space heater" 77 | , "semiconductor" 78 | ] 79 | 80 | {- 81 | direct :: [String] 82 | direct = 83 | [north, north, take_ "space heater", 84 | east, take_ "semiconductor", 85 | west, south, south, east, take_ "ornament", 86 | south, take_ "festive hat", 87 | north, west, west, north, north, west] 88 | -} 89 | 90 | north, south, east, west :: String 91 | north = "north" 92 | south = "south" 93 | east = "east" 94 | west = "west" 95 | 96 | take_ :: String -> String 97 | take_ x = "take " ++ x 98 | 99 | drop_ :: String -> String 100 | drop_ x = "drop " ++ x 101 | -------------------------------------------------------------------------------- /execs/IntcodeConsole.hs: -------------------------------------------------------------------------------- 1 | module Main (main) where 2 | 3 | import Advent (memoryParser) 4 | import Control.Exception 5 | import Data.Char (chr, ord) 6 | import Data.Either 7 | import Data.Foldable 8 | import Data.List (intercalate) 9 | import Data.Map (Map) 10 | import Data.Sequence (Seq) 11 | import Intcode 12 | import Intcode.Machine 13 | import System.Console.ANSI 14 | import System.Console.GetOpt 15 | import System.Environment 16 | import System.Exit 17 | import System.IO 18 | import System.IO.Error 19 | import Text.Megaparsec (parse, errorBundlePretty) 20 | import Text.Read (readMaybe) 21 | import qualified Data.Map as Map 22 | import qualified Data.Sequence as Seq 23 | 24 | ------------------------------------------------------------------------ 25 | -- Command line arguments 26 | ------------------------------------------------------------------------ 27 | 28 | data Args = Args 29 | { argsFilename :: FilePath 30 | , overrides :: [(Int,Int)] 31 | , initialmode :: OutMode 32 | , initialRel :: Int 33 | , initialPC :: Int 34 | } 35 | 36 | options :: [OptDescr (Either String (Args -> Args))] 37 | options = 38 | 39 | [ let parseOverride str 40 | | [(pos,':':str1)] <- reads str 41 | , [(val,"" )] <- reads str1 = 42 | Right (\a -> a { overrides = overrides a ++ [(pos,val)] }) 43 | | otherwise = Left ("Unable to parse override: " ++ show str) 44 | 45 | in Option ['s'] ["set"] (ReqArg parseOverride "POS:VAL") "Override initial memory" 46 | 47 | 48 | , let parseMode str 49 | | Just mode <- lookup str availableModes = 50 | Right (\a -> a{initialmode = mode}) 51 | | otherwise = 52 | Left ("Valid modes:" ++ concat [' ':name | (name,_) <- availableModes]) 53 | in Option ['o'] ["output"] (ReqArg parseMode "MODE") "Initial output mode" 54 | 55 | 56 | , let parsePC str 57 | | [(i,"")] <- reads str = 58 | Right (\a -> a{initialPC = i}) 59 | | otherwise = Left "Unable to parse program counter" 60 | 61 | in Option ['p'] ["pc"] (ReqArg parsePC "POS") "Override initial program counter" 62 | 63 | 64 | , let parseRel str 65 | | [(i,"")] <- reads str, 0 <= i = 66 | Right (\a -> a{initialRel = i}) 67 | | otherwise = Left "Unable to parse relative base" 68 | 69 | in Option ['r'] ["rel"] (ReqArg parseRel "POS") "Override initial relative base" 70 | ] 71 | 72 | getAppArgs :: IO Args 73 | getAppArgs = 74 | do args <- getArgs 75 | case getOpt RequireOrder options args of 76 | (flagResult, filenames, errors) 77 | | null allErrors -> 78 | pure $ foldl (flip id) 79 | Args { argsFilename = head filenames 80 | , overrides = [] 81 | , initialmode = OutASCII 82 | , initialRel = 0 83 | , initialPC = 0 } 84 | updates 85 | 86 | | otherwise -> 87 | do errorPrintLn (usageInfo "Usage: IntcodeConsole FILENAME" options) 88 | mapM_ errorPrintLn errors 89 | exitFailure 90 | 91 | where 92 | (argErrors, updates) = partitionEithers flagResult 93 | filenameErrors = 94 | case filenames of 95 | [] -> ["missing filename"] 96 | _:_:_ -> ["too many filenames"] 97 | _ -> [] 98 | allErrors = filenameErrors ++ 99 | argErrors ++ 100 | errors 101 | 102 | ------------------------------------------------------------------------ 103 | -- Initialization 104 | ------------------------------------------------------------------------ 105 | 106 | getMachine :: Args -> IO Machine 107 | getMachine args = 108 | do imageText <- readFile (argsFilename args) 109 | case parse memoryParser (argsFilename args) imageText of 110 | Left e -> fail (errorBundlePretty e) 111 | Right i -> 112 | do let i1 = foldl' (\acc (p,v) -> set p v acc) 113 | (new i) 114 | (overrides args) 115 | i2 = i1 { pc = initialPC args 116 | , relBase = initialRel args } 117 | pure i2 118 | 119 | 120 | main :: IO () 121 | main = 122 | do args <- getAppArgs 123 | mach <- getMachine args 124 | launch Console 125 | { machine = mach 126 | , looper = looperStep mach 127 | , history = Seq.Empty 128 | , inputq = [] 129 | , outmode = initialmode args } 130 | 131 | ------------------------------------------------------------------------ 132 | -- Console logic 133 | ------------------------------------------------------------------------ 134 | 135 | data Console = Console 136 | { machine :: !Machine 137 | , looper :: !(Maybe Machine) 138 | , history :: Seq Machine 139 | , inputq :: [Int] 140 | , outmode :: OutMode 141 | } 142 | 143 | data OutMode = OutASCII | OutInt 144 | deriving (Eq, Ord, Show, Read) 145 | 146 | availableModes :: [(String, OutMode)] 147 | availableModes = [("ascii", OutASCII), ("int", OutInt)] 148 | 149 | 150 | addInput :: [Int] -> Console -> Console 151 | addInput [] con = con 152 | addInput xs con = con { history = history con Seq.|> machine con 153 | , inputq = xs } 154 | 155 | looperStep :: Machine -> Maybe Machine 156 | looperStep m = 157 | case step m of 158 | Step m' -> Just m' 159 | StepOut _ m' -> Just m' 160 | _ -> Nothing 161 | 162 | launch :: Console -> IO () 163 | launch con 164 | | Just (machine con) == looper con = 165 | do errorPrintLn "<>" 166 | prompt con{ looper = looperStep (machine con) } 167 | | otherwise = 168 | 169 | let looper' = looperStep =<< looperStep =<< looper con in 170 | case step (machine con) of 171 | Step m' -> 172 | launch con{ machine = m', looper = looper' } 173 | 174 | StepOut o m' -> 175 | do emit o (outmode con) 176 | launch con{ machine = m', looper = looper' } 177 | 178 | StepIn resume -> 179 | case inputq con of 180 | x:xs -> let m = resume x 181 | in launch con{ inputq = xs, machine = m, looper = looperStep m } 182 | [] -> prompt con 183 | 184 | StepHalt -> 185 | do metaprintLn "<>" 186 | prompt con 187 | 188 | StepFault -> 189 | do metaprintLn "<>" 190 | prompt con 191 | 192 | 193 | prompt :: Console -> IO () 194 | prompt con = 195 | do -- draw the prompt 196 | setTitle ("Intcode Console" ++ 197 | " PC:" ++ show (pc (machine con)) ++ 198 | " REL:" ++ show (relBase (machine con))) 199 | metaprint (show (length (history con)) ++ "> ") 200 | 201 | -- get next line 202 | setSGR [SetColor Foreground Dull Yellow] 203 | hFlush stdout 204 | line <- try getLine 205 | setSGR [Reset] 206 | 207 | -- process input 208 | case line of 209 | Left e | isEOFError e -> putStrLn "" 210 | | otherwise -> errorPrintLn (displayException e) 211 | Right [] -> prompt con 212 | Right ('!':command) -> runCommand command con 213 | Right str -> launch (addInput (map ord (str ++ "\n")) con) 214 | 215 | runCommand :: String -> Console -> IO () 216 | runCommand command con = 217 | case words command of 218 | [] -> prompt con 219 | cmd:args -> 220 | case Map.lookup cmd commandImpls of 221 | Nothing -> errorPrintLn "Unknown command" >> prompt con 222 | Just impl -> impl args con 223 | 224 | ------------------------------------------------------------------------ 225 | -- Command implementations 226 | ------------------------------------------------------------------------ 227 | 228 | commandImpls :: Map String ([String] -> Console -> IO ()) 229 | commandImpls = Map.fromList 230 | [("back" , backCommand ) 231 | ,("dump" , dumpCommand ) 232 | ,("ints" , intsCommand ) 233 | ,("output", outputCommand) 234 | ,("help" , helpCommand ) 235 | ,("info" , infoCommand ) 236 | ,("changes" , changesCommand ) 237 | ] 238 | 239 | infoCommand :: [String] -> Console -> IO () 240 | infoCommand _ con = 241 | do metaprintLn ("PC : " ++ show (pc (machine con))) 242 | metaprintLn ("REL: " ++ show (relBase (machine con))) 243 | metaprintLn ("CNG: " ++ show (length (memUpdates (machine con)))) 244 | prompt con 245 | 246 | helpCommand :: [String] -> Console -> IO () 247 | helpCommand _ con = 248 | do metaprintLn ("Available commands:" ++ 249 | concat [' ':name | name <- Map.keys commandImpls]) 250 | prompt con 251 | 252 | outputCommand :: [String] -> Console -> IO () 253 | outputCommand args con = 254 | case args of 255 | [modestr] | Just mode <- lookup modestr availableModes -> 256 | launch con{ outmode = mode } 257 | 258 | _ -> do errorPrintLn ("Valid modes:" ++ concat [' ':name | (name,_) <- availableModes]) 259 | prompt con 260 | 261 | changesCommand :: [String] -> Console -> IO () 262 | changesCommand _ con = 263 | do metaprintLn (show (memUpdates (machine con))) 264 | prompt con 265 | 266 | backCommand :: [String] -> Console -> IO () 267 | backCommand args con = 268 | case param of 269 | Just i 270 | | (l, m Seq.:<| _) <- Seq.splitAt i (history con) -> 271 | launch con{ history = l 272 | , machine = m 273 | , inputq = [] } 274 | _ -> 275 | do errorPrintLn "Bad arguments to back" 276 | prompt con 277 | where 278 | param = 279 | case args of 280 | [istr] -> readMaybe istr 281 | [] -> Just (length (history con) - 1) 282 | _ -> Nothing 283 | 284 | dumpCommand :: [String] -> Console -> IO () 285 | dumpCommand args con = 286 | case args of 287 | [filename] -> 288 | do let txt = intercalate "," (map show (memoryList (machine con))) ++ "\n" 289 | writeFile filename txt 290 | prompt con 291 | 292 | _ -> 293 | do errorPrintLn "Bad arguments to dump" 294 | prompt con 295 | 296 | intsCommand :: [String] -> Console -> IO () 297 | intsCommand args con = 298 | case traverse readMaybe args of 299 | Just ints -> launch (addInput ints con) 300 | Nothing -> 301 | do errorPrintLn "Bad arguments to ints" 302 | prompt con 303 | 304 | ------------------------------------------------------------------------ 305 | -- Console IO 306 | ------------------------------------------------------------------------ 307 | 308 | metaprintLn :: String -> IO () 309 | metaprintLn str = metaprint (str ++ "\n") 310 | 311 | metaprint :: String -> IO () 312 | metaprint str = 313 | do setSGR [ SetConsoleIntensity BoldIntensity 314 | , SetColor Foreground Dull Green ] 315 | putStr str 316 | setSGR [Reset] 317 | hFlush stdout 318 | 319 | errorPrintLn :: String -> IO () 320 | errorPrintLn str = 321 | do setSGR [SetColor Foreground Dull Red] 322 | putStrLn str 323 | setSGR [Reset] 324 | hFlush stdout 325 | 326 | emit :: Int -> OutMode -> IO () 327 | emit i mode 328 | | 0 <= i, i < 0x80, mode == OutASCII = putChar (chr i) 329 | | otherwise = metaprintLn ("<>") 330 | -------------------------------------------------------------------------------- /inputs/input01.txt: -------------------------------------------------------------------------------- 1 | 88093 2 | 102524 3 | 75875 4 | 62024 5 | 86072 6 | 106670 7 | 105440 8 | 51371 9 | 148951 10 | 123704 11 | 92364 12 | 50848 13 | 117125 14 | 95022 15 | 131085 16 | 129886 17 | 145084 18 | 123077 19 | 69219 20 | 84366 21 | 51344 22 | 65604 23 | 140383 24 | 53606 25 | 132685 26 | 83550 27 | 76648 28 | 120937 29 | 137498 30 | 84167 31 | 94438 32 | 54178 33 | 106306 34 | 80802 35 | 98524 36 | 70214 37 | 114108 38 | 118782 39 | 75444 40 | 76449 41 | 144233 42 | 56747 43 | 93663 44 | 137969 45 | 99981 46 | 110442 47 | 106873 48 | 93708 49 | 114085 50 | 53655 51 | 78096 52 | 137640 53 | 50775 54 | 72563 55 | 135043 56 | 146136 57 | 147244 58 | 105601 59 | 106293 60 | 63048 61 | 104864 62 | 93044 63 | 118222 64 | 107110 65 | 92725 66 | 57424 67 | 94602 68 | 87898 69 | 51668 70 | 137651 71 | 55070 72 | 67255 73 | 103823 74 | 83059 75 | 61150 76 | 82029 77 | 56060 78 | 56702 79 | 85486 80 | 114522 81 | 94121 82 | 104870 83 | 53014 84 | 111776 85 | 63615 86 | 78378 87 | 113830 88 | 80059 89 | 123427 90 | 73545 91 | 93688 92 | 122410 93 | 93174 94 | 131464 95 | 137014 96 | 114304 97 | 138703 98 | 54128 99 | 111698 100 | 84299 101 | -------------------------------------------------------------------------------- /inputs/input02.txt: -------------------------------------------------------------------------------- 1 | 1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,13,1,19,1,19,10,23,1,23,13,27,1,6,27,31,1,9,31,35,2,10,35,39,1,39,6,43,1,6,43,47,2,13,47,51,1,51,6,55,2,6,55,59,2,59,6,63,2,63,13,67,1,5,67,71,2,9,71,75,1,5,75,79,1,5,79,83,1,83,6,87,1,87,6,91,1,91,5,95,2,10,95,99,1,5,99,103,1,10,103,107,1,107,9,111,2,111,10,115,1,115,9,119,1,13,119,123,1,123,9,127,1,5,127,131,2,13,131,135,1,9,135,139,1,2,139,143,1,13,143,0,99,2,0,14,0 2 | -------------------------------------------------------------------------------- /inputs/input03.txt: -------------------------------------------------------------------------------- 1 | R995,D882,R144,U180,L638,U282,L907,D326,R731,D117,R323,U529,R330,U252,R73,U173,R345,U552,R230,U682,R861,U640,L930,U590,L851,D249,R669,D878,R951,D545,L690,U392,R609,D841,R273,D465,R546,U858,L518,U567,L474,D249,L463,D390,L443,U392,L196,U418,R433,U651,R520,D450,R763,U714,R495,D716,L219,D289,L451,D594,R874,U451,R406,U662,R261,D242,R821,D951,R808,D862,L871,U133,R841,D465,R710,U300,R879,D497,R85,U173,R941,U953,R705,U972,R260,D315,L632,U182,L26,D586,R438,U275,L588,U956,L550,D576,R738,U974,R648,D880,R595,D510,L789,U455,R627,U709,R7,D486,L184,U999,L404,U329,L852,D154,L232,U398,L587,U881,R938,D40,L657,D164,R45,D917,R106,U698,L824,D426,R879,U700,R847,D891,L948,U625,R663,D814,R217,U30,R610,D781,L415,D435,L904,U815,R152,U587,R287,U141,R866,D636,L290,D114,L751,D660,R6,U383,L263,U799,R330,U96,L6,U542,L449,D361,R486,U278,L990,U329,L519,U605,R501,D559,R916,U198,L499,D174,R513,U396,L473,D565,R337,D770,R211,D10,L591,D920,R367,D748,L330,U249,L307,D645,R661,U266,R234,D403,L513,U443,L989,D1,L674,D210,L537,D872,L607,D961,R894,U632,L195,U744,L426,U531,R337,D821,R113,U436,L700,U779,R555,U891,R268,D30,R958,U411,R904,U24,R760,D958,R231,U229,L561,D134,L382,D961,L237,U676,L223,U324,R663,D186,R833,U188,R419,D349,L721,U152,L912,U490,R10,D995,L98,U47,R140,D815,R826,U730,R808,U256,R479,D322,L504,D891,L413,D848,L732,U375,L307,U7,R682,U270,L495,D248,R691,D945,L70,U220,R635,D159,R269,D15,L161,U214,R814,D3,R354,D632,R469,D36,R85,U215,L243,D183,R140,U179,R812,U180,L905,U136,L34,D937,L875 2 | L999,D22,L292,U843,R390,U678,R688,D492,L489,U488,R305,U951,L636,U725,R402,U84,L676,U171,L874,D201,R64,D743,R372,U519,R221,U986,L393,D793,R72,D184,L553,D137,L187,U487,L757,U880,L535,U887,R481,U236,L382,D195,L388,D90,R125,U414,R512,D382,R972,U935,L172,D1,R957,U593,L151,D158,R396,D42,L30,D178,R947,U977,R67,D406,R744,D64,L677,U23,R792,U864,R259,U315,R314,U17,L37,D658,L642,U135,R624,U601,L417,D949,R203,D122,R76,D493,L569,U274,L330,U933,R815,D30,L630,D43,R86,U926,L661,D491,L541,D96,R868,D565,R664,D935,L336,D152,R63,U110,L782,U14,R172,D945,L732,D870,R404,U767,L907,D558,R748,U591,R461,D153,L635,D457,R241,U478,L237,U218,R393,U468,L182,D745,L388,D360,L222,D642,L151,U560,R437,D326,R852,U525,R717,U929,L470,U621,R421,U408,L540,D176,L69,U753,L200,U251,R742,U628,R534,U542,R85,D71,R283,U905,L418,D755,L593,U335,L114,D684,L576,D645,R652,D49,R86,D991,L838,D309,L73,U847,L418,U675,R991,U463,R314,D618,L433,U173,R869,D115,L18,U233,R541,U516,L570,U340,R264,D442,L259,U276,R433,D348,R524,D353,R336,D883,R580,U157,R79,D27,L134,D161,L748,D278,R322,D581,R654,D156,L930,D293,L156,U311,R807,D618,R408,U719,R366,D632,R307,D565,R478,D620,R988,D821,R365,D581,L946,D138,L943,U69,R620,U208,L407,U188,L122,U353,L751,U565,R849,D874,R668,D794,L140,D474,R289,D773,R344,D220,L55,D385,L394,U208,R305,U736,L896,D376,R331,D855,L466,U516,L741,U124,L825,U467,L525,D911,R76,U220,L610,U102,L261,D891,L585,U397,L152,U753,R822,D252,R106,U145,L7,U524,R343,U352,L357,D399,L446,D140,L723,U46,R687,D409,R884 3 | -------------------------------------------------------------------------------- /inputs/input04.txt: -------------------------------------------------------------------------------- 1 | 134564-585159 2 | -------------------------------------------------------------------------------- /inputs/input05.txt: -------------------------------------------------------------------------------- 1 | 3,225,1,225,6,6,1100,1,238,225,104,0,1101,91,67,225,1102,67,36,225,1102,21,90,225,2,13,48,224,101,-819,224,224,4,224,1002,223,8,223,101,7,224,224,1,223,224,223,1101,62,9,225,1,139,22,224,101,-166,224,224,4,224,1002,223,8,223,101,3,224,224,1,223,224,223,102,41,195,224,101,-2870,224,224,4,224,1002,223,8,223,101,1,224,224,1,224,223,223,1101,46,60,224,101,-106,224,224,4,224,1002,223,8,223,1001,224,2,224,1,224,223,223,1001,191,32,224,101,-87,224,224,4,224,102,8,223,223,1001,224,1,224,1,223,224,223,1101,76,90,225,1101,15,58,225,1102,45,42,224,101,-1890,224,224,4,224,1002,223,8,223,1001,224,5,224,1,224,223,223,101,62,143,224,101,-77,224,224,4,224,1002,223,8,223,1001,224,4,224,1,224,223,223,1101,55,54,225,1102,70,58,225,1002,17,80,224,101,-5360,224,224,4,224,102,8,223,223,1001,224,3,224,1,223,224,223,4,223,99,0,0,0,677,0,0,0,0,0,0,0,0,0,0,0,1105,0,99999,1105,227,247,1105,1,99999,1005,227,99999,1005,0,256,1105,1,99999,1106,227,99999,1106,0,265,1105,1,99999,1006,0,99999,1006,227,274,1105,1,99999,1105,1,280,1105,1,99999,1,225,225,225,1101,294,0,0,105,1,0,1105,1,99999,1106,0,300,1105,1,99999,1,225,225,225,1101,314,0,0,106,0,0,1105,1,99999,1008,677,677,224,102,2,223,223,1005,224,329,1001,223,1,223,1108,677,226,224,1002,223,2,223,1006,224,344,101,1,223,223,107,677,226,224,1002,223,2,223,1006,224,359,101,1,223,223,108,677,677,224,1002,223,2,223,1006,224,374,1001,223,1,223,108,226,677,224,1002,223,2,223,1006,224,389,101,1,223,223,7,226,677,224,102,2,223,223,1006,224,404,1001,223,1,223,1108,677,677,224,1002,223,2,223,1005,224,419,101,1,223,223,1008,226,677,224,102,2,223,223,1006,224,434,101,1,223,223,107,226,226,224,102,2,223,223,1005,224,449,1001,223,1,223,1007,677,677,224,1002,223,2,223,1006,224,464,1001,223,1,223,1007,226,226,224,1002,223,2,223,1005,224,479,101,1,223,223,1008,226,226,224,102,2,223,223,1006,224,494,1001,223,1,223,8,226,226,224,102,2,223,223,1006,224,509,101,1,223,223,1107,677,677,224,102,2,223,223,1005,224,524,1001,223,1,223,1108,226,677,224,1002,223,2,223,1006,224,539,101,1,223,223,1107,677,226,224,1002,223,2,223,1006,224,554,101,1,223,223,1007,677,226,224,1002,223,2,223,1005,224,569,101,1,223,223,7,677,226,224,1002,223,2,223,1006,224,584,101,1,223,223,107,677,677,224,1002,223,2,223,1005,224,599,1001,223,1,223,8,226,677,224,1002,223,2,223,1005,224,614,101,1,223,223,7,677,677,224,1002,223,2,223,1006,224,629,1001,223,1,223,1107,226,677,224,1002,223,2,223,1006,224,644,101,1,223,223,108,226,226,224,102,2,223,223,1005,224,659,1001,223,1,223,8,677,226,224,1002,223,2,223,1005,224,674,101,1,223,223,4,223,99,226 2 | -------------------------------------------------------------------------------- /inputs/input06.txt: -------------------------------------------------------------------------------- 1 | Z9G)Q7N 2 | D1W)7G9 3 | FP7)F5P 4 | L8W)55T 5 | YZC)1HN 6 | 1DQ)QKD 7 | 4RD)38D 8 | 8V7)DC8 9 | 95Q)33Q 10 | Y8N)G7L 11 | X25)7YN 12 | 5QH)JWW 13 | ZWL)HGG 14 | H4Y)RWG 15 | N38)XWR 16 | PWP)F6Y 17 | 6XB)QX1 18 | G3W)PKM 19 | 5G5)439 20 | V1Z)CBZ 21 | 8X1)5R5 22 | 6LJ)QHD 23 | V9Q)N7G 24 | WRP)XBW 25 | 61Z)7KN 26 | FQR)371 27 | KD8)GSS 28 | FMM)B8R 29 | QXD)4ZG 30 | 7JC)5SB 31 | VGH)XCZ 32 | VSN)C2H 33 | W76)12B 34 | R4Y)W7R 35 | L8H)V1Z 36 | BHB)1T9 37 | 7S2)1V6 38 | 338)MYS 39 | ZM3)RN1 40 | 3P8)WW7 41 | GVG)FPQ 42 | 43B)HKJ 43 | QN3)KK9 44 | 728)KSW 45 | QBV)J45 46 | XTS)WW1 47 | Q2C)HM8 48 | X25)9TL 49 | V63)WR1 50 | DP1)PX5 51 | GNV)J4Y 52 | 672)BY5 53 | CK1)WD2 54 | 5R5)TZR 55 | 4JW)MKF 56 | KMR)Y8K 57 | HDY)YZC 58 | CGS)ZL4 59 | RCT)238 60 | ZNZ)J3L 61 | 17F)8LJ 62 | YG5)YVS 63 | 1Z9)CK5 64 | HFN)GZV 65 | V15)97D 66 | 5NP)6XB 67 | K9D)J32 68 | Q36)KN8 69 | 91X)85T 70 | XRY)LLV 71 | ZL4)CK2 72 | JLC)DLX 73 | 99Q)8LK 74 | P3R)X6R 75 | ZNZ)SH8 76 | H7C)669 77 | V7K)43B 78 | Y9T)7VF 79 | X5L)54F 80 | RLX)TKF 81 | 5XJ)H69 82 | 7FB)MXS 83 | D74)24S 84 | MDV)VSN 85 | C1Y)J7T 86 | P8Q)BPJ 87 | LF7)JCM 88 | 77T)XYQ 89 | JYP)DCX 90 | WZ6)GB3 91 | 4YN)1Z9 92 | 5FS)Y9Z 93 | HXD)MWF 94 | XLS)CRC 95 | C93)9SN 96 | STQ)3FL 97 | D81)NLP 98 | T7T)8V7 99 | K6N)YSF 100 | 7ZB)73P 101 | 8NT)28S 102 | F1F)1L8 103 | 1HN)WL1 104 | TWS)D1W 105 | 6WG)2DS 106 | FPN)FBN 107 | CK2)NW8 108 | 2RS)DG7 109 | N6F)G5L 110 | CCK)C6M 111 | 7B9)KRX 112 | TXD)7FB 113 | J45)C32 114 | CG2)V7K 115 | 6YL)S4C 116 | PVN)CX9 117 | BTW)4FQ 118 | 6SL)CC5 119 | S97)3GM 120 | 47N)R5J 121 | T9R)5NP 122 | 3FL)HXF 123 | HF1)DSX 124 | RWJ)33Z 125 | NGS)JRF 126 | T74)D5R 127 | 9SQ)747 128 | Z7S)S4D 129 | WHS)XQ2 130 | PTF)1PW 131 | KW2)RCT 132 | 4Z7)K9D 133 | 9TV)N5N 134 | GJP)91Y 135 | RQB)WS7 136 | 14X)Y9T 137 | D1W)6ZH 138 | Z5M)M52 139 | HMM)JY4 140 | H64)SAN 141 | V3N)FT8 142 | 1ZQ)FTD 143 | WJG)516 144 | YQP)MK9 145 | 79F)GMS 146 | NC9)CKH 147 | VMD)W32 148 | GMS)385 149 | XPP)RDH 150 | JCM)8MB 151 | ZKH)CMV 152 | HYY)SK7 153 | NYN)JDY 154 | FTD)6WG 155 | G8K)Z4P 156 | 5NK)RRG 157 | GKY)3Z4 158 | Z9W)BWG 159 | LS6)3D4 160 | HZF)X5L 161 | 3NV)9TG 162 | 2HB)GLS 163 | 8N9)842 164 | T95)S6F 165 | 4PZ)338 166 | NC9)HYS 167 | VGM)VBR 168 | X9G)855 169 | GGP)WTG 170 | DRJ)HFY 171 | SXT)49K 172 | 71R)P99 173 | 49K)4VN 174 | B4P)G3W 175 | DS1)CC6 176 | PTX)Z69 177 | 19D)2V8 178 | 2DM)2VY 179 | CNT)CH4 180 | WD2)L5Y 181 | VFV)NGN 182 | BV6)8MQ 183 | HMS)NJ1 184 | V39)355 185 | 8B6)63R 186 | N6V)N8S 187 | X9X)BPV 188 | H5L)HW5 189 | QX1)8XJ 190 | BGB)2XW 191 | 8P1)99V 192 | 3H8)9TV 193 | Z2Q)XDQ 194 | 385)QS2 195 | 3D4)FMM 196 | BL3)J3T 197 | L6P)YG5 198 | JV4)6SL 199 | VL5)N6F 200 | BPV)SG7 201 | HLX)LB6 202 | KSW)SSF 203 | HKJ)KW2 204 | VYP)YGK 205 | 4RZ)KQG 206 | X8Q)X25 207 | CM4)XF4 208 | ZSG)C9Q 209 | XXP)CG2 210 | 9LS)YRN 211 | L4W)9SZ 212 | 98B)XJQ 213 | C9W)HMS 214 | SSF)9SQ 215 | 21W)J3F 216 | 4PH)H2J 217 | PKM)SHR 218 | 35M)G4D 219 | 8FT)9LH 220 | 3RW)VX8 221 | SSX)VZG 222 | BHH)BL3 223 | RTD)RNZ 224 | RD6)KMT 225 | YSL)1N8 226 | X1B)BH8 227 | LHB)HNN 228 | 73P)LHB 229 | TGY)Z2L 230 | JPD)HK3 231 | SN6)BTD 232 | FW3)T7T 233 | CBZ)1PM 234 | HV3)CM4 235 | 2DP)TX4 236 | 6P4)FWL 237 | HNN)BDH 238 | 51S)YS5 239 | 3VP)GZC 240 | 3D4)DDR 241 | MWF)66Z 242 | M52)TWS 243 | 7XM)V9Q 244 | XQ2)KQH 245 | 4XN)H8Y 246 | QKD)FP7 247 | FPQ)VC3 248 | 91Y)16Y 249 | 752)6P7 250 | RZN)T3D 251 | YS5)Z7S 252 | V1D)19X 253 | 14P)7WH 254 | KQT)FLS 255 | WVC)ZSG 256 | JXC)4JJ 257 | B8R)KD8 258 | 6S7)2MS 259 | NJH)S75 260 | S75)4Z7 261 | 8LJ)Y19 262 | C5K)57N 263 | SH2)HSR 264 | CJJ)13S 265 | 1HN)WVJ 266 | H3M)HLX 267 | N1R)Z9W 268 | S4C)XLS 269 | HP7)7LK 270 | WVJ)7JX 271 | GY3)SKW 272 | HSP)8X1 273 | VX8)2JT 274 | S4D)6CQ 275 | 9TM)752 276 | J3L)G1K 277 | 5LT)G4W 278 | HFY)6SN 279 | 4X9)VGY 280 | VMD)YK2 281 | 66Z)PWP 282 | HGP)YM7 283 | JDY)BDM 284 | ZSF)P2V 285 | MK9)XXP 286 | JRF)RFM 287 | RNZ)QRW 288 | 7QF)NJY 289 | BWN)YD5 290 | 9SS)X9V 291 | H69)GNV 292 | ZZH)LL9 293 | CM7)NYN 294 | J24)BGB 295 | RY9)5QL 296 | CCK)H5L 297 | J5M)DRJ 298 | 7LK)T74 299 | 373)RZN 300 | WQ1)7JC 301 | DG7)QBV 302 | LSR)PMX 303 | 6ZH)PYL 304 | MFL)4X9 305 | LTB)Z5M 306 | 36D)P7S 307 | 63P)DP1 308 | 38D)DVK 309 | D2P)XL6 310 | 1SZ)T3Q 311 | N27)F1F 312 | F9Q)BV6 313 | ZDS)SDJ 314 | JW6)61Z 315 | 7YN)Y14 316 | BXV)9LS 317 | JY4)VT4 318 | GVG)8FT 319 | HJW)3RW 320 | K39)GYC 321 | 14F)NCB 322 | MXS)2DM 323 | 24S)98N 324 | TKZ)CJJ 325 | XCZ)3NV 326 | NLP)X1B 327 | 87T)RL7 328 | JBF)SQV 329 | 3MZ)R56 330 | 7JX)ZNM 331 | 2S8)MPH 332 | MTL)LVS 333 | M87)3W9 334 | HXF)2L3 335 | 751)WG5 336 | 4ZG)65P 337 | 28R)DS1 338 | LPT)HYY 339 | ZGT)HKP 340 | W63)QXH 341 | ZL6)C4K 342 | W66)LVF 343 | QSN)9BR 344 | 8LY)BTW 345 | TP7)YTG 346 | SWG)BJ2 347 | 8MB)373 348 | CS8)ZDS 349 | 34F)N1R 350 | P1S)W66 351 | BWG)H2K 352 | G9T)ZM3 353 | DHJ)672 354 | H6G)V2T 355 | FCY)S1M 356 | XVM)4WM 357 | N6F)N27 358 | LZ3)HDY 359 | 9D8)6P4 360 | 2L3)PSK 361 | 5HS)SH3 362 | 4FQ)MDQ 363 | QXD)JPD 364 | 6H1)2JH 365 | GNV)WXS 366 | RRG)Z2Q 367 | SQV)HQ1 368 | GCN)JL5 369 | LG6)SH2 370 | ZXK)PTF 371 | 2JT)3H8 372 | SKW)HMM 373 | Q46)T95 374 | 2XW)71R 375 | DBL)35T 376 | T7D)NT9 377 | PJ7)PMC 378 | M6X)DBK 379 | PZT)7P1 380 | G9H)5LT 381 | 1V6)D1X 382 | MDV)M6G 383 | WVC)9D8 384 | T6X)NJG 385 | Q44)SSX 386 | BY5)Q44 387 | Y8K)DKH 388 | DLX)H64 389 | NJ1)79F 390 | 3ZH)R9Z 391 | PYP)CW6 392 | N38)728 393 | 3SC)NBL 394 | XWR)4RC 395 | BPJ)X24 396 | FCP)WQ1 397 | 8XJ)NJH 398 | 6V6)2TK 399 | M7H)PR6 400 | 65P)XM7 401 | 9R1)D74 402 | MBZ)VX3 403 | XJQ)P8Q 404 | HM8)HSP 405 | 5W2)MPV 406 | DVK)17F 407 | 8LK)5XJ 408 | BP2)6FD 409 | C6M)QLL 410 | ZXJ)KMR 411 | 8QS)YTH 412 | W35)3R1 413 | 1N8)HKQ 414 | 4VN)H6Z 415 | 2VW)3V9 416 | HYS)VFV 417 | YZ3)ZK5 418 | KNV)3VP 419 | FWL)YSL 420 | NRN)P38 421 | MFX)PVN 422 | MZ7)3P8 423 | LLV)PYP 424 | MGY)7H8 425 | N26)KCC 426 | 4ZK)2DP 427 | HJS)ZSF 428 | HTV)JXC 429 | 3J3)W4G 430 | 4GG)JNB 431 | X6R)HY5 432 | GLS)FQR 433 | 9LH)H4Y 434 | F4P)TV5 435 | HLY)V39 436 | HM8)LG6 437 | F6Y)JHK 438 | VPC)NN3 439 | YWT)X8T 440 | JV5)NQS 441 | 7FL)3ZH 442 | MKY)P3R 443 | SCR)RY9 444 | 5FR)T47 445 | BJ2)5FR 446 | NJY)MZ7 447 | BTD)JLC 448 | 516)PXS 449 | G8K)K3T 450 | 9SZ)PTX 451 | MYS)47N 452 | Z4P)CRS 453 | J84)V63 454 | 6P7)VYP 455 | YGK)596 456 | SF4)VL5 457 | PX5)4SJ 458 | 2V8)F4W 459 | XSC)FDN 460 | RBZ)35M 461 | XL6)4KJ 462 | K9M)R47 463 | Q7N)LZ3 464 | DJ2)Q36 465 | HY5)X8Q 466 | 35T)PHH 467 | C3Q)6V6 468 | SH3)CTS 469 | X8T)DHJ 470 | 3K4)W76 471 | LF1)KTP 472 | GB3)2RS 473 | RL7)HLL 474 | G1K)9TM 475 | 63R)F4P 476 | LR9)Q2C 477 | XM7)6YL 478 | 9TG)P67 479 | C32)4GG 480 | 5NP)L1Z 481 | 3V9)1TL 482 | GJP)ZGT 483 | N5N)L71 484 | VX3)7C8 485 | Q8Q)95Q 486 | Z3T)1N1 487 | 57N)HJS 488 | QS2)3SC 489 | PV8)8FF 490 | 63P)8QS 491 | PBV)JV5 492 | KQG)TXL 493 | 7P1)X9X 494 | ZK5)M28 495 | JVF)P1S 496 | DL8)JTY 497 | 9D8)91X 498 | 4WT)XCJ 499 | S6F)TPQ 500 | FDN)KPT 501 | KS4)2VW 502 | NGN)7NQ 503 | WW1)XSC 504 | HP7)YOU 505 | KTP)MV8 506 | 49K)2VD 507 | 2CJ)CCK 508 | J4Y)YSY 509 | Q2Q)MWV 510 | YTH)J5M 511 | 26H)CXL 512 | MWV)SCR 513 | W4G)9TT 514 | Y19)K6N 515 | 5QL)GKY 516 | R5K)BBQ 517 | C2H)M74 518 | WW7)Q8Q 519 | YSF)J84 520 | 9BR)14P 521 | 6FD)CM7 522 | 7G9)XTS 523 | TV5)ZKK 524 | X24)Y8N 525 | CSK)3YD 526 | HSR)H3M 527 | 211)CK1 528 | 92P)BHH 529 | MGZ)MDV 530 | 5ZR)Q2Q 531 | P7S)2FV 532 | JWW)Z9G 533 | 99V)ZZH 534 | WXS)S97 535 | PVN)HP7 536 | 6CQ)KXK 537 | RZF)RD6 538 | M87)RLQ 539 | Y9Z)DT2 540 | PR6)GNR 541 | WL1)VGH 542 | LG6)6Z2 543 | C4K)HV3 544 | WS7)KD5 545 | 98N)XCT 546 | CKH)BHB 547 | 8CH)TGY 548 | GMS)99Q 549 | 7VF)K39 550 | D54)LF1 551 | 4SJ)PV8 552 | BDM)JW6 553 | 3YD)ZL6 554 | BBQ)5NK 555 | 9BR)GCN 556 | 73L)D54 557 | MDQ)TP7 558 | C9Q)2S8 559 | 2TK)77T 560 | PR5)LS6 561 | L5Y)FHX 562 | VZG)4PH 563 | NCB)D31 564 | H6Z)PBV 565 | 6YD)26H 566 | XCT)63P 567 | BDH)8KZ 568 | VX3)ZNZ 569 | 7PM)3MZ 570 | F4W)R4Y 571 | HKQ)PZT 572 | HKY)QN3 573 | TQY)FCY 574 | NJG)QX8 575 | CMV)8NT 576 | NN3)HK9 577 | 7P1)5ZR 578 | 697)YQP 579 | RV3)69K 580 | QX8)G9H 581 | R5J)RWJ 582 | 13S)T2D 583 | NT9)NC4 584 | RLQ)BR6 585 | M24)CS8 586 | YSY)2HB 587 | VGY)DBL 588 | QQN)CCC 589 | RWG)X76 590 | SSX)F9Q 591 | FT5)N38 592 | 6QQ)SY4 593 | JL5)L4W 594 | 2VD)211 595 | 5BF)36D 596 | JV4)L6P 597 | RDH)XW8 598 | 61C)LC1 599 | 85T)FCP 600 | 4H6)LPT 601 | CH4)F8G 602 | BB7)RZF 603 | JHK)T6Z 604 | SHR)LTB 605 | HK9)JB4 606 | 6QQ)TQY 607 | 5WX)KQT 608 | 7G9)L8H 609 | 4T5)CNT 610 | T3D)92P 611 | 7NQ)77J 612 | DDR)8M3 613 | DBK)X9G 614 | CGQ)9J8 615 | G5L)3WM 616 | YVS)M6X 617 | SG7)JK2 618 | CK5)V1D 619 | NQS)26M 620 | C32)TXD 621 | 51G)FKP 622 | X8T)5BF 623 | XW8)6LJ 624 | CBZ)87T 625 | Q5J)NGW 626 | 3YD)VGM 627 | WR1)C1Y 628 | 2MS)H6G 629 | JK2)9R1 630 | YM7)21W 631 | W32)6WP 632 | 4T5)CV6 633 | CW6)D2P 634 | DSX)7XM 635 | YDG)7ZB 636 | T13)Z3T 637 | P67)2JF 638 | XGK)SX6 639 | NFB)DCW 640 | KN8)KZH 641 | TXL)14F 642 | KD5)HGP 643 | 2VD)S9X 644 | TQV)D81 645 | TRM)75P 646 | PXS)T13 647 | BH8)HJW 648 | 48P)2CJ 649 | H2J)RLX 650 | XYQ)NGS 651 | FKP)14X 652 | SK7)7PM 653 | LVS)D56 654 | DT2)J24 655 | 439)M5S 656 | 4Z7)4ZK 657 | HGG)7MR 658 | VC3)6QQ 659 | 3W9)DDZ 660 | 842)YWT 661 | PHH)RV3 662 | B3V)JVF 663 | 7C8)WHS 664 | 9TT)61C 665 | ZNM)RTD 666 | 48Y)6S7 667 | PRW)HV6 668 | LC1)HTV 669 | 75P)34F 670 | MPH)MTL 671 | 2X4)4H6 672 | F8G)N6V 673 | VC3)WRP 674 | MLR)SKV 675 | 7WH)1GY 676 | CZC)NFB 677 | 9SN)DL8 678 | COM)HXD 679 | XZV)9SS 680 | YTG)4RD 681 | 6SQ)MFL 682 | 3GM)K9M 683 | 1N1)4XN 684 | PS3)FW3 685 | HK3)CGQ 686 | N7G)ZWL 687 | 28S)NRN 688 | GNR)BXQ 689 | DKH)LSR 690 | Z69)T6X 691 | M74)1ZN 692 | J3T)MLR 693 | SH8)1ZQ 694 | L1Z)WVC 695 | CXL)M49 696 | GGP)BWN 697 | 7MR)NX2 698 | 1GY)6SQ 699 | KQH)HKY 700 | LL9)V15 701 | TNS)HZF 702 | Y6X)6YD 703 | 9VN)TNS 704 | K3T)YDG 705 | 48P)XRY 706 | G7L)5FS 707 | HV6)7S2 708 | 7H8)SF4 709 | 4RC)MBZ 710 | BH8)48P 711 | K3N)7QF 712 | YM7)FT5 713 | 1T9)M87 714 | PYL)DJ2 715 | Y14)9VN 716 | 12B)LF7 717 | C9Q)48Y 718 | X9V)T9R 719 | MPV)ZKH 720 | MDQ)2X4 721 | GVY)XGK 722 | G4D)8ZH 723 | T47)4PZ 724 | M49)MGY 725 | RN1)V3N 726 | 8KZ)K3N 727 | 211)TRM 728 | 69K)BP2 729 | 7LK)PS3 730 | NX2)6H1 731 | D5R)GJP 732 | S9X)PJ7 733 | D1X)Y6X 734 | GZC)19D 735 | 8M3)QQN 736 | YNN)PR5 737 | 33Q)5QH 738 | YK2)GVG 739 | 4JJ)751 740 | GSS)5G5 741 | MKF)KNV 742 | 3WM)VQH 743 | QSX)VPC 744 | FLS)MKY 745 | MKF)4RZ 746 | 33Z)BXV 747 | CC5)FPN 748 | RJT)28R 749 | YD5)TVW 750 | H2K)HF1 751 | TKZ)1SZ 752 | Z4Y)JBF 753 | X76)FJW 754 | VT4)4YN 755 | Q44)M7H 756 | L71)M24 757 | RBN)CS1 758 | DLL)M81 759 | DDZ)G8K 760 | 1ZN)Z4Y 761 | KK9)8CH 762 | TZR)JV4 763 | 9Z4)GY3 764 | 596)BB7 765 | WG5)JYP 766 | RDH)VMD 767 | JNB)C5K 768 | XF4)GGP 769 | SKV)NJS 770 | FBN)71F 771 | 9J8)1KP 772 | NBL)9Z4 773 | 6Z2)L8W 774 | 16Y)N26 775 | DC8)4WT 776 | FT8)4JW 777 | 97D)8LY 778 | NDH)QSN 779 | VQH)LR9 780 | PMX)3Y2 781 | T3Q)Q46 782 | M6G)XSB 783 | 8LK)51G 784 | J12)T7D 785 | FHX)XVM 786 | 77J)5HS 787 | 9WM)RQB 788 | HKP)CSK 789 | CGH)RBZ 790 | 9TL)QSX 791 | KCC)H7C 792 | SDJ)SWG 793 | SY4)YF8 794 | 2FV)C9W 795 | Z2L)PRW 796 | W7R)WZ6 797 | 72C)STQ 798 | YRN)B4P 799 | 1PM)8B6 800 | T6Z)C93 801 | CRC)XZV 802 | 8MQ)RJT 803 | J3F)CGS 804 | 238)8N9 805 | 19X)JN8 806 | QXH)ZXK 807 | 6P7)X3M 808 | ZKK)RBN 809 | P2V)DLL 810 | J32)3J3 811 | NJS)8P1 812 | 6WP)MGZ 813 | NW8)B3V 814 | 9J8)Q5J 815 | FKP)TQV 816 | P99)C3Q 817 | M28)KS4 818 | 98N)9WM 819 | CJ9)R5K 820 | DCX)J12 821 | 2V5)QXD 822 | JTY)SXT 823 | HW5)XPP 824 | 2VY)W35 825 | 1KP)G2Y 826 | 747)1DQ 827 | BR6)CGH 828 | J7T)MFX 829 | FJW)HLY 830 | MGV)4T5 831 | PMC)TKZ 832 | S1M)7B9 833 | KXK)5W2 834 | GZV)DLW 835 | YF8)72C 836 | 1L8)7FL 837 | JB4)98B 838 | DCW)W63 839 | D31)DTG 840 | CRS)ZXJ 841 | D56)CJ9 842 | 43B)WJG 843 | WTG)YZ3 844 | KPT)2V5 845 | G2Y)HFN 846 | R9Z)3K4 847 | 7KN)51S 848 | JN8)NC9 849 | 2JH)697 850 | 55T)73L 851 | 3R1)5WX 852 | 5SB)GVY 853 | CX9)YNN 854 | P38)CZC 855 | 1PW)SN6 856 | 2JF)G9T 857 | QRW)9MD 858 | LVF)MGV 859 | RFM)NDH 860 | -------------------------------------------------------------------------------- /inputs/input07.txt: -------------------------------------------------------------------------------- 1 | 3,8,1001,8,10,8,105,1,0,0,21,34,55,68,93,106,187,268,349,430,99999,3,9,102,5,9,9,1001,9,2,9,4,9,99,3,9,1001,9,5,9,102,2,9,9,101,2,9,9,102,2,9,9,4,9,99,3,9,101,2,9,9,102,4,9,9,4,9,99,3,9,101,4,9,9,102,3,9,9,1001,9,2,9,102,4,9,9,1001,9,2,9,4,9,99,3,9,101,2,9,9,1002,9,5,9,4,9,99,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,1,9,9,4,9,99,3,9,101,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,1001,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,2,9,9,4,9,99,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,99,3,9,101,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,1,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,99 2 | -------------------------------------------------------------------------------- /inputs/input08.txt: -------------------------------------------------------------------------------- 1 | 222222022022222222222022222222122122222212222122222022212222202222222221222122221022222222202022220222222222222020222222002222222222222200222222202220222222222022222222222122222222022022222202222222222122212222202222222200222122222022222222222222222222222222222222222222222222222222222201222222222222022222222022222212222122222022122222222212222122222222212222202222222220222122221222222222222022222222222222222110222222022222222222222221222222222220222222022122222202222222222222022122222212222122222122202222202222222200222222220022222222222122222222222222222010222222212222222222222210222222212221122222222122222212222222222222022222222202222120222222212222212222222200222222220122222222222222221222222222222212222222022222222222222202222222222222122222122022222212222222222122122122222212222222222222212222222222222212222222222222222222222122221222222222222102222222112222222222222211222222202220122222022222222222222222222222222022222212222021222122202222202222222200222222220222222222202122220222222222222202222222222222222222222220222222212220222222022222222212222022222022122222222202222022222222222222202222222202222122222122222222222022222222222222222022222222212222022222222201122222212220122222222122222212222222222122222122222202222022222122212222212222222221222022222222222222212222222222222222222201222222202222222222222211122222222220222202122022222222222022222022222122222212222020222222222222212222222220222122220122222222202122221222222222222212222222222222022222222211122222212220022212022122222212222222212022122022222222222120222022212222202222222211212222221222222222212222220222222222222120222222002222022222222201022222212200222202022222222222222222222022022122222202222022222022202222212222222210212022221022222222202222221222222222222210222222022222122022222200022222212201222202222022222212222102202022122222222222222221222022202222202222222211202022222222222222202222221222222222222101222222212222122022222221122222202222022212122022222222222002212022022222222222222022222222202222202122222022222122221222212222202122222222222222222000222022002222222022222202122222212222122202222122222222222212202022022122202212222000222122222222212022222002222022220022202222202022221222222222222021222122222222222022202222122222212210222202222222222212222002202022022122212212222001222122222222222222222121202222222122202222222122222222222222222212222022102222022222222222022222202222222222022022222202222212222122022122222222222011222021212222222222222212212122221122212222202022222222222222222120222222002222122122222200222222222221022212022222222202222022222022222222212212222212222222212222212222222021222122221122202222222022220222212222222221222222122222222222212212222222212211022222222122222202222202222122122122202212222001222122202222212222222120202022220222212222222122221222202222222011222122102222122222212210222222212212122222222222222202222222202122122222222212220220222022222212222022222022222122221222202222222222222222212222222122222022112222222022222222222222222222222222222222222202222222212222122022202222221122212020212212222122222101222022221222212222202022220222212222222022222122112222222222212210122222212222222222122222222212222222212022022122212212220101222220220212212022222001222022222022222222222122222222212222222001222222122222222222202210022222202211122222022222222202222212202222022022222202220012212120222202222122222222212122221122202222222222222222222222222101222222212222022022222221222222202221122202022222222212222212202022022222212222220212212121220212212022222200202122221022222222202022222222202222222201222022102222022122222202022212212222022222122122222222222212222022122022212222222222202122222222222022222022202022220122212222202222221220212222222200222222212222222022222200022210212212122202122122222212222012202122022022212212221211202222202222202122222221222022222022212222222022220222212222222120222222122222222122202200122220212221222202222022222212222222212122022122222202220221202120210202222022222000222222222122212222212022221222212222222010222222002222022022212200222200222200122212122222222222222002222022222022212202220022212221201202222122222121222022220022212222202022220220222222222012222222202222222122212212122212212210022222122022222212222002222022022022212222221021212220221222202022222112222222221022222222212122212221222222222021222020202222222222222201022211212212022222022022222212222102222022222222222212221000222021212202202222222200222022221022202222222022221220222222222110022122212222022222202222222221212222022202222022222202222102222022022122202222221200212122212222222022222210202022220222202222222122221221212222222022022121122222222222212211022210202200222212022222222212222102222122122222222222221111222022201202212222222211222222222222222222212122222220212222222000222022202222222222202220122211202201222202122122222202222222202222022022222212221022202020222202222022222011212122221122212222202122201221202222222121022020102222122022212221122222202211122222022022222222222002222222022022202222221221212002211222222022222022212222222022222222202022212221202222222201122122022222222022212201122220202202022202022122222222222112222022022122212222222102222000211212202122222111202222220122212222222122221221202222222010222120212222022222212211122211212201022212122122222222222112222222022122212202222000222002201202222022220002212222221222222222222022211221212222202202122022212222222122212212122222222202222212022212222222222202222122022122202222222010212002220212222022220211222122222022202222222122212221222222222121122222102222122022202222022202202201222212222122222212222212222022022122222212221221202021212212202022221000222222221122212222212022220220222222212211222022012222122222212210122201222200022222122102222222222002212122222022212202222022202220221202212121221022212122221022202222212022220222202222212021022122112222022122220212122202222210022221222212222212222212202022222122222212222021212011212202212020220110222222222122212222212222212222202222212221222121012222022222220212222211212221122222222222222222222002222222122122222212220120222020201212222121221121202022222122222222202222210221202220222012222021022222022122201200222201222212022212022102222202222022202022022221212202220122222220210202212021221002222222221122222222212222222222222222202212122222112222022122202200022210212202222200122122222212222002212122122020222202210210212002211222222021221022212022222022202222212222202220222221222001222120212222022222221210222222222222222210022112222212222002212022022121222222222100212110202212212121222022202022221122202222202022210220202221212021122220222222022222211200022202202222022201122202222222222202212222022122222202202122212102210202202121222200202022220122202222212222222221222221212112122122212222022122212220222210222212122200222122220202222222202222122022202222200110222020212212212121222022212222220102222222212222201220222221222020022021022222222222210212122210212122222222022202222212222002202222022222202222200010202000220202222121220122202022221022212222222222211222212222222201022221112222022122222212222212212122122220022212221202222102112222122221212222200111212012212202202221220110212122220002212222202122202221212222212002022222222222222222222220122101202020022200122222221202222212222222022120222222222001212012211202222021222001222222221112222222202222222221212220202101122020012222022122221222222210202100022220222112222222222112102122022121212202220001212002221202222221220220212122222212212222212122212221222222222002122220002222122222222210122000202211022220122222221212222212202022122022222202201210202000212222212220221211212122222212222222222122012221202220222210022220122222022222200201122110222020022210022122221222222022212122122020212222200000222201220202202121221121202112222122212222202222102021202220212212222021102222222222211220022121222002022211222222221222222222122222122220212222210121222200202212202020220202222012220202222222202022012120212220222221222220212222122122210221222211222111122212122112220202222102002022022020202212210200212010221212212120220200212122220122202222212122102020222220202121222220012222022122221211222101212112122221022102222222222102202122222222212222202202212020210212222220221100202012222112212222222022112121222222212220022021012222122122211212222200212112222220222222220222222112122022022020212222220221222100201222202122222021222122222202212222222122002220202221202211122121212222222022210211022012202001022222122212221222222212222122222120212202202122212001210212222222222121212122221112222222212222112222212222212011022020002222122122210102222001202111022222022202221222222222122022122121202202212021212212200222222122220011202002222002012222222222111222212221202010022120002222122022221100222212212210122201122122220212222112112222222020222202220110222121211202212120221111202012220222202222212122121020212221202111022020002222222222220202022022212011122200222112220222222002202022022122212222211102222000212202212121220101202002221202012222222022102221202220202010122021002222122221201121022122222200222221122122220222222122122222022120202212220120222222212202222222221011222102120102202222222222212020212220212002222220202222102022210202122220212002122200122202222222222222202122022121212202211001222010202220212222222211202202122122222222222122212020222220202200222220102222022020222022122220212101122202122002222212222020002022022120202202211122222122201201212221221200222202222102012222212120021020202220202102122021121222112121122122122112222000222201222122222212222201202222022221222212222121212001201201122121021210222212120002222222202122010020222221222111122020111222022022222202222020202122222221122122221202222120212222122021212212220001202100210210212222020222212212201102112222212220200221202221222210122120202022012021222220222112202020122220022202222222222120122122122220222222201022202002002212222022221120222202220012212222212121202021222221212111022220112022122220001112122101202122022220022202222212222021222222022121212222202111212201001212002021221221222022222112112222202222120121222120222000022221021122102020002112222012212120122211022022221202222012202022222220222212202000222102212200202021022112222022102012102222222221021220222021202120022121011222011121210111222220202120022200122102221212222200102122222122202212211122212201010210022221121200222222202212202222212220121020202021222212022021222122101221021011022010222010122200221022222222222022012122022022202222222200212100010222022120021111212102221202112222212121121022212121212022122221111122221220000202122012202121222200022222220202222022012022222020202212200212202002112200102022220201202112012202012222212220221022222122202002022022212122202122210011122122222201222220021002222202222001012222022021222222202001212222201220222220121112212022010212022222222121200120212122222001122121101022102022212011222122202110022221020212222222222212202122122220212212200220222101102221012120022002222012200202122222202120002221212020222210122121002222221122010202022100202010122201022112222212222100002022222122022212202021202022022212112020022111222222000202012222212022122120202122212101222022102022001220020210222110212010122220222112220202222212112222122120102212202121202002100210212222121122202102022202122222222220020122222220212022222220210122022022120022022111212221122202221222222222222111112022222021122202201200202020222211122222122211222022010012222222222022201120202221212210022120000222211020000011022101212111022200221112222222222020222122122220022202221200222010111222212021022210202102012112122222212121001021202221202010122121002122020021012121222112222202022202122202222202222210222222022020022212201201202220222200112221022122202012212212012202222120221120202222102201022121210222100220101211122221222022222202122122221222202002022022122222212202220111202002222210012002222202212222100022102202202222220120202220122021022020102022120120002212222210202120122001221102220222212210212222022121112200211210202102010210102111122120202112120112122202212120001222222221022201222121021222101022212112222102202021022220122122201212212112112222022120102202201212212020000211102101121222202112022212212212222221001221220122212220022020000222100122221202222020202100022002222202212212212212212122222020002200220210222121212200212201220010222122001112112222112022220221221021122212122122010222100220120101022102212012222102121122202202222120122122122021002212212100202010010220212212020022202122221002202202202020012121212021212211222021201222001122201110022020212211022100121212201222202022012122122121111220220211212201012010222011020110222222002102122212112120201120222022202012022221120222010121102222122010220002122010222012221012212000022222122220112200201101222201111022122121120120222102111112102202000022012121211022112212022121212222221120001022122200212211222102222122211112202002222222122122112211211122212201000201002220021002212212110002112212122021012020221020112110122122211022120021101010222210210111022021020122220002222002102022222220111221220202222121101111012010220020212222111012202202110121100121202120212021222122020022110021212012022112202220022102220112210122222210122122222122002200212120212112101221002202221212212012111212222212221022220221220021202222122120200222010021102221200002222211122111122222210002212121012022122021121221200022202221010212022222122100212012121022002212210021110020202122212021222122210022210121200112220012200201122000021202201222202112210022122021120222211222202101211201002002222011212212011202122202102221121222210022002020022020000222222221122001010221211112222222222002200122222010022222222120202200012221212210122012202200222222212012012212102212221021102221201020202001122221221022222020120110102102220221122011221222202212222120220022022122010212222102222111120221002000020022202212012102022222200121200220220020202022122022100022111020012111121012202121022112022202211002202002200022000021222210122111222220100220202021021221222102210022012222200021011022202021222112022122001122120121002222121201210101122210220202202001202010120122000222021211011021202100110002212020220121202201212212002212110020210222210022012022022020211022010122011101121220211000122102120102222201211010202222202220100212121110202220101001102202221202202212122002112212000122120121201022012110222121022222211021002221110120202212022210020102200222222112020222122222101221211210212122001021122121220201202200212102012102020020221121210020002011112020210022022020121111210222210210222000200112220022210100212212210020100201121101222220112122022010221220212210011212102202100020110222200220222122122221010122122000000220211200201010022012022022212022210012020222200021201201000211202121122011022120122120222022221112222222111120202021220021012100122220202122122200221002001001222000022122001202210122021200001102202020122200122012222012212122222201020110202020020222022202020121222120202101002210022120102122021011111210012102220211211021220111102002021022200220100001220002111011001020010012210012202222020011210011121010211002000012001021201002200012221001101122020211100010020112 2 | -------------------------------------------------------------------------------- /inputs/input09.txt: -------------------------------------------------------------------------------- 1 | 1102,34463338,34463338,63,1007,63,34463338,63,1005,63,53,1101,3,0,1000,109,988,209,12,9,1000,209,6,209,3,203,0,1008,1000,1,63,1005,63,65,1008,1000,2,63,1005,63,904,1008,1000,0,63,1005,63,58,4,25,104,0,99,4,0,104,0,99,4,17,104,0,99,0,0,1101,37,0,1013,1101,426,0,1027,1101,36,0,1000,1101,0,606,1023,1102,34,1,1011,1102,1,712,1029,1102,1,27,1007,1101,831,0,1024,1102,32,1,1002,1102,1,1,1021,1101,429,0,1026,1102,1,826,1025,1101,0,717,1028,1102,1,20,1018,1101,0,24,1004,1102,31,1,1009,1101,22,0,1015,1102,38,1,1014,1102,613,1,1022,1102,29,1,1017,1102,0,1,1020,1102,1,21,1008,1102,33,1,1012,1101,0,30,1006,1101,0,28,1016,1102,1,26,1005,1102,35,1,1019,1101,25,0,1003,1102,1,23,1001,1102,1,39,1010,109,-3,2102,1,5,63,1008,63,34,63,1005,63,205,1001,64,1,64,1106,0,207,4,187,1002,64,2,64,109,-2,1201,7,0,63,1008,63,34,63,1005,63,227,1105,1,233,4,213,1001,64,1,64,1002,64,2,64,109,21,21102,40,1,3,1008,1019,37,63,1005,63,257,1001,64,1,64,1106,0,259,4,239,1002,64,2,64,109,-4,21101,41,0,2,1008,1014,38,63,1005,63,279,1105,1,285,4,265,1001,64,1,64,1002,64,2,64,109,-10,1201,4,0,63,1008,63,30,63,1005,63,307,4,291,1105,1,311,1001,64,1,64,1002,64,2,64,109,6,1207,0,22,63,1005,63,329,4,317,1105,1,333,1001,64,1,64,1002,64,2,64,109,-5,1207,5,20,63,1005,63,353,1001,64,1,64,1106,0,355,4,339,1002,64,2,64,109,8,2108,29,-5,63,1005,63,375,1001,64,1,64,1105,1,377,4,361,1002,64,2,64,109,15,1206,-6,395,4,383,1001,64,1,64,1105,1,395,1002,64,2,64,109,-11,21107,42,43,4,1005,1019,413,4,401,1106,0,417,1001,64,1,64,1002,64,2,64,109,6,2106,0,6,1105,1,435,4,423,1001,64,1,64,1002,64,2,64,109,-15,1208,-3,24,63,1005,63,455,1001,64,1,64,1105,1,457,4,441,1002,64,2,64,109,-13,1208,10,25,63,1005,63,475,4,463,1106,0,479,1001,64,1,64,1002,64,2,64,109,21,21108,43,42,3,1005,1017,495,1106,0,501,4,485,1001,64,1,64,1002,64,2,64,109,-14,2107,31,2,63,1005,63,519,4,507,1106,0,523,1001,64,1,64,1002,64,2,64,109,-4,1202,8,1,63,1008,63,24,63,1005,63,549,4,529,1001,64,1,64,1105,1,549,1002,64,2,64,109,1,2108,23,4,63,1005,63,567,4,555,1105,1,571,1001,64,1,64,1002,64,2,64,109,2,2101,0,5,63,1008,63,21,63,1005,63,591,1105,1,597,4,577,1001,64,1,64,1002,64,2,64,109,28,2105,1,-4,1001,64,1,64,1105,1,615,4,603,1002,64,2,64,109,-10,1205,4,633,4,621,1001,64,1,64,1106,0,633,1002,64,2,64,109,2,1206,2,645,1106,0,651,4,639,1001,64,1,64,1002,64,2,64,109,-4,1202,-6,1,63,1008,63,28,63,1005,63,671,1105,1,677,4,657,1001,64,1,64,1002,64,2,64,109,-9,21102,44,1,4,1008,1010,44,63,1005,63,699,4,683,1105,1,703,1001,64,1,64,1002,64,2,64,109,31,2106,0,-9,4,709,1105,1,721,1001,64,1,64,1002,64,2,64,109,-30,21108,45,45,6,1005,1013,743,4,727,1001,64,1,64,1106,0,743,1002,64,2,64,109,2,21101,46,0,3,1008,1012,46,63,1005,63,765,4,749,1106,0,769,1001,64,1,64,1002,64,2,64,109,-5,2101,0,0,63,1008,63,24,63,1005,63,795,4,775,1001,64,1,64,1105,1,795,1002,64,2,64,109,6,2107,32,-1,63,1005,63,815,1001,64,1,64,1106,0,817,4,801,1002,64,2,64,109,19,2105,1,-5,4,823,1106,0,835,1001,64,1,64,1002,64,2,64,109,-12,21107,47,46,-1,1005,1016,851,1105,1,857,4,841,1001,64,1,64,1002,64,2,64,109,-2,1205,5,873,1001,64,1,64,1105,1,875,4,863,1002,64,2,64,109,-6,2102,1,-8,63,1008,63,23,63,1005,63,897,4,881,1105,1,901,1001,64,1,64,4,64,99,21101,0,27,1,21101,0,915,0,1106,0,922,21201,1,44808,1,204,1,99,109,3,1207,-2,3,63,1005,63,964,21201,-2,-1,1,21101,942,0,0,1105,1,922,21201,1,0,-1,21201,-2,-3,1,21102,957,1,0,1105,1,922,22201,1,-1,-2,1106,0,968,21202,-2,1,-2,109,-3,2105,1,0 2 | -------------------------------------------------------------------------------- /inputs/input10.txt: -------------------------------------------------------------------------------- 1 | ...###.#########.#### 2 | .######.###.###.##... 3 | ####.########.#####.# 4 | ########.####.##.###. 5 | ####..#.####.#.#.##.. 6 | #.################.## 7 | ..######.##.##.#####. 8 | #.####.#####.###.#.## 9 | #####.#########.##### 10 | #####.##..##..#.##### 11 | ##.######....######## 12 | .#######.#.#########. 13 | .#.##.#.#.#.##.###.## 14 | ######...####.#.#.### 15 | ###############.#.### 16 | #.#####.##..###.##.#. 17 | ##..##..###.#.####### 18 | #..#..########.#.##.. 19 | #.#.######.##.##...## 20 | .#.##.#####.#..#####. 21 | #.#.##########..#.##. 22 | -------------------------------------------------------------------------------- /inputs/input11.txt: -------------------------------------------------------------------------------- 1 | 3,8,1005,8,310,1106,0,11,0,0,0,104,1,104,0,3,8,1002,8,-1,10,101,1,10,10,4,10,1008,8,0,10,4,10,1001,8,0,29,1,2,11,10,1,1101,2,10,2,1008,18,10,2,106,3,10,3,8,1002,8,-1,10,1001,10,1,10,4,10,1008,8,1,10,4,10,102,1,8,67,2,105,15,10,3,8,1002,8,-1,10,101,1,10,10,4,10,1008,8,0,10,4,10,1001,8,0,93,2,1001,16,10,3,8,102,-1,8,10,1001,10,1,10,4,10,1008,8,1,10,4,10,102,1,8,119,3,8,1002,8,-1,10,1001,10,1,10,4,10,1008,8,1,10,4,10,101,0,8,141,2,7,17,10,1,1103,16,10,3,8,1002,8,-1,10,101,1,10,10,4,10,108,0,8,10,4,10,102,1,8,170,3,8,1002,8,-1,10,1001,10,1,10,4,10,1008,8,1,10,4,10,1002,8,1,193,1,7,15,10,2,105,13,10,1006,0,92,1006,0,99,3,8,1002,8,-1,10,101,1,10,10,4,10,108,1,8,10,4,10,101,0,8,228,1,3,11,10,1006,0,14,1006,0,71,3,8,1002,8,-1,10,101,1,10,10,4,10,1008,8,0,10,4,10,101,0,8,261,2,2,2,10,1006,0,4,3,8,102,-1,8,10,101,1,10,10,4,10,108,0,8,10,4,10,101,0,8,289,101,1,9,9,1007,9,1049,10,1005,10,15,99,109,632,104,0,104,1,21101,0,387240009756,1,21101,327,0,0,1105,1,431,21101,0,387239486208,1,21102,1,338,0,1106,0,431,3,10,104,0,104,1,3,10,104,0,104,0,3,10,104,0,104,1,3,10,104,0,104,1,3,10,104,0,104,0,3,10,104,0,104,1,21102,3224472579,1,1,21101,0,385,0,1106,0,431,21101,0,206253952003,1,21102,396,1,0,1105,1,431,3,10,104,0,104,0,3,10,104,0,104,0,21102,709052072296,1,1,21102,419,1,0,1105,1,431,21102,1,709051962212,1,21102,430,1,0,1106,0,431,99,109,2,21202,-1,1,1,21102,1,40,2,21102,462,1,3,21102,452,1,0,1105,1,495,109,-2,2105,1,0,0,1,0,0,1,109,2,3,10,204,-1,1001,457,458,473,4,0,1001,457,1,457,108,4,457,10,1006,10,489,1101,0,0,457,109,-2,2105,1,0,0,109,4,2102,1,-1,494,1207,-3,0,10,1006,10,512,21101,0,0,-3,22101,0,-3,1,21202,-2,1,2,21102,1,1,3,21101,531,0,0,1105,1,536,109,-4,2106,0,0,109,5,1207,-3,1,10,1006,10,559,2207,-4,-2,10,1006,10,559,21202,-4,1,-4,1105,1,627,22102,1,-4,1,21201,-3,-1,2,21202,-2,2,3,21102,1,578,0,1105,1,536,21202,1,1,-4,21102,1,1,-1,2207,-4,-2,10,1006,10,597,21101,0,0,-1,22202,-2,-1,-2,2107,0,-3,10,1006,10,619,21201,-1,0,1,21102,1,619,0,106,0,494,21202,-2,-1,-2,22201,-4,-2,-4,109,-5,2106,0,0 2 | -------------------------------------------------------------------------------- /inputs/input12.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /inputs/input13.txt: -------------------------------------------------------------------------------- 1 | 1,380,379,385,1008,2799,144351,381,1005,381,12,99,109,2800,1102,0,1,383,1101,0,0,382,21001,382,0,1,21001,383,0,2,21102,37,1,0,1106,0,578,4,382,4,383,204,1,1001,382,1,382,1007,382,45,381,1005,381,22,1001,383,1,383,1007,383,24,381,1005,381,18,1006,385,69,99,104,-1,104,0,4,386,3,384,1007,384,0,381,1005,381,94,107,0,384,381,1005,381,108,1105,1,161,107,1,392,381,1006,381,161,1102,1,-1,384,1105,1,119,1007,392,43,381,1006,381,161,1101,0,1,384,20102,1,392,1,21102,1,22,2,21102,0,1,3,21101,0,138,0,1106,0,549,1,392,384,392,20102,1,392,1,21102,1,22,2,21102,3,1,3,21102,161,1,0,1105,1,549,1102,1,0,384,20001,388,390,1,20102,1,389,2,21102,180,1,0,1105,1,578,1206,1,213,1208,1,2,381,1006,381,205,20001,388,390,1,20101,0,389,2,21102,205,1,0,1105,1,393,1002,390,-1,390,1101,1,0,384,21002,388,1,1,20001,389,391,2,21101,228,0,0,1106,0,578,1206,1,261,1208,1,2,381,1006,381,253,20101,0,388,1,20001,389,391,2,21101,253,0,0,1105,1,393,1002,391,-1,391,1102,1,1,384,1005,384,161,20001,388,390,1,20001,389,391,2,21102,1,279,0,1106,0,578,1206,1,316,1208,1,2,381,1006,381,304,20001,388,390,1,20001,389,391,2,21101,304,0,0,1106,0,393,1002,390,-1,390,1002,391,-1,391,1102,1,1,384,1005,384,161,20101,0,388,1,20101,0,389,2,21102,1,0,3,21101,0,338,0,1106,0,549,1,388,390,388,1,389,391,389,20101,0,388,1,21002,389,1,2,21101,4,0,3,21101,365,0,0,1105,1,549,1007,389,23,381,1005,381,75,104,-1,104,0,104,0,99,0,1,0,0,0,0,0,0,462,20,19,1,1,22,109,3,21202,-2,1,1,21201,-1,0,2,21102,0,1,3,21101,414,0,0,1106,0,549,22102,1,-2,1,21201,-1,0,2,21102,1,429,0,1105,1,601,2101,0,1,435,1,386,0,386,104,-1,104,0,4,386,1001,387,-1,387,1005,387,451,99,109,-3,2105,1,0,109,8,22202,-7,-6,-3,22201,-3,-5,-3,21202,-4,64,-2,2207,-3,-2,381,1005,381,492,21202,-2,-1,-1,22201,-3,-1,-3,2207,-3,-2,381,1006,381,481,21202,-4,8,-2,2207,-3,-2,381,1005,381,518,21202,-2,-1,-1,22201,-3,-1,-3,2207,-3,-2,381,1006,381,507,2207,-3,-4,381,1005,381,540,21202,-4,-1,-1,22201,-3,-1,-3,2207,-3,-4,381,1006,381,529,21202,-3,1,-7,109,-8,2105,1,0,109,4,1202,-2,45,566,201,-3,566,566,101,639,566,566,1202,-1,1,0,204,-3,204,-2,204,-1,109,-4,2106,0,0,109,3,1202,-1,45,594,201,-2,594,594,101,639,594,594,20101,0,0,-2,109,-3,2105,1,0,109,3,22102,24,-2,1,22201,1,-1,1,21102,1,547,2,21102,1,67,3,21101,1080,0,4,21102,1,630,0,1105,1,456,21201,1,1719,-2,109,-3,2106,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,2,2,0,2,2,2,2,2,0,2,0,0,2,0,2,2,2,0,2,2,2,2,0,2,2,2,2,0,2,2,2,0,2,0,0,2,2,2,0,0,1,1,0,2,0,2,2,2,2,0,0,2,2,0,0,2,2,0,2,2,2,2,0,2,2,2,2,0,0,0,2,2,2,0,2,0,2,2,2,2,2,2,2,0,0,1,1,0,0,0,2,2,2,2,0,0,0,2,0,0,2,2,2,2,2,2,2,2,0,0,2,0,0,0,2,2,2,2,2,0,2,2,0,0,2,2,0,2,2,0,1,1,0,2,2,0,2,2,0,0,0,2,0,2,2,0,2,0,2,2,2,2,2,0,0,2,2,2,0,2,0,0,2,2,0,2,0,2,0,2,2,2,2,2,0,1,1,0,2,0,0,2,2,2,0,0,2,2,0,0,2,2,2,2,2,2,0,2,2,2,2,2,0,2,2,0,2,0,0,2,2,2,2,2,2,2,0,0,2,0,1,1,0,2,0,2,2,2,2,2,2,0,0,2,0,2,2,2,2,0,2,2,2,2,2,2,2,0,2,2,2,0,2,2,2,0,2,0,2,2,2,0,2,2,0,1,1,0,2,2,2,2,2,2,0,2,2,2,2,0,0,2,0,2,0,2,0,0,2,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,1,1,0,2,0,2,2,2,2,2,2,0,2,2,0,2,2,2,2,2,2,2,0,0,0,2,2,0,0,2,2,2,2,0,2,0,2,2,2,2,2,2,2,2,0,1,1,0,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,2,2,2,2,0,2,0,2,0,2,0,2,2,2,2,0,0,2,2,2,2,0,2,2,2,2,0,1,1,0,2,2,0,2,2,0,0,2,2,2,2,2,2,2,2,2,0,2,2,0,2,0,2,2,0,2,2,2,2,2,2,0,0,2,2,2,2,2,0,2,0,0,1,1,0,0,2,2,0,2,0,2,2,2,2,2,0,0,0,2,2,2,0,0,2,2,2,2,2,2,0,2,2,2,0,2,2,0,0,2,2,2,2,0,2,0,0,1,1,0,0,2,2,2,0,2,2,0,2,2,2,0,2,2,2,2,0,0,2,2,2,2,2,2,2,2,2,0,2,2,0,2,2,0,2,2,2,0,2,2,2,0,1,1,0,2,2,2,0,2,2,2,2,2,2,2,0,2,0,2,0,2,2,2,2,2,2,2,0,0,0,0,2,2,2,2,0,0,2,2,2,2,2,2,2,2,0,1,1,0,2,2,0,0,0,0,2,2,2,2,2,0,2,2,2,0,0,0,2,2,0,2,2,0,0,0,2,2,2,0,2,2,2,2,2,2,2,2,2,2,2,0,1,1,0,0,2,2,2,0,0,2,2,0,2,0,2,2,2,0,0,2,2,0,2,0,0,0,2,0,0,2,0,2,2,2,0,0,2,2,0,2,2,2,2,2,0,1,1,0,0,2,2,2,0,0,2,2,0,0,0,2,0,2,2,0,2,0,2,2,2,2,2,2,2,2,2,2,0,2,2,0,2,2,2,0,2,2,2,2,2,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,9,39,41,83,13,97,81,2,94,70,54,80,64,53,86,83,73,14,8,90,38,79,87,81,5,14,43,32,46,39,20,18,47,85,63,71,38,16,83,50,21,69,67,20,94,57,26,11,65,31,41,24,60,79,15,34,87,60,81,76,46,90,47,31,33,98,10,70,60,94,50,41,27,24,34,12,17,91,45,97,40,89,36,47,94,47,40,58,44,50,27,57,4,86,45,93,75,55,57,34,98,58,60,31,26,62,92,50,47,71,31,14,19,31,11,11,61,60,41,32,43,3,74,88,14,60,47,98,11,71,76,79,60,14,49,69,5,1,64,43,63,23,59,81,55,96,43,36,80,1,2,94,56,79,66,1,41,27,35,22,64,89,41,77,1,98,13,85,48,55,73,70,56,13,50,73,95,19,15,82,27,74,18,11,90,44,11,25,57,76,15,94,90,85,97,21,67,21,82,17,64,40,11,46,82,73,62,46,82,80,90,1,91,4,3,93,31,3,65,57,14,66,30,25,9,66,69,56,71,25,50,19,57,44,16,34,81,61,95,71,33,97,60,59,43,75,6,30,55,90,69,70,45,37,89,5,9,81,51,28,4,84,21,73,75,53,82,67,36,26,45,82,93,16,17,89,55,20,62,37,39,38,55,71,44,80,28,95,18,83,40,82,46,70,74,70,53,8,92,38,9,29,66,95,24,75,85,20,23,88,71,66,2,39,58,78,44,15,74,52,77,87,2,4,17,18,45,2,71,2,17,86,68,24,6,19,36,12,40,40,79,58,52,53,14,79,48,62,94,9,4,86,8,33,76,62,8,80,81,51,74,49,26,56,12,40,3,32,48,51,74,12,77,73,53,58,82,92,92,9,53,53,11,92,33,73,80,68,93,85,51,95,69,83,74,66,90,90,98,6,96,83,51,16,46,41,87,4,86,90,28,52,54,70,98,26,26,1,74,49,64,56,16,67,50,60,45,61,32,66,19,23,73,20,12,27,71,29,52,61,24,24,92,3,97,84,48,40,23,64,50,25,12,76,25,3,88,31,8,29,87,24,3,2,77,95,8,90,31,71,5,76,41,54,51,2,17,85,23,79,62,80,8,64,31,31,14,83,88,90,29,53,74,80,63,15,61,68,86,17,3,83,87,10,63,9,37,92,23,16,64,66,45,28,92,15,61,34,4,27,72,10,19,96,49,29,87,62,46,97,80,81,52,31,11,5,51,10,75,52,16,97,89,96,21,26,98,14,11,92,66,69,30,60,71,76,38,70,74,88,78,42,42,60,6,69,9,23,59,92,9,72,27,90,55,10,36,56,74,61,95,28,69,57,6,96,36,21,88,22,54,65,13,13,91,64,52,43,45,49,37,80,13,55,78,57,63,88,51,46,13,58,44,23,5,15,14,84,39,94,25,63,93,82,2,90,36,62,1,68,2,54,66,79,34,94,55,44,4,53,39,65,40,41,42,40,89,69,23,43,80,73,7,5,71,14,54,38,46,46,58,89,61,6,49,56,40,35,76,8,69,95,31,34,36,14,91,83,98,76,5,7,68,79,87,85,85,61,79,44,6,20,26,4,27,15,80,62,27,85,3,76,10,48,28,12,48,93,44,36,41,92,67,36,76,58,26,80,40,19,98,68,53,28,19,96,20,39,19,13,60,64,18,12,91,50,7,11,32,31,69,92,39,70,50,42,66,12,38,92,1,27,47,52,59,12,76,2,90,65,80,50,40,54,29,97,87,73,39,80,94,70,81,97,4,98,16,51,31,77,77,34,74,62,30,41,37,40,5,62,74,51,47,58,65,37,60,77,35,32,83,35,36,77,70,17,74,19,97,16,39,58,56,75,3,1,69,4,73,39,52,65,33,62,22,70,25,88,97,76,34,43,80,29,14,89,39,81,12,6,79,90,85,14,31,59,64,59,51,89,34,66,90,95,92,31,16,37,23,7,85,83,91,64,41,89,3,12,32,72,92,94,93,66,59,51,52,69,78,73,45,38,62,20,64,8,21,61,5,62,98,23,46,77,4,73,74,43,2,77,94,75,42,76,91,67,82,40,54,58,86,92,3,51,28,69,78,39,35,7,63,14,2,96,17,53,44,75,20,66,92,67,42,44,58,54,15,40,65,61,75,85,92,74,57,74,11,6,20,33,21,36,7,20,28,89,15,28,15,11,97,9,48,70,94,7,10,72,86,64,23,36,93,55,91,36,44,35,43,10,53,4,34,70,96,41,70,98,7,28,30,9,97,36,89,25,21,77,51,4,19,26,65,56,76,51,56,73,88,56,4,52,89,6,10,26,36,73,32,54,57,92,72,48,74,76,14,19,33,56,70,6,38,20,6,11,55,61,60,52,58,61,88,30,7,86,60,73,72,46,56,73,78,50,58,3,32,45,87,78,64,86,72,73,83,36,56,1,70,98,80,62,38,45,90,13,70,9,28,72,144351 2 | -------------------------------------------------------------------------------- /inputs/input14.txt: -------------------------------------------------------------------------------- 1 | 4 SRWZ, 3 ZGSFW, 1 HVJVQ, 1 RWDSX, 12 BDHX, 1 GDPKF, 23 WFPSM, 1 MPKC => 6 VCWNW 2 | 3 BXVJK, 3 WTPN => 4 GRQC 3 | 5 KWFD => 9 NMZND 4 | 1 DNZQ, 5 CDSP => 3 PFDBV 5 | 4 VSPSC, 34 MPKC, 9 DFNVL => 9 PZWSP 6 | 5 NTXHM => 9 DBKN 7 | 4 JNSP, 4 TCKR, 7 PZWSP => 7 DLHG 8 | 12 CNBS, 3 FNPC => 2 SRWZ 9 | 3 RWDSX, 4 NHSTB, 2 JNSP => 8 TCKR 10 | 24 PGHF, 1 NMZND => 3 RWDSX 11 | 1 DLHG => 9 QSVN 12 | 6 HVJVQ => 2 QSNCW 13 | 4 CHDTJ => 9 FDVNC 14 | 1 HBXF, 1 RWDSX => 7 BWSPN 15 | 2 ZGSFW, 1 KWFD => 8 JNSP 16 | 2 BWSPN, 7 GDPKF, 1 BXVJK => 6 FVQM 17 | 2 MHBH => 6 FNPC 18 | 2 WTPN, 15 GRQC => 3 ZGSFW 19 | 9 LXMLX => 6 CLZT 20 | 5 DFNVL, 1 KHCQ => 4 MHLBR 21 | 21 CNTFK, 3 XHST => 9 CHDTJ 22 | 1 CNTFK => 7 MHBH 23 | 1 GMQDW, 34 GDPKF, 2 ZDGPL, 1 HVJVQ, 13 QSVN, 1 QSNCW, 1 BXVJK => 2 SGLGN 24 | 1 BMVRK, 1 XHST => 8 XHLNT 25 | 23 CXKN => 1 BDKN 26 | 121 ORE => 9 XHST 27 | 4 NTXHM, 4 FNPC, 15 VCMVN => 8 MPKC 28 | 2 ZDGPL, 7 JNSP, 3 FJVMD => 4 GMQDW 29 | 1 LXMLX, 2 BWSPN => 2 DNZQ 30 | 6 WTPN => 9 KCMH 31 | 20 CDSP => 2 VSPSC 32 | 2 QSNCW, 1 BDHX, 3 HBXF, 8 PFDBV, 17 ZDGPL, 1 MHLBR, 9 ZGSFW => 8 FDWSG 33 | 2 VSFTG, 2 DLHG => 9 BDHX 34 | 174 ORE => 5 BMVRK 35 | 2 BMVRK => 2 KWFD 36 | 3 WTPN, 9 TVJPG => 9 CDSP 37 | 191 ORE => 2 CNTFK 38 | 9 FDVNC, 1 MHBH => 8 NTXHM 39 | 3 NHSTB, 2 BXVJK, 1 JNSP => 1 WFPSM 40 | 7 FJVMD => 9 CXKN 41 | 3 GDPKF, 10 QSNCW => 7 ZDGPL 42 | 7 LPXM, 11 VSPSC => 1 LXMLX 43 | 6 RWDSX, 2 NMZND, 1 MPKC => 1 KHCQ 44 | 6 RWDSX => 4 QMJK 45 | 15 MHBH, 28 DBKN, 12 CNBS => 4 PGHF 46 | 20 NMZND, 1 PGHF, 1 BXVJK => 2 LPXM 47 | 1 CDSP, 17 BXVJK => 5 NHSTB 48 | 12 HVJVQ => 3 VSFTG 49 | 2 PGHF, 3 VCMVN, 2 NHSTB => 1 DFNVL 50 | 5 FNPC => 9 HBXF 51 | 3 DPRL => 4 FJVMD 52 | 1 KWFD, 1 TVJPG => 8 VCMVN 53 | 1 FDWSG, 1 VCWNW, 4 BDKN, 14 FDVNC, 1 CLZT, 62 SGLGN, 5 QMJK, 26 ZDGPL, 60 KCMH, 32 FVQM, 15 SRWZ => 1 FUEL 54 | 3 XHLNT => 8 TVJPG 55 | 5 HBXF => 2 HVJVQ 56 | 3 CHDTJ, 15 KWFD => 9 WTPN 57 | 7 CNTFK => 7 CNBS 58 | 1 CNBS => 2 JPDF 59 | 5 JNSP => 8 DPRL 60 | 11 NTXHM => 8 GDPKF 61 | 10 JPDF => 9 BXVJK 62 | -------------------------------------------------------------------------------- /inputs/input15.txt: -------------------------------------------------------------------------------- 1 | 3,1033,1008,1033,1,1032,1005,1032,31,1008,1033,2,1032,1005,1032,58,1008,1033,3,1032,1005,1032,81,1008,1033,4,1032,1005,1032,104,99,101,0,1034,1039,1002,1036,1,1041,1001,1035,-1,1040,1008,1038,0,1043,102,-1,1043,1032,1,1037,1032,1042,1105,1,124,1002,1034,1,1039,101,0,1036,1041,1001,1035,1,1040,1008,1038,0,1043,1,1037,1038,1042,1106,0,124,1001,1034,-1,1039,1008,1036,0,1041,101,0,1035,1040,102,1,1038,1043,1001,1037,0,1042,1105,1,124,1001,1034,1,1039,1008,1036,0,1041,1002,1035,1,1040,1001,1038,0,1043,102,1,1037,1042,1006,1039,217,1006,1040,217,1008,1039,40,1032,1005,1032,217,1008,1040,40,1032,1005,1032,217,1008,1039,5,1032,1006,1032,165,1008,1040,7,1032,1006,1032,165,1101,2,0,1044,1106,0,224,2,1041,1043,1032,1006,1032,179,1102,1,1,1044,1105,1,224,1,1041,1043,1032,1006,1032,217,1,1042,1043,1032,1001,1032,-1,1032,1002,1032,39,1032,1,1032,1039,1032,101,-1,1032,1032,101,252,1032,211,1007,0,31,1044,1106,0,224,1101,0,0,1044,1106,0,224,1006,1044,247,1002,1039,1,1034,101,0,1040,1035,1001,1041,0,1036,102,1,1043,1038,1002,1042,1,1037,4,1044,1105,1,0,9,21,83,15,75,17,11,9,80,22,37,23,19,89,6,29,79,24,75,3,39,3,98,13,20,53,24,30,59,26,13,19,63,84,10,2,57,7,22,43,28,72,11,25,67,17,90,6,10,24,93,76,36,21,34,18,19,15,72,53,18,19,82,8,57,40,18,2,48,71,19,46,26,32,69,29,27,42,8,58,25,17,44,39,47,24,54,32,48,6,26,43,91,4,16,47,45,19,73,3,52,43,25,5,22,73,58,12,56,23,44,7,46,96,48,25,8,16,56,20,48,72,28,44,26,14,23,28,61,29,15,69,86,28,97,6,4,77,4,1,37,55,70,69,22,19,23,78,21,41,2,1,48,29,20,30,22,91,36,15,46,16,83,5,95,38,9,42,84,25,45,3,81,38,79,8,1,78,42,25,58,15,29,48,52,19,36,4,27,43,24,62,6,56,60,22,22,48,23,70,8,83,17,13,63,85,25,13,14,85,79,18,13,63,3,48,94,22,73,18,26,40,68,12,25,10,56,90,59,19,68,25,27,20,20,65,1,22,55,20,1,20,88,24,69,65,13,49,8,5,78,77,1,3,93,9,13,34,17,75,28,13,92,66,35,7,98,3,63,78,59,87,2,80,83,56,15,28,96,25,32,3,27,47,5,73,56,9,59,19,16,60,2,21,50,92,44,19,73,64,7,21,39,19,20,20,63,5,12,6,14,34,12,8,48,12,68,33,14,99,9,85,20,76,18,29,99,52,11,5,98,65,83,15,30,97,35,21,96,4,53,44,23,39,25,53,60,78,85,11,7,4,39,23,84,22,29,56,37,88,18,19,84,4,65,86,8,27,66,24,26,19,95,13,19,61,19,42,85,14,19,29,90,22,15,78,18,90,8,24,21,97,86,15,40,21,61,21,49,61,6,88,40,9,2,38,13,85,16,50,55,93,83,16,77,25,27,91,8,95,15,60,70,63,13,24,24,96,30,8,22,27,74,17,14,92,18,49,4,38,9,33,88,12,62,28,35,77,29,59,3,18,45,5,10,42,58,23,78,72,15,79,2,48,47,14,65,24,5,83,41,11,89,4,57,36,19,12,2,40,21,16,44,36,13,69,70,1,11,51,16,68,30,24,83,26,40,14,82,48,10,5,83,1,76,90,15,44,24,10,88,30,24,78,1,54,97,83,27,46,87,5,19,86,19,48,19,9,50,20,69,17,10,80,34,23,24,18,75,19,20,21,73,11,32,5,15,35,2,77,22,53,18,22,86,6,9,37,30,64,28,77,17,28,12,41,62,59,2,92,97,77,14,3,76,85,11,47,14,85,6,53,2,18,52,29,23,54,35,75,5,97,40,6,45,4,75,64,5,13,86,7,84,84,1,38,23,81,72,5,26,97,70,14,40,9,41,63,41,26,80,57,14,69,90,2,28,95,24,21,80,18,26,33,39,29,11,70,73,69,17,79,13,7,73,6,21,11,75,35,10,23,30,78,75,1,1,73,4,62,30,11,21,6,38,8,40,9,56,3,24,92,66,3,86,61,28,40,17,81,74,58,92,19,4,48,34,39,30,14,36,35,73,12,15,60,49,77,13,53,77,12,20,78,18,34,17,36,17,53,64,7,63,26,20,19,94,16,26,84,13,18,60,47,17,11,56,2,48,53,11,8,79,94,22,14,8,95,7,12,21,77,16,44,4,89,70,96,11,81,8,72,5,35,79,45,1,47,10,86,75,82,5,47,5,65,4,50,22,34,12,84,13,62,80,63,23,45,39,36,0,0,21,21,1,10,1,0,0,0,0,0,0 2 | -------------------------------------------------------------------------------- /inputs/input16.txt: -------------------------------------------------------------------------------- 1 | 59782619540402316074783022180346847593683757122943307667976220344797950034514416918778776585040527955353805734321825495534399127207245390950629733658814914072657145711801385002282630494752854444244301169223921275844497892361271504096167480707096198155369207586705067956112600088460634830206233130995298022405587358756907593027694240400890003211841796487770173357003673931768403098808243977129249867076581200289745279553289300165042557391962340424462139799923966162395369050372874851854914571896058891964384077773019120993386024960845623120768409036628948085303152029722788889436708810209513982988162590896085150414396795104755977641352501522955134675 2 | -------------------------------------------------------------------------------- /inputs/input17.txt: -------------------------------------------------------------------------------- 1 | 1,330,331,332,109,3862,1101,0,1182,15,1101,1465,0,24,1002,0,1,570,1006,570,36,102,1,571,0,1001,570,-1,570,1001,24,1,24,1106,0,18,1008,571,0,571,1001,15,1,15,1008,15,1465,570,1006,570,14,21101,58,0,0,1105,1,786,1006,332,62,99,21102,333,1,1,21101,73,0,0,1105,1,579,1102,0,1,572,1102,0,1,573,3,574,101,1,573,573,1007,574,65,570,1005,570,151,107,67,574,570,1005,570,151,1001,574,-64,574,1002,574,-1,574,1001,572,1,572,1007,572,11,570,1006,570,165,101,1182,572,127,102,1,574,0,3,574,101,1,573,573,1008,574,10,570,1005,570,189,1008,574,44,570,1006,570,158,1105,1,81,21101,340,0,1,1106,0,177,21101,477,0,1,1106,0,177,21101,514,0,1,21102,1,176,0,1105,1,579,99,21102,1,184,0,1106,0,579,4,574,104,10,99,1007,573,22,570,1006,570,165,1002,572,1,1182,21102,1,375,1,21102,211,1,0,1105,1,579,21101,1182,11,1,21101,0,222,0,1105,1,979,21101,0,388,1,21102,233,1,0,1106,0,579,21101,1182,22,1,21101,0,244,0,1106,0,979,21102,1,401,1,21102,255,1,0,1105,1,579,21101,1182,33,1,21102,1,266,0,1106,0,979,21102,1,414,1,21101,0,277,0,1106,0,579,3,575,1008,575,89,570,1008,575,121,575,1,575,570,575,3,574,1008,574,10,570,1006,570,291,104,10,21101,1182,0,1,21102,313,1,0,1105,1,622,1005,575,327,1101,1,0,575,21102,327,1,0,1105,1,786,4,438,99,0,1,1,6,77,97,105,110,58,10,33,10,69,120,112,101,99,116,101,100,32,102,117,110,99,116,105,111,110,32,110,97,109,101,32,98,117,116,32,103,111,116,58,32,0,12,70,117,110,99,116,105,111,110,32,65,58,10,12,70,117,110,99,116,105,111,110,32,66,58,10,12,70,117,110,99,116,105,111,110,32,67,58,10,23,67,111,110,116,105,110,117,111,117,115,32,118,105,100,101,111,32,102,101,101,100,63,10,0,37,10,69,120,112,101,99,116,101,100,32,82,44,32,76,44,32,111,114,32,100,105,115,116,97,110,99,101,32,98,117,116,32,103,111,116,58,32,36,10,69,120,112,101,99,116,101,100,32,99,111,109,109,97,32,111,114,32,110,101,119,108,105,110,101,32,98,117,116,32,103,111,116,58,32,43,10,68,101,102,105,110,105,116,105,111,110,115,32,109,97,121,32,98,101,32,97,116,32,109,111,115,116,32,50,48,32,99,104,97,114,97,99,116,101,114,115,33,10,94,62,118,60,0,1,0,-1,-1,0,1,0,0,0,0,0,0,1,6,30,0,109,4,1202,-3,1,587,20101,0,0,-1,22101,1,-3,-3,21102,0,1,-2,2208,-2,-1,570,1005,570,617,2201,-3,-2,609,4,0,21201,-2,1,-2,1105,1,597,109,-4,2106,0,0,109,5,1202,-4,1,630,20102,1,0,-2,22101,1,-4,-4,21101,0,0,-3,2208,-3,-2,570,1005,570,781,2201,-4,-3,653,20101,0,0,-1,1208,-1,-4,570,1005,570,709,1208,-1,-5,570,1005,570,734,1207,-1,0,570,1005,570,759,1206,-1,774,1001,578,562,684,1,0,576,576,1001,578,566,692,1,0,577,577,21102,702,1,0,1106,0,786,21201,-1,-1,-1,1106,0,676,1001,578,1,578,1008,578,4,570,1006,570,724,1001,578,-4,578,21102,731,1,0,1105,1,786,1106,0,774,1001,578,-1,578,1008,578,-1,570,1006,570,749,1001,578,4,578,21102,756,1,0,1106,0,786,1106,0,774,21202,-1,-11,1,22101,1182,1,1,21102,1,774,0,1106,0,622,21201,-3,1,-3,1105,1,640,109,-5,2105,1,0,109,7,1005,575,802,20101,0,576,-6,20101,0,577,-5,1106,0,814,21101,0,0,-1,21101,0,0,-5,21102,1,0,-6,20208,-6,576,-2,208,-5,577,570,22002,570,-2,-2,21202,-5,51,-3,22201,-6,-3,-3,22101,1465,-3,-3,2102,1,-3,843,1005,0,863,21202,-2,42,-4,22101,46,-4,-4,1206,-2,924,21102,1,1,-1,1105,1,924,1205,-2,873,21101,35,0,-4,1105,1,924,1201,-3,0,878,1008,0,1,570,1006,570,916,1001,374,1,374,1202,-3,1,895,1101,0,2,0,2101,0,-3,902,1001,438,0,438,2202,-6,-5,570,1,570,374,570,1,570,438,438,1001,578,558,921,21002,0,1,-4,1006,575,959,204,-4,22101,1,-6,-6,1208,-6,51,570,1006,570,814,104,10,22101,1,-5,-5,1208,-5,47,570,1006,570,810,104,10,1206,-1,974,99,1206,-1,974,1101,1,0,575,21101,0,973,0,1105,1,786,99,109,-7,2106,0,0,109,6,21101,0,0,-4,21101,0,0,-3,203,-2,22101,1,-3,-3,21208,-2,82,-1,1205,-1,1030,21208,-2,76,-1,1205,-1,1037,21207,-2,48,-1,1205,-1,1124,22107,57,-2,-1,1205,-1,1124,21201,-2,-48,-2,1106,0,1041,21101,0,-4,-2,1105,1,1041,21101,-5,0,-2,21201,-4,1,-4,21207,-4,11,-1,1206,-1,1138,2201,-5,-4,1059,2101,0,-2,0,203,-2,22101,1,-3,-3,21207,-2,48,-1,1205,-1,1107,22107,57,-2,-1,1205,-1,1107,21201,-2,-48,-2,2201,-5,-4,1090,20102,10,0,-1,22201,-2,-1,-2,2201,-5,-4,1103,1201,-2,0,0,1106,0,1060,21208,-2,10,-1,1205,-1,1162,21208,-2,44,-1,1206,-1,1131,1106,0,989,21101,439,0,1,1106,0,1150,21101,0,477,1,1105,1,1150,21101,514,0,1,21102,1,1149,0,1106,0,579,99,21101,0,1157,0,1106,0,579,204,-2,104,10,99,21207,-3,22,-1,1206,-1,1138,2101,0,-5,1176,2101,0,-4,0,109,-6,2106,0,0,4,13,38,1,11,1,38,1,11,1,38,1,11,1,38,1,11,1,38,1,11,1,34,5,11,1,15,13,6,1,15,1,15,1,11,1,6,1,15,1,15,1,11,1,6,1,15,1,15,1,11,1,6,1,15,1,15,1,11,1,6,1,15,1,15,1,11,1,6,1,5,11,15,1,11,1,6,1,31,1,11,1,6,1,31,1,11,1,6,1,31,1,11,1,6,9,23,1,1,11,14,1,23,1,1,1,24,1,23,7,20,1,25,1,3,1,20,1,9,7,7,11,16,1,9,1,5,1,7,1,1,1,3,1,3,1,16,1,7,11,5,1,1,1,3,1,3,1,16,1,7,1,1,1,5,1,1,1,5,1,1,1,3,1,3,1,16,1,7,1,1,1,5,11,3,1,3,1,16,1,7,1,1,1,7,1,5,1,5,1,3,1,16,11,7,7,5,1,3,1,24,1,21,1,3,1,24,1,21,7,22,1,25,1,1,1,12,11,25,9,44,1,5,1,44,1,5,1,44,1,5,1,34,11,5,1,34,1,15,1,34,1,15,1,34,1,15,1,34,1,15,1,34,1,15,1,34,1,11,5,34,1,11,1,38,1,11,1,38,1,11,1,38,1,11,1,38,1,11,1,38,13,4 2 | -------------------------------------------------------------------------------- /inputs/input18.txt: -------------------------------------------------------------------------------- 1 | ################################################################################# 2 | #...........#.......................#...#.........#.....#.....#...Q.............# 3 | ###.#######.#################.#.###.###G#.#####.#.#.#.###.#.#.#.#######.#####.### 4 | #...#.......................#.#.#.......#...#...#z#.#...#.#.#.#...#u..#....b#...# 5 | #.#########################.###.#######.###.#.#####.###.#.#.#####.#.#.#####.###.# 6 | #.............#...#l....#.#...#.....#.#.#...#...#...#...#.#.....#.#.#...#...#...# 7 | #.###########.#.###.#.#.#.###.#####.#.#.#######.#.###.#N#.###.###.#.###.#####.#.# 8 | #.#.........#.#.....#.#.....#.#.....#...#.......#.#.#.#.#...#...#.#...#.......#.# 9 | #.#.#######.#.#.#####.#####.#.#.#####.###.#####.#.#.#.#####.###.#.###.########### 10 | #.#.#.D.#...#.#.....#.....#.#.#.....#...#.#.....#...#...#...#...#...#...#.......# 11 | #.#S#.###.###.#####.#####.#.#.#####.###.#.#.#######.###.#.###.#.###.###.#.#####.# 12 | #...#.......#.#...#.#...#.#.#.#...#.#.#.#.#.#.......#.#.....#.#.#.....#...#.#.A.# 13 | #.###########.#.#.#.#.###.#.#.#C#.#.#.#.#.#.#.#######.#######.###.#######.#.#.#.# 14 | #.#.........#.#.#.#.#.#...#.#...#...#.#.#.#.#...#.#.....#.#...#...#...Y.#...#.#.# 15 | #.#.#######.#.#.###.#.#.#############.#.#.#####.#.#.#.#.#.#.###.###.###.###.#.### 16 | #.#.#...#.#...#...#...#.........#.....#.#.....#.#...#.#.#.#.......#.#.#.#...#...# 17 | ###.#.#.#.#######.###.#####.###.#.#.###.#.#.#.#.#####.#.#.#########.#.#.#######.# 18 | #...#.#...#.......#.....#...#.#.#.#.#...#.#.#.#.#.....#...#...#m..#...#.#.....#w# 19 | #.###.###.#.#.#####.#####.###.#.#.#.#.###.#.#.#.#.#.#######.#.#.#.###.#.#.###.#.# 20 | #e..#...#...#.#.......#...#.....#.#.#...#.#.#.#...#.#...F...#...#.#...#.#...#...# 21 | #.#.###.#######.#######.#.#####.###.###.#.#.#.#####.#.###########.#.###.#.#.###.# 22 | #.#...#...#.......#...#.#.#...#.......#.#.#.#.#.....#...#i..#.I.#.#.#y#.#.#.#.#.# 23 | #.###.#.#.#.#######.###.###.#.#######.#.#.#.###.#######.#.#.###.#M#.#.#.###.#.#.# 24 | #.#.#.#.#.......#...#.#.....#...#.....#.#.#...#...#.#...#.#.....#.....#x#...#.#.# 25 | #.#.#.#.#########.###.#.#######.###.###.#.###.###.#.#.###.#############.#.###.#.# 26 | #.#.#.#.#.#.....#.#...#...#...#...#...#.#v..#...#...#f..#.#...#..o#.....#.#...#.# 27 | #.#.#.#.#.#.###.#.#.#.###.#.#####.#####.#.###.#.###.###J#.#.#.#.#.#.#####.###.#.# 28 | #...#.#...#.#.#...#.#...#.#.#...#.#...#.#.#...#.#...#...#.#.#...#.#.#...#...#...# 29 | ###.#.###.#.#.#####.#####.#.#.#.#.#.#.#.#.#.#####.###.###.#.#####.#.#.###.#.#.### 30 | #...#...#.#...#...#.........#.#...#.#.#.#.#.#.....#...#.#.#.#...#.X.#.....#.#...# 31 | #.#####.#####.#.#.#.#########.#####.#.#.#.#.#.#####.###.#.#O#.#.###########.###.# 32 | #.#...#.....#...#.#.....#...#...#...#.#.#.#...#...#.#..k#...#.#.....#.......#.#.# 33 | #.#B#######.#####.###.###.#.###.#.###.#.#.#####.#.#.#.###########.#.#.#######.#.# 34 | #.#.......#.....#.#...#...#...#...#...#.#...#.#.#..j#.....#.......#.#.#.......#.# 35 | #.#.#####.###.#.#.#####.#####.#.###.#.#.###.#.#.#######.#.#.#######.#.#######.#.# 36 | #.#...#.....#.#.#.......#.....#.#.#.#.#.#.#.#.#.#...#...#.#...#...#.#.....#...#.# 37 | #.#####.###.#.###########.#####.#.#.###.#.#.#.#K#.#.#.###R#.#T###.#.#####.#.###.# 38 | #.#...#...#.#.....#.....#.#...#.#.#...#.#.#.#.#.#.#...#...#.#.#...#...#...#...#.# 39 | #.#.#.###.#.#####.#.#.###.#.#.#.#.###.#.#.#.#.#.#.#####.#####.#.#####.#.###.#.#.# 40 | #...#.....#.....#...#.....#.#.......#.........#...#...........#.......H.#...#..p# 41 | #######################################.@.####################################### 42 | #...........#.....#.....#...#...#.....#.........#...#.......#...#...#...........# 43 | #.###.#####.###.#.#.#.#.#.#.#.#.#.#.#.#.#.#.###.#.#.#.#.###.#.#.#.#.###.#######.# 44 | #.#.#.#...#.....#.#.#.#.#.#.#.#...#.#...#.#.#...#.#...#...#...#...#...#.#.......# 45 | #.#.#.#.#########.###.#.#.#.#####.#.###.#.#.#.###.#######.###########.#.#.####### 46 | #.#.#.#.........#...#.#.#.#.....#.#...#.#.#.#...#.......#...#.#...#...#.#.#.....# 47 | #W#.#.#####.###.###.#.#.#.#####.#####.#.###.###.#######.###.#.#.#.#.###.#.#.###.# 48 | #...#.#...#...#...#.#.#.#.#.....#.....#.#...#...#........g#.#...#.#.#..s#.#...#.# 49 | ###.#.#.#.###.###.#.#.#.#.#.#####.#####.#.#######.#######.#.#####.#.#.#####.###.# 50 | #...#.#.#.#t..#...#.#.#.#.#...#...#...#.#.#.......#...#...#.....#.#.#.......#...# 51 | #.###.#.#.###.#.###.#.#.#.###.###.#.#.#.#.#.#######.#.#########.#.#.#.#######.#.# 52 | #...#...#...#.#.....#.#.#...#...#.#.#...#...#.......#...#...#...#...#...#.....#.# 53 | ###.#######.#######.#.#.###.###.#.#.#####.###.#########.#.#.#.###.#######.#####.# 54 | #.#.#.....#...#...#...#.#r#.#.#...#.....#.#.#...#.....#...#.#.#.#...#.....#.....# 55 | #.#.#.#######.#.#.#####.#.#.#.#########V#.#.###.#.###.#####.#.#.###.#.#####.##### 56 | #...#.#.....#.#.#.#...#.#.#.#.........#.#...#.#.#...#.#...#...#...#...#.#...#...# 57 | #P###.#.###.#.#.#.#.#.#.#.#.#.#####.###.###.#.#.###.#.###.#######.#####.#.#####.# 58 | #.....#.#.....#.#.#.#...#.#.#.....#.....#.#...#...#.#...#.#.............#.......# 59 | ###.###.#####.#.#.###.###.#.#####.#######.###.###.#.###.#.#.#.#########.#######.# 60 | #...#...#...#.#.#...#.....#.#.#...#.....#.#.....#.#.#.....#.#.........#.....#...# 61 | #####.###.#.###.###.#######.#.#.###.###.#.#.#####.#.#######.#######.#.#####.#.### 62 | #.....#...#.......#.#.#.....#.#.#...#...#...#...#.#.......#.#.#...#.#.....#.#.#.# 63 | #.###.#.###########.#.#.#####.#.###.#.#######.#.#.#.#####.#.#.#.#.#.#####.###.#.# 64 | #...#.#.#.....#.....#...#.....#...#.#...#...#.#...#...#...#.#...#.#.#...#...#.#d# 65 | #.#.#.#.#.###.#.#########.#.#####.#.#####.#.#.#########.#.#.#####.#.#.#.###.#.#.# 66 | #.#.#.#...#.#.#...#.......#.#...#.#.#...#.#.#.........#.#.#.....#.#...#...#.#.#.# 67 | #.#.#######.#.###.#.#######.#.#.#.#.#.#.#.#.#########.#.#######.#.#########.#.#.# 68 | #.#.........#...#.#...#.L.#...#c#.#...#.#.#...........#....q..#.#.........#.....# 69 | #.#######.#####.#.###.###.#####.#.#####.#.#############.#####.#E#########.####### 70 | #.#.....#.......#...#.....#...#.#.#...#.#.#...#...#.....#...#.#.#.......#.......# 71 | #.#.###############.#####.###.#.#Z#.#.#.#.#.#.#.#.#.#####.###.#.#.#############.# 72 | #.#.......#.....#.#.....#.....#...#.#...#...#.#.#...#...#.U.#...#.....#.........# 73 | #.#.###.#.###.#.#.###.#######.#####.###.#.###.#.#####.#.###.#########.#.######### 74 | #.#...#.#.....#.....#.......#.#.....#.#.#.#...#...#...#.#.........#...#.#.#.....# 75 | #.###.#.###########.#######.#.#.#.###.#.#.#.#####.###.#.#.#######.#.#.#.#.#.#.#.# 76 | #.#...#a#.........#...#.#...#.#.#.#...#.#.#.....#.....#...#.....#...#.#.#...#.#.# 77 | #.#####.#.#####.#####.#.#.###.###.#.#.#.#.#####.#########.#.###.#######.#####.#.# 78 | #.#...#.#.#...#.....#...#..n..#...#.#.#.#...#.#.........#.#.#...#.....#.#...#.#.# 79 | #.#.#.#.#.#.#.#####.###.#######.###.#.#.###.#.#########.###.#.###.###.#.#.#.#.#.# 80 | #...#...#...#....h#.............#...#...#.............#.....#.......#.....#...#.# 81 | ################################################################################# 82 | -------------------------------------------------------------------------------- /inputs/input19.txt: -------------------------------------------------------------------------------- 1 | 109,424,203,1,21101,0,11,0,1105,1,282,21101,18,0,0,1105,1,259,2101,0,1,221,203,1,21101,31,0,0,1105,1,282,21102,38,1,0,1106,0,259,20101,0,23,2,21201,1,0,3,21101,1,0,1,21101,0,57,0,1105,1,303,2101,0,1,222,21001,221,0,3,21001,221,0,2,21101,259,0,1,21101,0,80,0,1106,0,225,21102,117,1,2,21102,91,1,0,1105,1,303,2101,0,1,223,20102,1,222,4,21102,1,259,3,21101,0,225,2,21102,1,225,1,21101,0,118,0,1105,1,225,21001,222,0,3,21102,1,77,2,21102,133,1,0,1105,1,303,21202,1,-1,1,22001,223,1,1,21102,1,148,0,1105,1,259,2102,1,1,223,21002,221,1,4,20101,0,222,3,21102,20,1,2,1001,132,-2,224,1002,224,2,224,1001,224,3,224,1002,132,-1,132,1,224,132,224,21001,224,1,1,21102,195,1,0,106,0,109,20207,1,223,2,20102,1,23,1,21101,0,-1,3,21101,0,214,0,1106,0,303,22101,1,1,1,204,1,99,0,0,0,0,109,5,1202,-4,1,249,21201,-3,0,1,21201,-2,0,2,22101,0,-1,3,21102,250,1,0,1106,0,225,22101,0,1,-4,109,-5,2105,1,0,109,3,22107,0,-2,-1,21202,-1,2,-1,21201,-1,-1,-1,22202,-1,-2,-2,109,-3,2106,0,0,109,3,21207,-2,0,-1,1206,-1,294,104,0,99,21202,-2,1,-2,109,-3,2105,1,0,109,5,22207,-3,-4,-1,1206,-1,346,22201,-4,-3,-4,21202,-3,-1,-1,22201,-4,-1,2,21202,2,-1,-1,22201,-4,-1,1,21202,-2,1,3,21102,1,343,0,1105,1,303,1106,0,415,22207,-2,-3,-1,1206,-1,387,22201,-3,-2,-3,21202,-2,-1,-1,22201,-3,-1,3,21202,3,-1,-1,22201,-3,-1,2,21202,-4,1,1,21102,384,1,0,1106,0,303,1105,1,415,21202,-4,-1,-4,22201,-4,-3,-4,22202,-3,-2,-2,22202,-2,-4,-4,22202,-3,-2,-3,21202,-4,-1,-2,22201,-3,-2,1,22101,0,1,-4,109,-5,2105,1,0 2 | -------------------------------------------------------------------------------- /inputs/input20.txt: -------------------------------------------------------------------------------- 1 | S R C O F Z Y 2 | X E R T P Z H 3 | ###############################.###########.#######.###.#########.#######.###.############################### 4 | #.#.#.#.#.........#.#.#.#...#.....#.....#.....#...#...#.....#.#.......#...........#...#.........#.#.......#.# 5 | #.#.#.#.#########.#.#.#.#.#####.###.#.#######.###.###.#####.#.#.###.#.#.###.#.#####.###.#####.###.###.#####.# 6 | #.....#...#.#...................#...#.#.............#.#.....#.....#.#.#.#...#.#.............#.#.........#...# 7 | #####.#.###.###.#####.#.#.###.#.#.###.#.#.#####.#####.#.#########.#######.#####.###.#.#.#######.###.#####.### 8 | #...#...#.#.....#.....#.#.#...#.....#.#.#.....#.#...#.#.#.....#...#...#...#.....#.#.#.#...........#...#.#...# 9 | #.#####.#.#.#.#.#.###.#.#.###########.###.###.###.#.#.#.###.#####.#.#.###.#.###.#.###.#.#.#############.#.### 10 | #.#...#...#.#.#.#.#...#.#...#.#.#.......#.#...#...#...#...#.#.....#.#...#.....#.....#.#.#...#...#.#.#...#...# 11 | #.###.###.###########.#.#.###.#.###.###.#####.#####.###.###.#####.#.#.#.#.#########.#########.###.#.###.#.### 12 | #.......#.#.#.#.......#.#.#...........#.#.....#.......#.#.....#.#...#.#.#.#.....#.#.#.#.....#.#.#...#.....#.# 13 | #.#.#.###.#.#.#############.#.###.###.#######.###.###.#.#.###.#.#.###.###.#.#####.###.#.#####.#.#.#.#.#.#.#.# 14 | #.#.#.....#.....#...#...#.#.#.#...#.#...#...#...#.#.#.#.....#.#.#.#...#...............#.#...#...#.#...#.#.#.# 15 | #########.#####.#.#####.#.#.###.###.#.###.###.###.#.###.###.#.#.#####.#.###.#######.###.#.###.#######.#####.# 16 | #.#...#.......#...........#.#.#.#.....#.......#...#.......#.#.....#.#.#.#.#.#.#.#.#.#...#.......#...#...#...# 17 | #.#.#########.###.#.#####.###.#####.#.#######.#.#############.#####.#.#.#.###.#.#.###.###.###.#.###.###.###.# 18 | #...#...#.#...#...#.#.........#...#.#...#.#.#.#.......#.#.....#.#.....#.....#...............#.#.#.....#.....# 19 | #.#####.#.#.#########.#######.#.###.#.###.#.#.###.#####.#.###.#.#####.###.###.###.#####.#.#.###.###.###.##### 20 | #.#...#.#.#.#.........#.#.....#...#.#.#.....#.#.....#.....#.......#.....#.#...#.....#...#.#.#...#.#.#.......# 21 | #.###.#.#.#.###########.#.#.#.###.###.#.###.#.#.#############.#####.#.###.#.#####.###.#.#########.#.#.####### 22 | #...#.#.....#.....#.....#.#.#...#.#...#.#.#...#...#...#.#...#.....#.#.#.......#.#...#.#...#.#.....#...#.#.#.# 23 | ###.#.###.#####.#######.#####.###.###.#.#.#######.#.###.###.#.#.#####.#.#######.#########.#.#.#######.#.#.#.# 24 | #.#...#.....#.#.....#...#.#...........#...#.#.......#.#.......#.#.#.#.#.#...#...#...#.#.#.#.#.#.........#...# 25 | #.#.#.#.#.###.#.#.###.###.#.###.#####.###.#.###.###.#.#.#########.#.#.#.#.#####.#.###.#.###.#.#######.#####.# 26 | #...#.#.#.#.#...#...#.......#.....#.....#.#.#.....#.#.........#.....#.#...#.............#.......#.#.#...#.#.# 27 | ###.#####.#.###.#####.###.#####.#########.#.#.#.#######.###.#.#.###.#.#.###.###.###.#######.###.#.#.#.###.#.# 28 | #.#.#...#.#...#.....#.#.....#.........#.....#.#.......#.#...#.#...#...#.......#.#...#.#.#.....#.#.#.#.#.....# 29 | #.#.###.#.###.#.#################.#########.#####.#######.#######.#########.#########.#.###.#.###.#.#.#####.# 30 | #...........#.......#...#.# R Q O O B S #.#...#.#.#.#.#.....#.#.#.# 31 | #####.#########.#.#.#.###.# G M Y Q K X #.#.###.#.###.###.###.#.#.# 32 | #...#...#.#.#...#.#.#.#.#.# #...................#......RK 33 | ###.#.###.#.#.#######.#.#.# #.#######.#.#.#####.###.### 34 | #.#...#.#.#.#...#...#.#.#.# RE......#.#.#.#.#.....#.#...# 35 | #.###.#.#.#.#.###.###.#.#.# #.#####.#####.###.#.#.###.# 36 | #.......#.........#...#...# #.....#...#.#.#.#.#.#...#.# 37 | ###.###.#.#####.#####.#.### #.#####.#.#.###.###.#####.# 38 | #.#...#.....#.#.#.........# #.#.#.#.#...#.#.#.........# 39 | #.###.#######.#.#.#.###.### #.#.#.#####.#.#.###.#####.# 40 | BK..........#.......#.#.....# #.#.#.............#...#...# 41 | #.#.###################.### ###.#.#######.###.######### 42 | #.#.#.#.#.#.#.#.#...#......MV #.#.#.....#...#.....#.....# 43 | #.###.#.#.#.#.#.#.#####.### #.#.#####.###.#####.#.##### 44 | #.#.#.....#.......#.......# #.......#.#.....#.....#.#..FL 45 | ###.###.#.#.#####.#.#####.# #.#.#####.###.#.#.#.#.#.#.# 46 | #.#.#...#.....#...#.#...#.# FP..#.........#.#.#.#.#.....# 47 | #.#.###.#.#.#####.#####.### ###########.############### 48 | #.......#.#...#.......#...# DB..#.....#.#.#.#...#...#.#.# 49 | ###.###############.###.### #.#.#.###.###.###.#.#.#.#.# 50 | QM......#.....#.#...#........FW #...#.#.....#.......#.#....UC 51 | ###.#####.#.#.#.########### #.###.#.#.#######.###.#.### 52 | DB..#.#...#.#.#.....#.......# #...#...#.......#...#.....# 53 | #.#####.###.###.#.###.###.# #.###.#####.#######.#.##### 54 | #...#.....#.....#.#.#.#...# #.#.#...#...........#.#...# 55 | #.###.#.#####.#####.#.#.### ###.#.###################.# 56 | #...#.#.#...#...#...#.#.#.# AV....#.#.............#.....# 57 | #.###.#.#.###.#.#.#.#.#.#.# #.#####.#.#########.###.#.# 58 | #.....#.......#...#...#....ZP #.......#...#.......#...#.# 59 | #.#.#.#.#################.# ###.###.#####.#.#.#####.#.# 60 | #.#.#.#.#.#...........#...# #.#.#.#.#...#.#.#.......#..PA 61 | #########.#.#.###.###.##### #.#.#.###.################# 62 | #.......#.#.#.#...#.....#..RK UC..#.#...#.#.#.#............RG 63 | #.###.###.#.#####.#.#.###.# #.###.#.#.#.#.#.#.#.###.#.# 64 | DE..#.....#.#...#...#.#.....# #...#.#.........#.#.#...#.# 65 | ###.#####.#.###.########### ###.#.#######.#.#.#.###.#.# 66 | #.............#.#...#...#.# #...#.....#.#.#.#.#.#...#.# 67 | #######.#########.#.###.#.# #.###.#####.#.#.###.####### 68 | #...#.........#.#.#.......# #.....#.#.....#...#.#.#.#.# 69 | ###.#####.#####.#####.#.#.# #.#####.#########.###.#.#.# 70 | #.....#.#...#.#.#.#.#.#.#.# #.#.............#.#.#.#...# 71 | ###.###.#####.#.#.#.#.###.# #.#.###.#.#########.#.#.### 72 | #...#...#.....#...#...#...# #.#...#.#.#.#.#.#...#.#...# 73 | #.#.###.###.###.#####.###.# ###.###.###.#.#.#.###.###.# 74 | OQ..#.....................#..YI ZJ......#.......#.#.....#...# 75 | #.#.#########.###.#.####### #######.###.###.#.#.#####.# 76 | #.#.#.......#...#.#.#.....# #...#...#.........#........MV 77 | #####.#.###.###.#######.#.# #.#######.#.###.#####.###.# 78 | #...#.#.#.#...#.#...#...#.# ZL........#.#.#.......#...#.# 79 | #.#.#.#####.#.#####.#.###.# #####.###############.##### 80 | #.#.....#...#.#.#.....#...# #.....#.#...#...#...#.#....ZJ 81 | #.###.###.#####.###.###.### #.#####.#.#####.#.#######.# 82 | FW....#...#...........#.#....YH OT..#...#.....#.....#........AV 83 | #.###.#######.###.#.#.#.### #.#.#.#.#.#####.#.#######.# 84 | #.#.....#.......#.#.#...#.# #...#...#.......#.........# 85 | #.###.###.#.#####.#.#####.# C N I F D P E #.#.###.#.#####.#.#####.### 86 | #.#...#.#.#.....#.#...#...# R C A L E A K #.#...#.#.#.....#...#.#...# 87 | #.#.#.#.###.#####.#.###.#######.#######.#########.#####.#####.#########.###.#######.#.#####.###.###.###.#.#.# 88 | #.#.#.....#...#...#...#.#...........#.....#.#.....#.....#.........#.....#.......#.#.#.....#.#.....#.#...#.#.# 89 | ###.#.#####.#####.#####.#####.###.#####.###.#.###.#.#####.###########.#.#####.#.#.###.###.#.#.#.#.#.###.###.# 90 | #.#.#...#.#.....#.#.........#...#.#.#.......#.#.#.#.....#.........#...#...#.#.#.#...#.#.#.#.#.#.#.#.......#.# 91 | #.###.###.#.#########.#.###.#.#####.#.#.#.#####.#.#.#####.#.#########.#.#.#.###.#.#.###.###.#.#.###.###.##### 92 | #.......#.......#.....#.#.........#.#.#.#.#...#...#...#...#.#.#.......#.#.#...#.#.#.....#.#.#.#.#.#...#.#...# 93 | ###.###.#.#.#.###.###.#.###.###.###.###.#.###.#.###.#######.#.#####.#.#######.#.###.###.#.#######.#.#######.# 94 | #...#...#.#.#.#...#...#.#.....#.#.#...#.#...#.....#.....#.......#.#.#...#.............#.#.#...#.#...........# 95 | #.#.#.###.#####.###############.#.#.#.###.#####.###.#######.###.#.###.#####.#.###########.#.#.#.#.#.#####.### 96 | #.#.#.#...#.#.......#.....#.#.....#.#.........#.#...#...#.#.#...#...#.....#.#.#.............#.#...#...#.....# 97 | ###.#######.###.#.#.#.###.#.#.#######.#####.###.###.###.#.###.#.#.###.#######.#####.#.###.#####.#########.### 98 | #...#...........#.#.#.#...#.#.#...........#...#.#...#.......#.#.#.....#...#.........#...#.#...#.#...#.......# 99 | #.###.#.#####.#.#########.#.#.#.###.#####.#####.###.#####.#.#.###.###.#.#######.#############.###.#####.###.# 100 | #...#.#.#.....#.#...#.........#.#.....#...#.......#.....#.#.....#.#.#.....#.#.........#.....#.#.#.#...#.#...# 101 | ###.###.#.#.#.#####.###.#.#.#.#########.#.#######.#.###########.#.#.#######.#.#.#.###.###.#.#.#.#.#.#######.# 102 | #...#...#.#.#.....#...#.#.#.#.....#.....#.#.....#.#.....#.#.#...#.#.#.#.......#.#.#.#.....#.........#.....#.# 103 | #.#.#.#.###.#.#.#####.#######.#.###.#.#.###.###.#.#.#.###.#.###.#.#.#.#####.#.#####.#.#.#######.###.#.#####.# 104 | #.#.#.#...#.#.#.#.#.....#.....#.#...#.#.#.....#...#.#.#.#...#...#.#.....#.#.#.#.#...#.#.#.#...#.#.......#.#.# 105 | #.#######.#######.#####.#####.#######.###.###.#.#.###.#.###.###.#.#####.#.#.###.#.#####.#.###.#####.###.#.### 106 | #.#.......#.....................#.......#...#.#.#.#...#.....#...#...#.#.......#.......#.#.........#...#.....# 107 | ###.###.###.#.#.###.#.#######.#####.#####.###.#####.#####.#.###.#.#.#.###.#####.#########.#####.#######.##### 108 | #...#...#...#.#.#...#.#.#.......#.....#.#.#...#.#...#...#.#.....#.#.#.#...#.......#...........#.....#.#.#...# 109 | #.#####.#########.#####.#####.#######.#.#####.#.###.#.###.#.#.###.###.#.#.#.###.###.###.###.#######.#.#####.# 110 | #.#.#...#...........#...........#...#.......#.#.#...#...#.#.#.#.#.....#.#.#...#.......#.#.#.....#.......#...# 111 | ###.#.#.###.#.#.#.#####.#####.#####.#.#######.#.###.#.#.#.###.#.#.#.#.###.###.#.#####.###.#.###.#######.###.# 112 | #.....#.#...#.#.#.#.....#.........#.......#.....#.....#.#.#.....#.#.#.#.......#...#.......#.#.........#.....# 113 | #################################.#.#####.#####.#######.#.#######.#############.############################# 114 | Z A E Y O Z N I 115 | P A K I Y L C A 116 | -------------------------------------------------------------------------------- /inputs/input21.txt: -------------------------------------------------------------------------------- 1 | 109,2050,21102,1,966,1,21101,13,0,0,1105,1,1378,21102,20,1,0,1105,1,1337,21101,0,27,0,1105,1,1279,1208,1,65,748,1005,748,73,1208,1,79,748,1005,748,110,1208,1,78,748,1005,748,132,1208,1,87,748,1005,748,169,1208,1,82,748,1005,748,239,21102,1041,1,1,21102,73,1,0,1106,0,1421,21102,1,78,1,21102,1,1041,2,21102,88,1,0,1106,0,1301,21101,0,68,1,21101,0,1041,2,21101,103,0,0,1105,1,1301,1102,1,1,750,1105,1,298,21102,1,82,1,21101,0,1041,2,21101,0,125,0,1105,1,1301,1101,0,2,750,1106,0,298,21102,79,1,1,21102,1041,1,2,21102,147,1,0,1106,0,1301,21101,84,0,1,21101,0,1041,2,21101,0,162,0,1105,1,1301,1102,1,3,750,1105,1,298,21102,1,65,1,21101,0,1041,2,21102,1,184,0,1106,0,1301,21101,76,0,1,21101,1041,0,2,21102,1,199,0,1106,0,1301,21102,75,1,1,21101,0,1041,2,21102,214,1,0,1106,0,1301,21102,1,221,0,1106,0,1337,21102,10,1,1,21101,1041,0,2,21102,236,1,0,1105,1,1301,1105,1,553,21101,85,0,1,21101,1041,0,2,21101,0,254,0,1105,1,1301,21101,0,78,1,21101,0,1041,2,21102,269,1,0,1105,1,1301,21102,1,276,0,1105,1,1337,21102,10,1,1,21101,1041,0,2,21101,291,0,0,1105,1,1301,1102,1,1,755,1106,0,553,21101,32,0,1,21101,1041,0,2,21102,1,313,0,1105,1,1301,21102,1,320,0,1105,1,1337,21102,327,1,0,1105,1,1279,2102,1,1,749,21101,65,0,2,21101,73,0,3,21102,1,346,0,1105,1,1889,1206,1,367,1007,749,69,748,1005,748,360,1101,0,1,756,1001,749,-64,751,1105,1,406,1008,749,74,748,1006,748,381,1102,-1,1,751,1106,0,406,1008,749,84,748,1006,748,395,1101,0,-2,751,1105,1,406,21102,1100,1,1,21102,1,406,0,1105,1,1421,21101,32,0,1,21101,1100,0,2,21101,0,421,0,1105,1,1301,21102,1,428,0,1105,1,1337,21101,0,435,0,1105,1,1279,2101,0,1,749,1008,749,74,748,1006,748,453,1102,1,-1,752,1105,1,478,1008,749,84,748,1006,748,467,1102,-2,1,752,1106,0,478,21101,1168,0,1,21102,478,1,0,1105,1,1421,21102,1,485,0,1106,0,1337,21102,1,10,1,21101,0,1168,2,21102,500,1,0,1106,0,1301,1007,920,15,748,1005,748,518,21101,0,1209,1,21102,518,1,0,1105,1,1421,1002,920,3,529,1001,529,921,529,102,1,750,0,1001,529,1,537,102,1,751,0,1001,537,1,545,101,0,752,0,1001,920,1,920,1106,0,13,1005,755,577,1006,756,570,21102,1100,1,1,21102,570,1,0,1105,1,1421,21102,1,987,1,1106,0,581,21102,1,1001,1,21101,0,588,0,1105,1,1378,1101,0,758,594,102,1,0,753,1006,753,654,20101,0,753,1,21101,610,0,0,1105,1,667,21101,0,0,1,21102,621,1,0,1106,0,1463,1205,1,647,21102,1,1015,1,21101,635,0,0,1105,1,1378,21102,1,1,1,21102,1,646,0,1105,1,1463,99,1001,594,1,594,1106,0,592,1006,755,664,1101,0,0,755,1106,0,647,4,754,99,109,2,1102,1,726,757,22102,1,-1,1,21102,9,1,2,21102,1,697,3,21102,692,1,0,1105,1,1913,109,-2,2105,1,0,109,2,1001,757,0,706,2101,0,-1,0,1001,757,1,757,109,-2,2106,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,255,63,95,191,223,159,127,0,107,93,116,216,218,226,252,60,121,251,113,197,42,172,190,100,62,204,98,158,119,110,125,50,178,114,177,246,123,243,236,54,168,247,99,53,140,173,167,238,103,106,199,249,217,86,234,35,212,187,162,43,157,55,39,153,170,47,163,233,49,76,115,111,120,227,174,188,196,235,171,71,156,220,69,102,228,232,185,206,222,77,78,221,241,182,85,70,124,213,79,108,242,142,141,59,57,38,175,207,179,152,154,56,237,136,203,169,198,205,184,84,117,254,87,101,186,189,58,138,245,51,239,68,248,202,253,229,230,109,92,143,155,61,137,46,214,181,94,122,231,183,118,139,250,166,244,219,34,126,201,215,200,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20,73,110,112,117,116,32,105,110,115,116,114,117,99,116,105,111,110,115,58,10,13,10,87,97,108,107,105,110,103,46,46,46,10,10,13,10,82,117,110,110,105,110,103,46,46,46,10,10,25,10,68,105,100,110,39,116,32,109,97,107,101,32,105,116,32,97,99,114,111,115,115,58,10,10,58,73,110,118,97,108,105,100,32,111,112,101,114,97,116,105,111,110,59,32,101,120,112,101,99,116,101,100,32,115,111,109,101,116,104,105,110,103,32,108,105,107,101,32,65,78,68,44,32,79,82,44,32,111,114,32,78,79,84,67,73,110,118,97,108,105,100,32,102,105,114,115,116,32,97,114,103,117,109,101,110,116,59,32,101,120,112,101,99,116,101,100,32,115,111,109,101,116,104,105,110,103,32,108,105,107,101,32,65,44,32,66,44,32,67,44,32,68,44,32,74,44,32,111,114,32,84,40,73,110,118,97,108,105,100,32,115,101,99,111,110,100,32,97,114,103,117,109,101,110,116,59,32,101,120,112,101,99,116,101,100,32,74,32,111,114,32,84,52,79,117,116,32,111,102,32,109,101,109,111,114,121,59,32,97,116,32,109,111,115,116,32,49,53,32,105,110,115,116,114,117,99,116,105,111,110,115,32,99,97,110,32,98,101,32,115,116,111,114,101,100,0,109,1,1005,1262,1270,3,1262,20102,1,1262,0,109,-1,2106,0,0,109,1,21101,1288,0,0,1106,0,1263,21002,1262,1,0,1101,0,0,1262,109,-1,2106,0,0,109,5,21101,0,1310,0,1106,0,1279,22102,1,1,-2,22208,-2,-4,-1,1205,-1,1332,21201,-3,0,1,21101,0,1332,0,1105,1,1421,109,-5,2105,1,0,109,2,21102,1,1346,0,1105,1,1263,21208,1,32,-1,1205,-1,1363,21208,1,9,-1,1205,-1,1363,1106,0,1373,21102,1,1370,0,1105,1,1279,1106,0,1339,109,-2,2105,1,0,109,5,1202,-4,1,1385,21002,0,1,-2,22101,1,-4,-4,21101,0,0,-3,22208,-3,-2,-1,1205,-1,1416,2201,-4,-3,1408,4,0,21201,-3,1,-3,1105,1,1396,109,-5,2105,1,0,109,2,104,10,21202,-1,1,1,21101,0,1436,0,1106,0,1378,104,10,99,109,-2,2105,1,0,109,3,20002,594,753,-1,22202,-1,-2,-1,201,-1,754,754,109,-3,2106,0,0,109,10,21101,5,0,-5,21102,1,1,-4,21102,1,0,-3,1206,-9,1555,21102,1,3,-6,21102,5,1,-7,22208,-7,-5,-8,1206,-8,1507,22208,-6,-4,-8,1206,-8,1507,104,64,1105,1,1529,1205,-6,1527,1201,-7,716,1515,21002,0,-11,-8,21201,-8,46,-8,204,-8,1105,1,1529,104,46,21201,-7,1,-7,21207,-7,22,-8,1205,-8,1488,104,10,21201,-6,-1,-6,21207,-6,0,-8,1206,-8,1484,104,10,21207,-4,1,-8,1206,-8,1569,21102,1,0,-9,1105,1,1689,21208,-5,21,-8,1206,-8,1583,21102,1,1,-9,1105,1,1689,1201,-5,716,1589,20101,0,0,-2,21208,-4,1,-1,22202,-2,-1,-1,1205,-2,1613,22101,0,-5,1,21102,1,1613,0,1106,0,1444,1206,-1,1634,22102,1,-5,1,21102,1627,1,0,1105,1,1694,1206,1,1634,21102,2,1,-3,22107,1,-4,-8,22201,-1,-8,-8,1206,-8,1649,21201,-5,1,-5,1206,-3,1663,21201,-3,-1,-3,21201,-4,1,-4,1105,1,1667,21201,-4,-1,-4,21208,-4,0,-1,1201,-5,716,1676,22002,0,-1,-1,1206,-1,1686,21101,0,1,-4,1106,0,1477,109,-10,2106,0,0,109,11,21102,1,0,-6,21101,0,0,-8,21102,1,0,-7,20208,-6,920,-9,1205,-9,1880,21202,-6,3,-9,1201,-9,921,1724,21002,0,1,-5,1001,1724,1,1732,21002,0,1,-4,22101,0,-4,1,21102,1,1,2,21102,9,1,3,21102,1,1754,0,1105,1,1889,1206,1,1772,2201,-10,-4,1766,1001,1766,716,1766,21002,0,1,-3,1106,0,1790,21208,-4,-1,-9,1206,-9,1786,21201,-8,0,-3,1105,1,1790,21202,-7,1,-3,1001,1732,1,1796,20102,1,0,-2,21208,-2,-1,-9,1206,-9,1812,22101,0,-8,-1,1106,0,1816,21202,-7,1,-1,21208,-5,1,-9,1205,-9,1837,21208,-5,2,-9,1205,-9,1844,21208,-3,0,-1,1105,1,1855,22202,-3,-1,-1,1106,0,1855,22201,-3,-1,-1,22107,0,-1,-1,1106,0,1855,21208,-2,-1,-9,1206,-9,1869,22102,1,-1,-8,1105,1,1873,22101,0,-1,-7,21201,-6,1,-6,1105,1,1708,22102,1,-8,-10,109,-11,2105,1,0,109,7,22207,-6,-5,-3,22207,-4,-6,-2,22201,-3,-2,-1,21208,-1,0,-6,109,-7,2105,1,0,0,109,5,1201,-2,0,1912,21207,-4,0,-1,1206,-1,1930,21102,1,0,-4,21202,-4,1,1,22102,1,-3,2,21101,0,1,3,21102,1949,1,0,1105,1,1954,109,-5,2105,1,0,109,6,21207,-4,1,-1,1206,-1,1977,22207,-5,-3,-1,1206,-1,1977,21202,-5,1,-5,1106,0,2045,22101,0,-5,1,21201,-4,-1,2,21202,-3,2,3,21102,1,1996,0,1106,0,1954,21202,1,1,-5,21101,1,0,-2,22207,-5,-3,-1,1206,-1,2015,21101,0,0,-2,22202,-3,-2,-3,22107,0,-4,-1,1206,-1,2037,21201,-2,0,1,21101,0,2037,0,105,1,1912,21202,-3,-1,-3,22201,-5,-3,-5,109,-6,2105,1,0 2 | -------------------------------------------------------------------------------- /inputs/input22.txt: -------------------------------------------------------------------------------- 1 | cut -4258 2 | deal with increment 71 3 | cut -6593 4 | deal into new stack 5 | deal with increment 54 6 | cut -5397 7 | deal into new stack 8 | cut 1327 9 | deal with increment 20 10 | deal into new stack 11 | deal with increment 45 12 | cut -9986 13 | deal into new stack 14 | deal with increment 47 15 | cut -3318 16 | deal with increment 75 17 | cut 542 18 | deal with increment 48 19 | cut 8670 20 | deal with increment 13 21 | deal into new stack 22 | deal with increment 5 23 | cut -8813 24 | deal with increment 36 25 | cut 3228 26 | deal with increment 21 27 | cut 5143 28 | deal with increment 13 29 | cut 7329 30 | deal with increment 74 31 | deal into new stack 32 | deal with increment 4 33 | cut 4178 34 | deal with increment 29 35 | cut -7664 36 | deal with increment 17 37 | cut 8216 38 | deal with increment 22 39 | cut -7497 40 | deal with increment 10 41 | cut -2813 42 | deal into new stack 43 | cut 8416 44 | deal with increment 16 45 | cut -4124 46 | deal with increment 13 47 | cut -8531 48 | deal with increment 74 49 | cut -9397 50 | deal with increment 57 51 | cut -1832 52 | deal with increment 34 53 | cut -2538 54 | deal into new stack 55 | cut 7837 56 | deal with increment 57 57 | cut 5257 58 | deal with increment 2 59 | cut -8241 60 | deal with increment 26 61 | deal into new stack 62 | deal with increment 39 63 | cut -659 64 | deal with increment 58 65 | cut 34 66 | deal into new stack 67 | deal with increment 46 68 | cut 9168 69 | deal with increment 35 70 | cut 8530 71 | deal into new stack 72 | cut 297 73 | deal into new stack 74 | cut 1116 75 | deal with increment 69 76 | cut 5440 77 | deal with increment 6 78 | deal into new stack 79 | cut 3811 80 | deal with increment 7 81 | deal into new stack 82 | cut -8657 83 | deal with increment 29 84 | cut 8933 85 | deal with increment 4 86 | cut -6643 87 | deal with increment 37 88 | cut 1688 89 | deal with increment 32 90 | cut -554 91 | deal with increment 69 92 | deal into new stack 93 | deal with increment 64 94 | cut 4395 95 | deal with increment 71 96 | cut -9180 97 | deal with increment 60 98 | cut 6480 99 | deal with increment 73 100 | cut -7146 101 | -------------------------------------------------------------------------------- /inputs/input23.txt: -------------------------------------------------------------------------------- 1 | 3,62,1001,62,11,10,109,2257,105,1,0,1119,1088,1678,1851,2222,1647,606,1707,785,1445,1220,1886,1160,818,1546,882,1820,1950,2055,1779,1408,1919,1987,571,1476,985,709,2088,680,1515,2191,647,1348,2158,950,1191,742,1744,1317,1610,1286,2018,851,1016,919,1249,1377,2117,1579,1051,0,0,0,0,0,0,0,0,0,0,0,0,3,64,1008,64,-1,62,1006,62,88,1006,61,170,1106,0,73,3,65,21001,64,0,1,20102,1,66,2,21102,1,105,0,1106,0,436,1201,1,-1,64,1007,64,0,62,1005,62,73,7,64,67,62,1006,62,73,1002,64,2,133,1,133,68,133,102,1,0,62,1001,133,1,140,8,0,65,63,2,63,62,62,1005,62,73,1002,64,2,161,1,161,68,161,1101,1,0,0,1001,161,1,169,1002,65,1,0,1101,0,1,61,1101,0,0,63,7,63,67,62,1006,62,203,1002,63,2,194,1,68,194,194,1006,0,73,1001,63,1,63,1106,0,178,21102,210,1,0,105,1,69,1202,1,1,70,1101,0,0,63,7,63,71,62,1006,62,250,1002,63,2,234,1,72,234,234,4,0,101,1,234,240,4,0,4,70,1001,63,1,63,1106,0,218,1106,0,73,109,4,21102,1,0,-3,21102,0,1,-2,20207,-2,67,-1,1206,-1,293,1202,-2,2,283,101,1,283,283,1,68,283,283,22001,0,-3,-3,21201,-2,1,-2,1106,0,263,22101,0,-3,-3,109,-4,2105,1,0,109,4,21102,1,1,-3,21101,0,0,-2,20207,-2,67,-1,1206,-1,342,1202,-2,2,332,101,1,332,332,1,68,332,332,22002,0,-3,-3,21201,-2,1,-2,1106,0,312,22101,0,-3,-3,109,-4,2106,0,0,109,1,101,1,68,358,21001,0,0,1,101,3,68,366,21002,0,1,2,21102,1,376,0,1105,1,436,22102,1,1,0,109,-1,2105,1,0,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648,4294967296,8589934592,17179869184,34359738368,68719476736,137438953472,274877906944,549755813888,1099511627776,2199023255552,4398046511104,8796093022208,17592186044416,35184372088832,70368744177664,140737488355328,281474976710656,562949953421312,1125899906842624,109,8,21202,-6,10,-5,22207,-7,-5,-5,1205,-5,521,21102,0,1,-4,21102,0,1,-3,21102,1,51,-2,21201,-2,-1,-2,1201,-2,385,471,20102,1,0,-1,21202,-3,2,-3,22207,-7,-1,-5,1205,-5,496,21201,-3,1,-3,22102,-1,-1,-5,22201,-7,-5,-7,22207,-3,-6,-5,1205,-5,515,22102,-1,-6,-5,22201,-3,-5,-3,22201,-1,-4,-4,1205,-2,461,1106,0,547,21101,0,-1,-4,21202,-6,-1,-6,21207,-7,0,-5,1205,-5,547,22201,-7,-6,-7,21201,-4,1,-4,1106,0,529,21202,-4,1,-7,109,-8,2106,0,0,109,1,101,1,68,563,21002,0,1,0,109,-1,2106,0,0,1101,50263,0,66,1101,0,3,67,1102,1,598,68,1102,302,1,69,1102,1,1,71,1102,604,1,72,1106,0,73,0,0,0,0,0,0,6,195758,1102,1,97879,66,1102,1,6,67,1102,633,1,68,1102,253,1,69,1102,1,1,71,1102,645,1,72,1105,1,73,0,0,0,0,0,0,0,0,0,0,0,0,11,35974,1101,34897,0,66,1102,1,1,67,1101,0,674,68,1101,556,0,69,1102,1,2,71,1101,676,0,72,1105,1,73,1,11,24,161373,20,297753,1102,1,55763,66,1102,1,1,67,1101,0,707,68,1101,556,0,69,1101,0,0,71,1101,0,709,72,1106,0,73,1,1753,1101,6389,0,66,1101,0,2,67,1101,0,736,68,1102,1,351,69,1102,1,1,71,1102,740,1,72,1106,0,73,0,0,0,0,255,15461,1102,1,353,66,1102,1,1,67,1101,769,0,68,1102,556,1,69,1102,7,1,71,1101,771,0,72,1105,1,73,1,1,49,48779,23,50263,45,209548,37,172358,24,107582,7,186562,4,47798,1102,1,68171,66,1102,1,2,67,1102,1,812,68,1102,1,302,69,1101,0,1,71,1101,0,816,72,1106,0,73,0,0,0,0,39,299361,1101,82963,0,66,1101,0,1,67,1102,1,845,68,1102,556,1,69,1102,2,1,71,1101,0,847,72,1105,1,73,1,10,15,100379,47,12377,1102,1,24391,66,1102,1,1,67,1102,1,878,68,1102,556,1,69,1101,0,1,71,1101,880,0,72,1105,1,73,1,21,24,53791,1101,100379,0,66,1102,4,1,67,1101,0,909,68,1101,0,302,69,1102,1,1,71,1101,917,0,72,1105,1,73,0,0,0,0,0,0,0,0,47,61885,1102,92363,1,66,1101,0,1,67,1102,946,1,68,1101,556,0,69,1102,1,1,71,1101,0,948,72,1106,0,73,1,160,47,37131,1102,1,90089,66,1101,3,0,67,1101,0,977,68,1102,302,1,69,1101,0,1,71,1102,1,983,72,1105,1,73,0,0,0,0,0,0,39,399148,1102,57557,1,66,1102,1,1,67,1101,1012,0,68,1101,0,556,69,1102,1,1,71,1101,1014,0,72,1106,0,73,1,733,37,86179,1102,72977,1,66,1101,0,1,67,1101,1043,0,68,1102,556,1,69,1101,0,3,71,1101,0,1045,72,1106,0,73,1,5,15,301137,15,401516,47,49508,1101,0,48779,66,1102,4,1,67,1101,0,1078,68,1102,302,1,69,1102,1,1,71,1101,0,1086,72,1106,0,73,0,0,0,0,0,0,0,0,6,587274,1102,99881,1,66,1102,1,1,67,1101,0,1115,68,1101,0,556,69,1102,1,1,71,1102,1,1117,72,1105,1,73,1,-95,37,258537,1102,15461,1,66,1101,0,1,67,1102,1146,1,68,1102,1,556,69,1102,1,6,71,1101,1148,0,72,1105,1,73,1,23892,8,136342,3,182738,3,274107,34,90089,34,180178,34,270267,1102,93253,1,66,1102,1,1,67,1101,0,1187,68,1101,556,0,69,1102,1,1,71,1102,1189,1,72,1105,1,73,1,569,23,100526,1102,1,37997,66,1102,1,1,67,1102,1218,1,68,1101,556,0,69,1102,1,0,71,1102,1220,1,72,1106,0,73,1,1682,1101,0,68399,66,1102,1,1,67,1102,1247,1,68,1102,556,1,69,1102,1,0,71,1101,0,1249,72,1105,1,73,1,1850,1102,52387,1,66,1101,4,0,67,1102,1,1276,68,1102,1,302,69,1102,1,1,71,1102,1,1284,72,1106,0,73,0,0,0,0,0,0,0,0,6,489395,1102,60659,1,66,1102,1,1,67,1102,1,1313,68,1102,1,556,69,1101,1,0,71,1102,1315,1,72,1105,1,73,1,293,7,93281,1101,0,85853,66,1102,1,1,67,1101,0,1344,68,1101,556,0,69,1102,1,1,71,1102,1,1346,72,1105,1,73,1,-183,17,378236,1102,1,97987,66,1102,1,1,67,1101,0,1375,68,1101,556,0,69,1101,0,0,71,1101,1377,0,72,1105,1,73,1,1347,1101,26371,0,66,1101,0,1,67,1101,0,1404,68,1101,0,556,69,1102,1,1,71,1102,1406,1,72,1105,1,73,1,-27,4,71697,1101,0,99251,66,1101,4,0,67,1101,0,1435,68,1102,302,1,69,1101,1,0,71,1101,0,1443,72,1106,0,73,0,0,0,0,0,0,0,0,39,199574,1101,40973,0,66,1102,1,1,67,1102,1,1472,68,1101,0,556,69,1101,1,0,71,1102,1474,1,72,1106,0,73,1,125,15,200758,1102,1,53791,66,1102,5,1,67,1101,0,1503,68,1102,302,1,69,1102,1,1,71,1101,0,1513,72,1105,1,73,0,0,0,0,0,0,0,0,0,0,6,391516,1101,0,31277,66,1102,1,1,67,1101,0,1542,68,1101,556,0,69,1102,1,1,71,1101,0,1544,72,1106,0,73,1,128,23,150789,1101,77291,0,66,1101,1,0,67,1102,1573,1,68,1102,556,1,69,1101,0,2,71,1101,0,1575,72,1106,0,73,1,191,49,97558,49,195116,1102,1,91753,66,1102,1,1,67,1101,0,1606,68,1102,1,556,69,1102,1,1,71,1102,1,1608,72,1106,0,73,1,61,17,94559,1102,99787,1,66,1102,4,1,67,1102,1637,1,68,1101,0,253,69,1102,1,1,71,1101,0,1645,72,1105,1,73,0,0,0,0,0,0,0,0,26,6389,1102,8081,1,66,1101,1,0,67,1101,0,1674,68,1102,556,1,69,1102,1,1,71,1101,1676,0,72,1105,1,73,1,8929,7,279843,1101,0,43997,66,1102,1,1,67,1102,1705,1,68,1101,0,556,69,1102,0,1,71,1101,0,1707,72,1106,0,73,1,1165,1102,1,93281,66,1102,4,1,67,1102,1,1734,68,1101,0,302,69,1102,1,1,71,1102,1,1742,72,1105,1,73,0,0,0,0,0,0,0,0,8,68171,1102,1,86179,66,1101,3,0,67,1102,1771,1,68,1101,302,0,69,1101,0,1,71,1102,1,1777,72,1105,1,73,0,0,0,0,0,0,6,97879,1101,14057,0,66,1102,1,1,67,1101,0,1806,68,1102,1,556,69,1101,0,6,71,1102,1808,1,72,1106,0,73,1,3,49,146337,45,52387,24,215164,11,17987,18,53974,20,99251,1102,1,69389,66,1102,1,1,67,1101,0,1847,68,1102,556,1,69,1102,1,1,71,1101,0,1849,72,1106,0,73,1,109,45,104774,1102,91369,1,66,1101,0,3,67,1102,1878,1,68,1101,302,0,69,1102,1,1,71,1101,1884,0,72,1105,1,73,0,0,0,0,0,0,39,99787,1101,0,17987,66,1101,0,2,67,1101,1913,0,68,1101,302,0,69,1102,1,1,71,1101,0,1917,72,1106,0,73,0,0,0,0,18,26987,1102,90173,1,66,1102,1,1,67,1102,1,1946,68,1101,0,556,69,1102,1,1,71,1101,0,1948,72,1106,0,73,1,-281,45,157161,1101,0,94559,66,1101,0,4,67,1101,0,1977,68,1101,0,302,69,1101,1,0,71,1101,1985,0,72,1106,0,73,0,0,0,0,0,0,0,0,6,293637,1102,13477,1,66,1101,0,1,67,1102,2014,1,68,1101,556,0,69,1101,1,0,71,1102,2016,1,72,1106,0,73,1,514,24,268955,1101,0,97871,66,1101,0,1,67,1102,2045,1,68,1102,556,1,69,1101,0,4,71,1102,2047,1,72,1106,0,73,1,2,17,189118,17,283677,47,24754,47,74262,1102,26987,1,66,1101,0,2,67,1102,2082,1,68,1102,1,302,69,1102,1,1,71,1101,2086,0,72,1106,0,73,0,0,0,0,20,198502,1101,92987,0,66,1101,0,1,67,1102,1,2115,68,1102,1,556,69,1102,0,1,71,1102,2117,1,72,1106,0,73,1,1857,1101,12377,0,66,1102,6,1,67,1101,0,2144,68,1101,302,0,69,1102,1,1,71,1101,2156,0,72,1106,0,73,0,0,0,0,0,0,0,0,0,0,0,0,26,12778,1102,69371,1,66,1102,1,1,67,1102,2185,1,68,1101,556,0,69,1102,2,1,71,1102,1,2187,72,1106,0,73,1,1889,20,397004,4,23899,1102,1,52861,66,1102,1,1,67,1101,0,2218,68,1101,556,0,69,1102,1,1,71,1102,2220,1,72,1105,1,73,1,599,7,373124,1101,23899,0,66,1102,1,3,67,1102,1,2249,68,1101,0,302,69,1102,1,1,71,1102,2255,1,72,1106,0,73,0,0,0,0,0,0,3,91369 2 | -------------------------------------------------------------------------------- /inputs/input24.txt: -------------------------------------------------------------------------------- 1 | #..#. 2 | #.#.# 3 | ...#. 4 | ....# 5 | #.#.# 6 | -------------------------------------------------------------------------------- /inputs/input25.txt: -------------------------------------------------------------------------------- 1 | 109,4797,21102,1,3124,1,21101,0,13,0,1105,1,1424,21101,0,166,1,21101,0,24,0,1105,1,1234,21101,0,31,0,1106,0,1984,1105,1,13,6,4,3,2,52,51,21,4,28,56,55,3,19,-9,-10,47,89,88,90,90,6,77,73,85,71,1,76,68,63,65,22,-27,70,76,81,87,5,105,105,107,108,95,4,97,92,109,109,5,110,105,110,108,95,4,115,96,109,109,13,-3,59,101,85,92,97,13,84,80,92,78,34,-15,26,-16,46,88,72,79,84,0,72,76,-3,85,74,79,75,-8,64,68,75,57,65,70,64,66,72,8,-41,32,-22,56,77,82,-4,60,76,62,70,-2,74,-11,55,52,68,67,73,56,60,52,-20,44,56,66,-24,48,58,42,49,54,-16,-53,10,0,56,99,96,95,82,94,83,45,-9,23,-13,61,85,88,74,71,82,73,79,73,89,67,65,-4,62,73,70,69,56,68,57,2,-35,24,-14,64,85,90,4,70,67,79,7,83,-2,68,75,-5,78,65,57,75,-10,76,53,76,0,-37,31,-21,57,78,83,-3,64,74,72,0,76,-9,73,58,57,-13,70,57,49,67,-18,54,64,48,55,-23,48,44,56,42,-14,-51,14,-4,74,95,100,14,97,77,86,79,9,92,79,75,5,27,-17,61,82,87,1,68,78,76,4,80,-5,66,58,78,60,-10,73,60,52,70,-15,57,67,51,58,-6,-43,14,-4,74,95,100,14,81,94,90,90,9,92,79,75,5,60,-50,23,42,38,-32,38,39,30,42,47,-38,30,36,28,25,41,38,34,31,18,23,29,19,33,-52,20,29,-55,27,27,27,8,15,-61,22,16,-64,24,13,18,-54,-69,-70,-14,7,12,-74,-8,-11,1,-71,5,-80,-4,-3,3,-15,-84,-85,-109,29,-19,59,80,85,-1,82,62,71,64,-6,77,64,60,-10,62,66,57,59,63,57,67,51,-19,56,58,57,57,-10,-47,44,-34,39,58,54,-16,60,61,57,64,48,56,-23,52,40,60,38,-28,44,53,-31,55,32,55,-35,48,42,41,-39,32,38,42,-42,-44,12,33,38,-48,28,19,25,32,-52,-76,-77,59,-49,13,55,-30,42,51,-33,49,50,32,31,31,39,36,48,-42,24,35,32,34,29,21,35,19,25,37,-53,14,10,26,18,-57,-59,-3,18,23,-63,1,17,3,-67,1,-4,14,-2,6,-73,-8,14,-76,-12,-78,-40,2,4,-13,-82,-106,-107,35,-25,53,74,79,0,74,60,-10,65,53,72,64,52,56,52,50,-19,53,57,62,56,-24,58,54,38,39,40,-29,-31,2,56,35,-34,-58,-59,138,-128,-74,-108,-33,-31,-26,-44,-101,-114,-33,-37,-51,-39,-35,-47,-54,-122,-37,-45,-52,-59,-58,-128,-46,-65,-42,-49,-133,-132,-102,-60,-68,-56,-55,-139,-141,-106,-61,-65,-72,-78,-64,-148,-70,-72,-151,-68,-81,-81,-72,-156,-74,-86,-86,-80,-161,-97,-81,-95,-165,-94,-98,-103,-83,-97,-102,-90,-173,-90,-103,-111,-99,-178,-95,-108,-112,-182,-115,-115,-101,-117,-120,-104,-120,-122,-191,-106,-128,-118,-110,-127,-196,-196,-199,-135,-123,-134,-203,-115,-126,-121,-207,-143,-127,-141,-211,-143,-139,-145,-148,-132,-148,-150,-219,-154,-156,-155,-148,-224,-141,-147,-227,-144,-157,-161,-231,-165,-161,-165,-168,-161,-157,-159,-166,-162,-157,-228,-265,138,-128,-74,-108,-33,-31,-26,-44,-101,-114,-33,-37,-51,-39,-35,-47,-54,-122,-37,-45,-52,-59,-58,-128,-46,-65,-42,-49,-133,-132,-102,-60,-68,-56,-55,-139,-141,-106,-61,-65,-72,-78,-64,-148,-70,-72,-151,-68,-81,-81,-72,-156,-74,-86,-86,-80,-161,-97,-81,-95,-165,-90,-94,-97,-97,-86,-102,-90,-173,-90,-103,-111,-99,-178,-95,-108,-112,-182,-115,-115,-101,-117,-120,-104,-120,-122,-191,-106,-128,-118,-110,-127,-196,-196,-199,-135,-123,-134,-203,-115,-126,-121,-207,-143,-127,-141,-211,-143,-139,-145,-148,-132,-148,-150,-219,-154,-156,-155,-148,-224,-141,-147,-227,-144,-157,-161,-231,-165,-161,-165,-168,-161,-157,-159,-166,-162,-157,-228,-265,263,-253,-199,-233,-158,-156,-151,-169,-226,-239,-158,-162,-176,-164,-160,-172,-179,-247,-162,-170,-177,-184,-183,-253,-171,-190,-167,-174,-258,-257,-227,-183,-197,-187,-175,-182,-193,-184,-268,-202,-191,-194,-192,-197,-205,-191,-207,-276,-278,-222,-201,-196,-282,-206,-219,-196,-286,-207,-206,-210,-223,-222,-223,-225,-280,-293,-296,-232,-220,-231,-300,-212,-223,-218,-304,-236,-228,-223,-239,-227,-310,-227,-240,-244,-314,-248,-237,-250,-243,-239,-247,-237,-308,-345,-273,-260,-248,-243,-263,-329,-252,-252,-248,-260,-267,-266,-253,-337,-249,-260,-255,-259,-342,-260,-267,-280,-270,-271,-348,-281,-268,-272,-279,-285,-342,-355,-280,-278,-279,-284,-277,-361,-282,-278,-274,-275,-290,-298,-300,-369,-300,-292,-290,-373,-309,-375,-299,-298,-301,-310,-302,-297,-370,-383,-302,-316,-321,-311,-315,-299,-321,-308,-392,-306,-322,-330,-312,-397,-326,-334,-317,-401,-330,-338,-324,-325,-337,-329,-339,-341,-398,-411,-347,-335,-346,-415,-334,-352,-350,-346,-341,-338,-422,-334,-345,-340,-344,-427,-345,-357,-357,-351,-432,-365,-361,-353,-367,-370,-354,-363,-351,-427,-464,-441,-397,-373,-434,-447,-376,-380,-374,-375,-373,-452,-454,-398,-377,-372,-458,-376,-388,-382,-377,-387,-396,-465,-400,-398,-468,-404,-404,-395,-403,-473,-390,-396,-476,-406,-409,-395,-480,-408,-404,-483,-418,-396,-486,-403,-399,-409,-417,-413,-421,-493,37,-5,73,71,-8,75,62,58,-12,62,55,74,64,48,50,-19,45,63,-22,61,48,44,-26,50,37,44,48,-31,33,40,48,41,43,30,37,-25,-38,-63,0,0,109,7,21102,1,0,-2,22208,-2,-5,-1,1205,-1,1169,22202,-2,-4,1,22201,1,-6,1,21202,-2,1,2,21102,1162,1,0,2106,0,-3,21201,-2,1,-2,1105,1,1136,109,-7,2105,1,0,109,6,1201,-5,0,1181,21002,0,1,-2,21101,0,0,-3,21201,-5,1,-5,22208,-3,-2,-1,1205,-1,1229,2201,-5,-3,1204,21001,0,0,1,21202,-3,1,2,22101,0,-2,3,21101,0,1222,0,2105,1,-4,21201,-3,1,-3,1106,0,1192,109,-6,2105,1,0,109,2,22102,1,-1,1,21102,1256,1,2,21101,0,1251,0,1105,1,1174,109,-2,2105,1,0,109,5,22201,-4,-3,-1,22201,-2,-1,-1,204,-1,109,-5,2105,1,0,109,3,2101,0,-2,1280,1006,0,1303,104,45,104,32,1201,-1,66,1291,21001,0,0,1,21101,1301,0,0,1105,1,1234,104,10,109,-3,2106,0,0,0,0,109,2,1201,-1,0,1309,1102,0,1,1308,21101,4601,0,1,21102,13,1,2,21101,0,4,3,21102,1,1353,4,21101,1343,0,0,1105,1,1130,21001,1308,0,-1,109,-2,2106,0,0,97,109,3,2101,0,-2,1360,20008,0,1309,-1,1206,-1,1419,1005,1308,1398,1102,1,1,1308,21008,1309,-1,-1,1206,-1,1387,21101,0,106,1,1105,1,1391,21102,92,1,1,21102,1398,1,0,1106,0,1234,104,45,104,32,1201,-2,1,1407,21002,0,1,1,21101,1417,0,0,1105,1,1234,104,10,109,-3,2106,0,0,109,3,2102,1,-2,1128,21101,0,34,1,21102,1,1441,0,1106,0,1234,1001,1128,0,1447,20102,1,0,1,21102,1456,1,0,1106,0,1234,21102,1,41,1,21102,1467,1,0,1106,0,1234,1001,1128,1,1472,21002,0,1,1,21102,1,1482,0,1105,1,1234,21101,0,46,1,21101,1493,0,0,1105,1,1234,21001,1128,3,1,21102,1,4,2,21101,0,1,3,21102,1,1273,4,21101,1516,0,0,1106,0,1130,21001,1128,0,1,21101,1527,0,0,1105,1,1310,1001,1128,2,1532,21001,0,0,-1,1206,-1,1545,21102,1545,1,0,2105,1,-1,109,-3,2105,1,0,109,0,99,109,2,1101,0,0,1550,21101,4601,0,1,21102,13,1,2,21102,4,1,3,21101,1664,0,4,21102,1,1582,0,1106,0,1130,2,2486,1352,1551,1102,0,1,1552,20102,1,1550,1,21102,33,1,2,21102,1702,1,3,21101,0,1609,0,1106,0,2722,21007,1552,0,-1,1205,-1,1630,20107,0,1552,-1,1205,-1,1637,21101,0,1630,0,1105,1,1752,21102,1,548,1,1105,1,1641,21101,0,687,1,21101,1648,0,0,1105,1,1234,21101,4457,0,1,21101,1659,0,0,1106,0,1424,109,-2,2106,0,0,109,4,21202,-2,-1,-2,1202,-3,1,1675,21008,0,-1,-1,1206,-1,1697,1201,-3,2,1687,20101,-27,0,-3,22201,-3,-2,-3,2001,1550,-3,1550,109,-4,2105,1,0,109,5,21008,1552,0,-1,1206,-1,1747,1201,-3,1901,1717,20101,0,0,-2,1205,-4,1736,20207,-2,1551,-1,1205,-1,1747,1102,-1,1,1552,1105,1,1747,22007,1551,-2,-1,1205,-1,1747,1102,1,1,1552,109,-5,2105,1,0,109,1,21101,0,826,1,21102,1,1765,0,1106,0,1234,20101,0,1550,1,21101,0,1776,0,1105,1,2863,21101,1090,0,1,21102,1,1787,0,1106,0,1234,99,1106,0,1787,109,-1,2106,0,0,109,1,21102,512,1,1,21101,0,1809,0,1105,1,1234,99,1106,0,1809,109,-1,2105,1,0,109,1,1101,1,0,1129,109,-1,2106,0,0,109,1,21102,377,1,1,21101,0,1842,0,1106,0,1234,1106,0,1831,109,-1,2106,0,0,109,1,21101,407,0,1,21101,0,1863,0,1106,0,1234,99,1106,0,1863,109,-1,2105,1,0,109,1,21101,0,452,1,21102,1885,1,0,1106,0,1234,99,1105,1,1885,109,-1,2105,1,0,1941,1947,1953,1958,1965,1972,1978,8193,8450,8357,8284,8319,7912,8091,8282,8635,8554,8405,8490,7916,7961,8297,7877,8314,8235,8233,8300,8038,7889,8158,8067,8098,8343,8629,7879,7943,8021,7975,8607,8130,2281,2468,2418,2450,2487,2125,2505,5,95,108,104,104,23,5,96,91,108,108,1,4,101,105,112,3,6,104,104,106,107,94,-1,6,109,104,109,107,94,-1,5,111,91,100,93,23,5,114,95,108,108,1,109,3,21102,1993,1,0,1105,1,2634,1006,1129,2010,21101,0,316,1,21101,0,2007,0,1106,0,1234,1105,1,2076,21102,0,1,-1,1201,-1,1894,2019,21002,0,1,1,21101,0,0,2,21102,1,0,3,21101,0,2037,0,1105,1,2525,1206,1,2054,1201,-1,1934,2050,21101,0,2051,0,105,1,0,1106,0,2076,21201,-1,1,-1,21207,-1,7,-2,1205,-2,2014,21102,1,177,1,21102,2076,1,0,1106,0,1234,109,-3,2106,0,0,109,3,2001,1128,-2,2089,20101,0,0,-1,1205,-1,2108,21101,0,201,1,21102,2105,1,0,1106,0,1234,1105,1,2119,22102,1,-1,1,21102,1,2119,0,1106,0,1424,109,-3,2105,1,0,0,109,1,1102,1,0,2124,21102,1,4601,1,21102,1,13,2,21101,0,4,3,21102,1,2173,4,21101,0,2154,0,1106,0,1130,1005,2124,2168,21102,226,1,1,21102,2168,1,0,1105,1,1234,109,-1,2105,1,0,109,3,1005,2124,2275,1201,-2,0,2183,20008,0,1128,-1,1206,-1,2275,1201,-2,1,2195,20102,1,0,-1,22102,1,-1,1,21101,5,0,2,21102,1,1,3,21101,0,2216,0,1106,0,2525,1206,1,2275,21101,258,0,1,21102,1,2230,0,1106,0,1234,22101,0,-1,1,21101,2241,0,0,1105,1,1234,104,46,104,10,1101,1,0,2124,1201,-2,0,2256,1102,1,-1,0,1201,-2,3,2262,21001,0,0,-1,1206,-1,2275,21102,2275,1,0,2105,1,-1,109,-3,2105,1,0,0,109,1,1101,0,0,2280,21101,4601,0,1,21101,13,0,2,21102,1,4,3,21102,2329,1,4,21101,0,2310,0,1106,0,1130,1005,2280,2324,21101,0,273,1,21102,1,2324,0,1105,1,1234,109,-1,2105,1,0,109,3,1005,2280,2413,1201,-2,0,2339,21008,0,-1,-1,1206,-1,2413,1201,-2,1,2351,20101,0,0,-1,22102,1,-1,1,21101,5,0,2,21101,1,0,3,21101,0,2372,0,1106,0,2525,1206,1,2413,21102,301,1,1,21101,2386,0,0,1106,0,1234,21202,-1,1,1,21101,2397,0,0,1106,0,1234,104,46,104,10,1102,1,1,2280,1201,-2,0,2412,102,1,1128,0,109,-3,2106,0,0,109,1,21102,1,-1,1,21101,0,2431,0,1106,0,1310,1205,1,2445,21102,133,1,1,21101,2445,0,0,1105,1,1234,109,-1,2105,1,0,109,1,21102,3,1,1,21102,1,2463,0,1105,1,2081,109,-1,2106,0,0,109,1,21101,0,4,1,21101,0,2481,0,1106,0,2081,109,-1,2106,0,0,88,109,1,21102,5,1,1,21102,1,2500,0,1106,0,2081,109,-1,2105,1,0,109,1,21102,6,1,1,21101,2518,0,0,1106,0,2081,109,-1,2105,1,0,0,0,109,5,1202,-3,1,2523,1102,1,1,2524,22102,1,-4,1,21102,1,2585,2,21101,2550,0,0,1106,0,1174,1206,-2,2576,2102,1,-4,2558,2001,0,-3,2566,101,3094,2566,2566,21008,0,-1,-1,1205,-1,2576,1102,1,0,2524,21001,2524,0,-4,109,-5,2106,0,0,109,5,22201,-4,-3,-4,22201,-4,-2,-4,21208,-4,10,-1,1206,-1,2606,21102,-1,1,-4,201,-3,2523,2615,1001,2615,3094,2615,21002,0,1,-1,22208,-4,-1,-1,1205,-1,2629,1101,0,0,2524,109,-5,2106,0,0,109,4,21101,3094,0,1,21102,1,30,2,21101,1,0,3,21101,2706,0,4,21102,2659,1,0,1105,1,1130,21102,1,0,-3,203,-2,21208,-2,10,-1,1205,-1,2701,21207,-2,0,-1,1205,-1,2663,21207,-3,29,-1,1206,-1,2663,2101,3094,-3,2693,2101,0,-2,0,21201,-3,1,-3,1105,1,2663,109,-4,2105,1,0,109,2,2101,0,-1,2715,1101,-1,0,0,109,-2,2105,1,0,0,109,5,2102,1,-2,2721,21207,-4,0,-1,1206,-1,2739,21101,0,0,-4,21202,-4,1,1,21201,-3,0,2,21102,1,1,3,21101,0,2758,0,1105,1,2763,109,-5,2106,0,0,109,6,21207,-4,1,-1,1206,-1,2786,22207,-5,-3,-1,1206,-1,2786,22102,1,-5,-5,1105,1,2858,22102,1,-5,1,21201,-4,-1,2,21202,-3,2,3,21102,1,2805,0,1106,0,2763,21202,1,1,-5,21101,1,0,-2,22207,-5,-3,-1,1206,-1,2824,21101,0,0,-2,22202,-3,-2,-3,22107,0,-4,-1,1206,-1,2850,22101,0,-2,1,21201,-4,-1,2,21102,1,2850,0,105,1,2721,21202,-3,-1,-3,22201,-5,-3,-5,109,-6,2105,1,0,109,3,21208,-2,0,-1,1205,-1,2902,21207,-2,0,-1,1205,-1,2882,1105,1,2888,104,45,21202,-2,-1,-2,21202,-2,1,1,21102,1,2899,0,1105,1,2909,1106,0,2904,104,48,109,-3,2105,1,0,109,4,21201,-3,0,1,21102,10,1,2,21101,0,2926,0,1105,1,3010,21202,1,1,-2,22101,0,2,-1,1206,-2,2948,21201,-2,0,1,21101,2948,0,0,1106,0,2909,22101,48,-1,-1,204,-1,109,-4,2106,0,0,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648,4294967296,8589934592,17179869184,34359738368,68719476736,137438953472,274877906944,549755813888,1099511627776,2199023255552,4398046511104,8796093022208,17592186044416,35184372088832,70368744177664,140737488355328,281474976710656,562949953421312,1125899906842624,109,8,21102,0,1,-4,21102,1,0,-3,21102,51,1,-2,21201,-2,-1,-2,1201,-2,2959,3034,20101,0,0,-1,21202,-3,2,-3,22207,-7,-1,-5,1205,-5,3059,21201,-3,1,-3,22102,-1,-1,-5,22201,-7,-5,-7,22207,-3,-6,-5,1205,-5,3078,22102,-1,-6,-5,22201,-3,-5,-3,22201,-1,-4,-4,1205,-2,3024,21202,-4,1,-7,21201,-3,0,-6,109,-8,2105,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3131,3143,0,3317,3372,0,3252,11,61,105,95,94,17,50,97,83,78,79,83,108,-19,2,7,-79,-9,-2,2,-83,-11,-7,-86,-3,-16,-7,-11,-6,-21,-21,-94,-30,-96,-25,-19,-23,-31,-101,-29,-25,-104,-21,-34,-38,-108,-39,-34,-32,-33,-31,-114,-43,-47,-35,-49,-105,-120,-69,-43,-123,-49,-56,-57,-47,-128,-40,-51,-46,-50,-133,-51,-63,-63,-57,-138,-69,-58,-62,-65,-143,-79,-69,-63,-68,-148,-79,-68,-82,-83,-63,-81,-77,-85,-145,-158,-75,-88,-92,-162,-91,-85,-89,-97,-167,-96,-104,-87,-171,-106,-104,-105,-97,-176,-94,-109,-114,-104,-112,-114,-169,3259,3282,0,4365,3124,0,3817,22,65,74,90,87,6,41,86,76,88,70,0,44,63,70,74,79,63,71,57,69,57,58,34,39,81,-4,60,74,73,61,56,72,72,-12,71,65,-15,50,52,-18,68,59,61,53,50,54,46,-26,51,51,53,47,34,44,43,55,-21,3324,3331,0,3543,0,3124,0,6,59,107,91,88,90,90,40,38,70,68,58,-12,66,56,-15,68,55,51,-19,47,44,44,50,54,44,58,56,-28,54,39,38,45,-33,50,44,-36,35,27,47,29,-41,38,36,43,24,36,-33,3379,3388,0,0,3889,3468,3124,8,59,102,104,103,93,87,97,99,79,5,24,20,-50,26,17,31,11,21,-56,30,7,17,16,22,-62,2,14,3,-66,17,4,0,-70,6,-3,11,-9,1,-76,-7,-2,0,-1,1,-82,-18,-2,-16,-86,-4,-12,-16,-19,-19,-8,-17,-5,-95,-28,-24,-28,-29,-31,-19,-33,-25,-20,-105,-39,-28,-32,-30,-28,-28,-98,-113,-67,-33,-116,-52,-36,-50,-120,-37,-50,-54,-35,-94,3475,3487,0,3372,3753,0,3694,11,72,87,92,87,95,83,84,14,57,77,77,55,34,55,60,-26,56,41,40,-30,38,54,40,34,34,42,30,31,-39,32,28,40,26,-44,34,24,-47,32,33,29,33,27,31,35,25,13,-57,22,20,16,28,15,6,18,-65,2,2,15,4,1,7,-72,14,5,7,-1,-63,3550,3562,0,0,3623,3317,0,11,68,86,102,87,99,102,80,98,92,94,100,60,24,43,39,51,37,-33,31,47,33,-37,27,-39,30,28,45,-43,40,24,30,22,35,18,29,29,17,30,-27,-55,28,15,11,30,-53,21,7,-63,1,11,10,-67,-2,10,6,13,-3,-5,-74,-7,3,10,0,-67,-80,3,-10,-4,1,-14,-14,-73,3630,3642,0,0,0,0,3543,11,58,98,90,91,95,85,84,96,86,90,82,51,38,59,64,-22,60,45,44,-26,38,-28,58,42,42,52,36,32,44,29,45,30,-39,47,32,42,29,-44,35,30,18,30,34,-50,19,27,29,-54,-4,24,25,15,19,11,7,20,16,9,3,-66,19,-50,-55,3701,3724,0,0,3468,0,0,22,50,88,92,7,41,77,83,70,81,77,65,83,67,-3,34,74,79,71,76,56,63,67,28,55,82,79,70,72,78,85,9,-4,68,78,0,75,-9,73,73,61,63,62,-15,71,62,64,56,53,57,49,-9,3760,3768,0,0,0,3939,3468,7,76,108,102,104,86,91,88,48,36,55,51,-19,46,58,66,46,59,-25,48,58,55,55,-30,36,47,45,50,30,37,41,-38,38,39,41,27,-43,22,34,42,22,35,-35,-50,-51,-2,16,13,30,26,26,15,27,9,15,27,-49,3824,3833,0,0,3252,0,0,8,72,88,105,104,85,90,87,100,55,29,48,44,63,-20,54,40,-30,34,-32,43,39,49,48,39,31,-39,44,46,31,40,40,44,-46,18,30,19,-50,32,32,12,28,29,17,21,13,-59,24,18,-62,13,15,14,9,-67,-3,7,6,-71,-7,3,-1,0,-7,-63,3896,3904,0,0,4308,0,3372,7,76,108,88,88,97,89,102,34,48,66,69,73,62,62,61,73,3,72,61,77,55,53,-2,-17,34,53,49,68,-15,59,45,-25,39,49,48,-29,39,46,48,51,55,-21,3946,3957,0,3753,4035,0,4235,10,68,86,106,92,89,82,100,88,93,91,77,6,38,18,36,36,33,-25,-52,-2,30,27,9,21,10,10,8,-47,-62,-15,12,4,-1,16,1,-69,13,14,8,7,2,14,-76,0,-9,-14,3,4,0,-14,-7,-16,-8,-3,-5,-89,-20,-9,-13,-16,-94,-25,-23,-27,-14,-10,-100,-18,-18,-38,-22,-22,-106,-23,-29,-109,-28,-42,-45,-48,-38,-42,-50,-35,-53,-35,-51,-107,4042,4050,0,0,4077,0,3939,7,68,97,107,89,93,89,97,26,43,91,73,85,91,85,72,72,76,68,3,78,-6,63,74,60,59,79,57,0,54,67,57,52,50,-5,4084,4093,0,0,0,4166,4035,8,75,96,89,96,20,53,83,106,72,11,44,38,37,35,37,38,36,-48,17,29,33,20,-53,-4,14,12,-44,-12,20,23,8,6,-63,-14,4,7,11,0,0,-1,11,-72,4,-5,-7,-3,-10,-5,-1,-11,-81,-17,-5,-16,-85,-4,-18,-17,-4,-14,-26,-10,-93,-12,-26,-23,-19,-30,-30,-31,-19,-102,-26,-35,-37,-33,-40,-35,-31,-41,-97,4173,4194,0,4077,0,0,0,20,51,84,80,93,8,62,88,70,84,83,75,79,71,-1,33,66,74,79,63,75,40,32,70,77,-11,57,63,69,54,-16,51,61,-19,69,58,63,-23,63,57,39,53,-28,51,52,38,51,36,44,49,47,-37,41,39,-40,43,30,26,-44,26,33,-16,4242,4251,0,0,3939,0,0,8,64,102,98,100,88,88,85,92,56,27,54,51,42,51,49,39,-31,51,36,35,42,47,-37,46,40,-40,31,23,43,25,-45,30,22,22,35,-50,22,32,-53,25,23,-56,27,14,10,-60,-22,11,2,14,19,-66,-28,14,4,-2,-71,11,-4,10,9,-3,1,-7,-65,4315,4329,0,0,0,0,3889,13,54,100,86,103,15,63,98,77,93,94,78,90,90,35,49,68,64,-6,59,61,59,73,-11,53,69,55,-15,49,59,58,-19,64,58,57,-23,59,52,39,49,48,-29,40,48,50,-33,55,44,49,-23,4372,4380,0,4457,0,3252,0,7,65,89,99,98,108,85,108,76,8,27,27,36,-48,16,32,18,13,-53,18,10,27,-57,8,10,9,17,-62,16,16,19,7,10,5,21,-1,-3,-72,-3,5,7,-76,6,1,-2,-11,3,-10,-10,-6,-14,-59,-87,1,-10,-5,-84,-10,-24,-94,-21,-11,-14,-14,-99,-22,-22,-18,-103,-23,-20,-33,-23,-39,-109,-27,-26,-30,-44,-114,-28,-44,-52,-34,-105,4464,4484,0,0,0,4365,4556,19,64,81,78,95,91,81,91,95,5,39,75,71,68,75,79,77,70,74,79,71,2,38,-41,42,29,25,-45,32,22,40,35,-50,31,27,26,23,-43,-56,8,-58,21,22,8,21,20,21,17,3,-54,15,0,8,12,1,11,-1,11,-7,-77,-8,-3,-1,-2,0,-83,3,-12,-10,-11,-88,-3,-21,-9,-19,-23,-5,-95,-7,-18,-13,-17,-100,-28,-34,-34,-26,-21,-33,-23,-19,-95,4563,4588,1553,0,4457,0,0,24,56,89,75,88,87,88,84,70,13,50,67,75,79,68,78,66,78,60,-10,27,64,66,65,67,12,53,97,83,93,105,105,87,91,83,25,24,23,3889,4653,27,1796,3753,4664,4124,0,3372,4673,8388637,0,4035,4682,262174,0,3252,4687,31,1850,4077,4699,32,1818,4365,4719,33,1829,3543,4733,36,0,3468,4746,16777251,0,3694,4758,36,1872,3623,4766,101,0,4235,4780,39,0,3317,4792,2147483687,0,10,91,104,87,84,98,86,16,95,93,81,8,89,106,106,90,102,92,101,92,8,103,105,100,86,97,88,96,101,4,95,92,101,94,11,98,99,95,102,86,94,15,90,78,98,76,19,84,85,76,88,93,8,76,82,74,71,87,84,80,77,64,69,75,65,79,13,92,96,87,89,93,87,97,81,11,86,88,87,87,12,103,99,83,84,85,15,86,82,77,95,79,91,11,91,89,102,102,90,102,84,14,85,77,95,7,105,96,102,106,100,98,102,13,102,87,94,89,82,93,91,80,96,77,93,87,89,11,91,99,98,86,17,98,80,98,86,91,89,4,111,92,104,93 2 | --------------------------------------------------------------------------------