├── .github └── workflows │ └── tests.yml ├── .gitignore ├── LICENSE.md ├── README.md ├── build.sbt ├── project └── build.properties └── src ├── main ├── resources │ ├── AdventOfCode2015 │ │ ├── Day01.txt │ │ ├── Day02.txt │ │ ├── Day03.txt │ │ ├── Day04.txt │ │ ├── Day05.txt │ │ ├── Day06.txt │ │ ├── Day07.txt │ │ ├── Day08.txt │ │ ├── Day09.txt │ │ ├── Day10.txt │ │ ├── Day11.txt │ │ ├── Day12.txt │ │ ├── Day13.txt │ │ ├── Day14.txt │ │ ├── Day15.txt │ │ ├── Day16.txt │ │ ├── Day17.txt │ │ ├── Day18.txt │ │ ├── Day19.txt │ │ ├── Day20.txt │ │ ├── Day21.txt │ │ ├── Day22.txt │ │ ├── Day23.txt │ │ ├── Day24.txt │ │ └── Day25.txt │ ├── AdventOfCode2016 │ │ ├── Day01.txt │ │ ├── Day02.txt │ │ ├── Day03.txt │ │ ├── Day04.txt │ │ ├── Day05.txt │ │ ├── Day06.txt │ │ ├── Day07.txt │ │ ├── Day08.txt │ │ ├── Day09.txt │ │ ├── Day10.txt │ │ ├── Day11.txt │ │ ├── Day12.txt │ │ ├── Day13.txt │ │ ├── Day14.txt │ │ ├── Day15.txt │ │ ├── Day16.txt │ │ ├── Day17.txt │ │ ├── Day18.txt │ │ ├── Day19.txt │ │ ├── Day20.txt │ │ ├── Day21.txt │ │ ├── Day22.txt │ │ ├── Day23.txt │ │ ├── Day24.txt │ │ └── Day25.txt │ ├── AdventOfCode2017 │ │ ├── Day01.txt │ │ ├── Day02.txt │ │ ├── Day03.txt │ │ ├── Day04.txt │ │ ├── Day05.txt │ │ ├── Day06.txt │ │ ├── Day07.txt │ │ ├── Day08.txt │ │ ├── Day09.txt │ │ ├── Day10.txt │ │ ├── Day11.txt │ │ ├── Day12.txt │ │ ├── Day13.txt │ │ ├── Day14.txt │ │ ├── Day15.txt │ │ ├── Day16.txt │ │ ├── Day17.txt │ │ ├── Day18.txt │ │ ├── Day19.txt │ │ ├── Day20.txt │ │ ├── Day21.txt │ │ ├── Day22.txt │ │ ├── Day23.txt │ │ ├── Day24.txt │ │ └── Day25.txt │ ├── AdventOfCode2018 │ │ ├── Day01.txt │ │ ├── Day02.txt │ │ ├── Day03.txt │ │ ├── Day04.txt │ │ ├── Day05.txt │ │ ├── Day06.txt │ │ ├── Day07.txt │ │ ├── Day08.txt │ │ ├── Day09.txt │ │ ├── Day10.txt │ │ ├── Day11.txt │ │ ├── Day12.txt │ │ ├── Day13.txt │ │ ├── Day14.txt │ │ ├── Day15.txt │ │ ├── Day16.txt │ │ ├── Day17.txt │ │ ├── Day18.txt │ │ ├── Day19.txt │ │ ├── Day20.txt │ │ ├── Day21.txt │ │ ├── Day22.txt │ │ ├── Day23.txt │ │ ├── Day24.txt │ │ └── Day25.txt │ ├── AdventOfCode2019 │ │ ├── Day01.txt │ │ ├── Day02.txt │ │ ├── Day03.txt │ │ ├── Day04.txt │ │ ├── Day05.txt │ │ ├── Day06.txt │ │ ├── Day07.txt │ │ ├── Day08.txt │ │ ├── Day09.txt │ │ ├── Day10.txt │ │ ├── Day11.txt │ │ ├── Day12.txt │ │ ├── Day13.txt │ │ ├── Day14.txt │ │ ├── Day15.txt │ │ ├── Day16.txt │ │ ├── Day17.txt │ │ ├── Day18.txt │ │ ├── Day19.txt │ │ ├── Day20.txt │ │ ├── Day21.txt │ │ ├── Day22.txt │ │ ├── Day23.txt │ │ ├── Day24.txt │ │ └── Day25.txt │ ├── AdventOfCode2020 │ │ ├── Day01.txt │ │ ├── Day02.txt │ │ ├── Day03.txt │ │ ├── Day04.txt │ │ ├── Day05.txt │ │ ├── Day06.txt │ │ ├── Day07.txt │ │ ├── Day08.txt │ │ ├── Day09.txt │ │ ├── Day10.txt │ │ ├── Day11.txt │ │ ├── Day12.txt │ │ ├── Day13.txt │ │ ├── Day14.txt │ │ ├── Day15.txt │ │ ├── Day16.txt │ │ ├── Day17.txt │ │ ├── Day18.txt │ │ ├── Day19.txt │ │ ├── Day20.txt │ │ ├── Day21.txt │ │ ├── Day22.txt │ │ ├── Day23.txt │ │ ├── Day24.txt │ │ └── Day25.txt │ ├── AdventOfCode2021 │ │ ├── Day01.txt │ │ ├── Day02.txt │ │ ├── Day03.txt │ │ ├── Day04.txt │ │ ├── Day05.txt │ │ ├── Day06.txt │ │ ├── Day07.txt │ │ ├── Day08.txt │ │ ├── Day09.txt │ │ ├── Day10.txt │ │ ├── Day11.txt │ │ ├── Day12.txt │ │ ├── Day13.txt │ │ ├── Day14.txt │ │ ├── Day15.txt │ │ ├── Day16.txt │ │ ├── Day17.txt │ │ ├── Day18.txt │ │ ├── Day19.txt │ │ ├── Day20.txt │ │ ├── Day21.txt │ │ ├── Day22.txt │ │ ├── Day23.txt │ │ ├── Day24.txt │ │ └── Day25.txt │ └── AdventOfCode2022 │ │ ├── Day01.txt │ │ ├── Day02.txt │ │ ├── Day03.txt │ │ ├── Day04.txt │ │ ├── Day05.txt │ │ ├── Day06.txt │ │ ├── Day07.txt │ │ ├── Day08.txt │ │ ├── Day09.txt │ │ ├── Day10.txt │ │ ├── Day11.txt │ │ ├── Day12.txt │ │ ├── Day13.txt │ │ ├── Day14.txt │ │ ├── Day15.txt │ │ ├── Day16.txt │ │ ├── Day17.txt │ │ ├── Day18.txt │ │ ├── Day19.txt │ │ ├── Day20.txt │ │ ├── Day21.txt │ │ ├── Day22.txt │ │ ├── Day23.txt │ │ ├── Day24.txt │ │ └── Day25.txt └── scala │ ├── AdventOfCode2015 │ ├── Day01.scala │ ├── Day02.scala │ ├── Day03.scala │ ├── Day04.scala │ ├── Day05.scala │ ├── Day06.scala │ ├── Day07.scala │ ├── Day08.scala │ ├── Day09.scala │ ├── Day10.scala │ ├── Day11.scala │ ├── Day12.scala │ ├── Day13.scala │ ├── Day14.scala │ ├── Day15.scala │ ├── Day16.scala │ ├── Day17.scala │ ├── Day18.scala │ ├── Day19.scala │ ├── Day20.scala │ ├── Day21.scala │ ├── Day22.scala │ ├── Day23.scala │ ├── Day24.scala │ └── Day25.scala │ ├── AdventOfCode2016 │ ├── Day01.scala │ ├── Day02.scala │ ├── Day03.scala │ ├── Day04.scala │ ├── Day05.scala │ ├── Day06.scala │ ├── Day07.scala │ ├── Day08.scala │ ├── Day09.scala │ ├── Day10.scala │ ├── Day11.scala │ ├── Day12.scala │ ├── Day13.scala │ ├── Day14.scala │ ├── Day15.scala │ ├── Day16.scala │ ├── Day17.scala │ ├── Day18.scala │ ├── Day19.scala │ ├── Day20.scala │ ├── Day21.scala │ ├── Day22.scala │ ├── Day23.scala │ ├── Day24.scala │ └── Day25.scala │ ├── AdventOfCode2017 │ ├── Day01.scala │ ├── Day02.scala │ ├── Day03.scala │ ├── Day04.scala │ ├── Day05.scala │ ├── Day06.scala │ ├── Day07.scala │ ├── Day08.scala │ ├── Day09.scala │ ├── Day10.scala │ ├── Day11.scala │ ├── Day12.scala │ ├── Day13.scala │ ├── Day14.scala │ ├── Day15.scala │ ├── Day16.scala │ ├── Day17.scala │ ├── Day18.scala │ ├── Day19.scala │ ├── Day20.scala │ ├── Day21.scala │ ├── Day22.scala │ ├── Day23.scala │ ├── Day24.scala │ └── Day25.scala │ ├── AdventOfCode2018 │ ├── Day01.scala │ ├── Day02.scala │ ├── Day03.scala │ ├── Day04.scala │ ├── Day05.scala │ ├── Day06.scala │ ├── Day07.scala │ ├── Day08.scala │ ├── Day09.scala │ ├── Day10.scala │ ├── Day11.scala │ ├── Day12.scala │ ├── Day13.scala │ ├── Day14.scala │ ├── Day15.scala │ ├── Day16.scala │ ├── Day17.scala │ ├── Day18.scala │ ├── Day19.scala │ ├── Day20.scala │ ├── Day21.scala │ ├── Day22.scala │ ├── Day23.scala │ ├── Day24.scala │ └── Day25.scala │ ├── AdventOfCode2019 │ ├── Day01.scala │ ├── Day02.scala │ ├── Day03.scala │ ├── Day04.scala │ ├── Day05.scala │ ├── Day06.scala │ ├── Day07.scala │ ├── Day08.scala │ ├── Day09.scala │ ├── Day10.scala │ ├── Day11.scala │ ├── Day12.scala │ ├── Day13.scala │ ├── Day14.scala │ ├── Day15.scala │ ├── Day16.scala │ ├── Day17.scala │ ├── Day18.scala │ ├── Day19.scala │ ├── Day20.scala │ ├── Day21.scala │ ├── Day22.scala │ ├── Day23.scala │ ├── Day24.scala │ └── Day25.scala │ ├── AdventOfCode2020 │ ├── Day01.scala │ ├── Day02.scala │ ├── Day03.scala │ ├── Day04.scala │ ├── Day05.scala │ ├── Day06.scala │ ├── Day07.scala │ ├── Day08.scala │ ├── Day09.scala │ ├── Day10.scala │ ├── Day11.scala │ ├── Day12.scala │ ├── Day13.scala │ ├── Day14.scala │ ├── Day15.scala │ ├── Day16.scala │ ├── Day17.scala │ ├── Day18.scala │ ├── Day19.scala │ ├── Day20.scala │ ├── Day21.scala │ ├── Day22.scala │ ├── Day23.scala │ ├── Day24.scala │ └── Day25.scala │ ├── AdventOfCode2021 │ ├── Day01.scala │ ├── Day02.scala │ ├── Day03.scala │ ├── Day04.scala │ ├── Day05.scala │ ├── Day06.scala │ ├── Day07.scala │ ├── Day08.scala │ ├── Day09.scala │ ├── Day10.scala │ ├── Day11.scala │ ├── Day12.scala │ ├── Day13.scala │ ├── Day14.scala │ ├── Day15.scala │ ├── Day16.scala │ ├── Day17.scala │ ├── Day18.scala │ ├── Day19.scala │ ├── Day20.scala │ ├── Day21.scala │ ├── Day22.scala │ ├── Day23.scala │ ├── Day24.scala │ └── Day25.scala │ └── AdventOfCode2022 │ ├── Day01.scala │ ├── Day02.scala │ ├── Day03.scala │ ├── Day04.scala │ ├── Day05.scala │ ├── Day06.scala │ ├── Day07.scala │ ├── Day08.scala │ ├── Day09.scala │ ├── Day10.scala │ ├── Day11.scala │ ├── Day12.scala │ ├── Day13.scala │ ├── Day14.scala │ ├── Day15.scala │ ├── Day16.scala │ ├── Day17.scala │ ├── Day18.scala │ ├── Day19.scala │ ├── Day20.scala │ ├── Day21.scala │ ├── Day22.scala │ ├── Day23.scala │ ├── Day24.scala │ └── Day25.scala └── test └── scala ├── AdventOfCode2015 ├── Day01Suite.scala ├── Day02Suite.scala ├── Day03Suite.scala ├── Day04Suite.scala ├── Day05Suite.scala ├── Day06Suite.scala ├── Day07Suite.scala ├── Day08Suite.scala ├── Day09Suite.scala ├── Day10Suite.scala ├── Day11Suite.scala ├── Day12Suite.scala ├── Day13Suite.scala ├── Day14Suite.scala ├── Day15Suite.scala ├── Day16Suite.scala ├── Day17Suite.scala ├── Day18Suite.scala ├── Day19Suite.scala ├── Day20Suite.scala ├── Day21Suite.scala ├── Day22Suite.scala ├── Day23Suite.scala ├── Day24Suite.scala └── Day25Suite.scala ├── AdventOfCode2016 ├── Day01Suite.scala ├── Day02Suite.scala ├── Day03Suite.scala ├── Day04Suite.scala ├── Day05Suite.scala ├── Day06Suite.scala ├── Day07Suite.scala ├── Day08Suite.scala ├── Day09Suite.scala ├── Day10Suite.scala ├── Day11Suite.scala ├── Day12Suite.scala ├── Day13Suite.scala ├── Day14Suite.scala ├── Day15Suite.scala ├── Day16Suite.scala ├── Day17Suite.scala ├── Day18Suite.scala ├── Day19Suite.scala ├── Day20Suite.scala ├── Day21Suite.scala ├── Day22Suite.scala ├── Day23Suite.scala ├── Day24Suite.scala └── Day25Suite.scala ├── AdventOfCode2017 ├── Day01Suite.scala ├── Day02Suite.scala ├── Day03Suite.scala ├── Day04Suite.scala ├── Day05Suite.scala ├── Day06Suite.scala ├── Day07Suite.scala ├── Day08Suite.scala ├── Day09Suite.scala ├── Day10Suite.scala ├── Day11Suite.scala ├── Day12Suite.scala ├── Day13Suite.scala ├── Day14Suite.scala ├── Day15Suite.scala ├── Day16Suite.scala ├── Day17Suite.scala ├── Day18Suite.scala ├── Day19Suite.scala ├── Day20Suite.scala ├── Day21Suite.scala ├── Day22Suite.scala ├── Day23Suite.scala ├── Day24Suite.scala └── Day25Suite.scala ├── AdventOfCode2018 ├── Day01Suite.scala ├── Day02Suite.scala ├── Day03Suite.scala ├── Day04Suite.scala ├── Day05Suite.scala ├── Day06Suite.scala ├── Day07Suite.scala ├── Day08Suite.scala ├── Day09Suite.scala ├── Day10Suite.scala ├── Day11Suite.scala ├── Day12Suite.scala ├── Day13Suite.scala ├── Day14Suite.scala ├── Day15Suite.scala ├── Day16Suite.scala ├── Day17Suite.scala ├── Day18Suite.scala ├── Day19Suite.scala ├── Day20Suite.scala ├── Day21Suite.scala ├── Day22Suite.scala ├── Day23Suite.scala ├── Day24Suite.scala └── Day25Suite.scala ├── AdventOfCode2019 ├── Day01Suite.scala ├── Day02Suite.scala ├── Day03Suite.scala ├── Day04Suite.scala ├── Day05Suite.scala ├── Day06Suite.scala ├── Day07Suite.scala ├── Day08Suite.scala ├── Day09Suite.scala ├── Day10Suite.scala ├── Day11Suite.scala ├── Day12Suite.scala ├── Day13Suite.scala ├── Day14Suite.scala ├── Day15Suite.scala ├── Day16Suite.scala ├── Day17Suite.scala ├── Day18Suite.scala ├── Day19Suite.scala ├── Day20Suite.scala ├── Day21Suite.scala ├── Day22Suite.scala ├── Day23Suite.scala ├── Day24Suite.scala └── Day25Suite.scala ├── AdventOfCode2020 ├── Day01Suite.scala ├── Day02Suite.scala ├── Day03Suite.scala ├── Day04Suite.scala ├── Day05Suite.scala ├── Day06Suite.scala ├── Day07Suite.scala ├── Day08Suite.scala ├── Day09Suite.scala ├── Day10Suite.scala ├── Day11Suite.scala ├── Day12Suite.scala ├── Day13Suite.scala ├── Day14Suite.scala ├── Day15Suite.scala ├── Day16Suite.scala ├── Day17Suite.scala ├── Day18Suite.scala ├── Day19Suite.scala ├── Day20Suite.scala ├── Day21Suite.scala ├── Day22Suite.scala ├── Day23Suite.scala ├── Day24Suite.scala └── Day25Suite.scala ├── AdventOfCode2021 ├── Day01Suite.scala ├── Day02Suite.scala ├── Day03Suite.scala ├── Day04Suite.scala ├── Day05Suite.scala ├── Day06Suite.scala ├── Day07Suite.scala ├── Day08Suite.scala ├── Day09Suite.scala ├── Day10Suite.scala ├── Day11Suite.scala ├── Day12Suite.scala ├── Day13Suite.scala ├── Day14Suite.scala ├── Day15Suite.scala ├── Day16Suite.scala ├── Day17Suite.scala ├── Day18Suite.scala ├── Day19Suite.scala ├── Day20Suite.scala ├── Day21Suite.scala ├── Day22Suite.scala ├── Day23Suite.scala ├── Day24Suite.scala └── Day25Suite.scala ├── AdventOfCode2022 ├── Day01Suite.scala ├── Day02Suite.scala ├── Day03Suite.scala ├── Day04Suite.scala ├── Day05Suite.scala ├── Day06Suite.scala ├── Day07Suite.scala ├── Day08Suite.scala ├── Day09Suite.scala ├── Day10Suite.scala ├── Day11Suite.scala ├── Day12Suite.scala ├── Day13Suite.scala ├── Day14Suite.scala ├── Day15Suite.scala ├── Day16Suite.scala ├── Day17Suite.scala ├── Day18Suite.scala ├── Day19Suite.scala ├── Day20Suite.scala ├── Day21Suite.scala ├── Day22Suite.scala ├── Day23Suite.scala ├── Day24Suite.scala └── Day25Suite.scala └── template ├── Day00.scala └── Day00Suite.scala /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: 4 | push: 5 | branches: main 6 | pull_request: 7 | branches: main 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v4 14 | - uses: actions/setup-java@v4 15 | with: 16 | java-version: '21' 17 | distribution: 'corretto' 18 | cache: 'sbt' 19 | - run: sbt test 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # IntelliJ 2 | .bsp/ 3 | .idea/ 4 | 5 | # macOS 6 | .DS_Store 7 | 8 | # Metals 9 | .metals/ 10 | .bloop/ 11 | metals.sbt 12 | 13 | # SBT 14 | target/ 15 | 16 | # Visual Studio Code 17 | .vscode 18 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | **Copyright © 2021-2023 maneatingape** 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /build.sbt: -------------------------------------------------------------------------------- 1 | name := "Advent of Code" 2 | 3 | scalaVersion := "3.3.3" 4 | 5 | scalacOptions ++= Seq( 6 | "-deprecation", 7 | "-explain", 8 | "-explaintypes", 9 | "-feature", 10 | "-unchecked") 11 | 12 | libraryDependencies ++= Seq( 13 | "org.scalatest" %% "scalatest" % "3.2.19" % Test 14 | ) 15 | -------------------------------------------------------------------------------- /project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=1.9.9 2 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2015/Day04.txt: -------------------------------------------------------------------------------- 1 | iwrupvqb 2 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2015/Day09.txt: -------------------------------------------------------------------------------- 1 | Faerun to Tristram = 65 2 | Faerun to Tambi = 129 3 | Faerun to Norrath = 144 4 | Faerun to Snowdin = 71 5 | Faerun to Straylight = 137 6 | Faerun to AlphaCentauri = 3 7 | Faerun to Arbre = 149 8 | Tristram to Tambi = 63 9 | Tristram to Norrath = 4 10 | Tristram to Snowdin = 105 11 | Tristram to Straylight = 125 12 | Tristram to AlphaCentauri = 55 13 | Tristram to Arbre = 14 14 | Tambi to Norrath = 68 15 | Tambi to Snowdin = 52 16 | Tambi to Straylight = 65 17 | Tambi to AlphaCentauri = 22 18 | Tambi to Arbre = 143 19 | Norrath to Snowdin = 8 20 | Norrath to Straylight = 23 21 | Norrath to AlphaCentauri = 136 22 | Norrath to Arbre = 115 23 | Snowdin to Straylight = 101 24 | Snowdin to AlphaCentauri = 84 25 | Snowdin to Arbre = 96 26 | Straylight to AlphaCentauri = 107 27 | Straylight to Arbre = 14 28 | AlphaCentauri to Arbre = 46 29 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2015/Day10.txt: -------------------------------------------------------------------------------- 1 | 1113222113 2 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2015/Day11.txt: -------------------------------------------------------------------------------- 1 | hepxcrrq 2 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2015/Day14.txt: -------------------------------------------------------------------------------- 1 | Vixen can fly 8 km/s for 8 seconds, but then must rest for 53 seconds. 2 | Blitzen can fly 13 km/s for 4 seconds, but then must rest for 49 seconds. 3 | Rudolph can fly 20 km/s for 7 seconds, but then must rest for 132 seconds. 4 | Cupid can fly 12 km/s for 4 seconds, but then must rest for 43 seconds. 5 | Donner can fly 9 km/s for 5 seconds, but then must rest for 38 seconds. 6 | Dasher can fly 10 km/s for 4 seconds, but then must rest for 37 seconds. 7 | Comet can fly 3 km/s for 37 seconds, but then must rest for 76 seconds. 8 | Prancer can fly 9 km/s for 12 seconds, but then must rest for 97 seconds. 9 | Dancer can fly 37 km/s for 1 seconds, but then must rest for 36 seconds. 10 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2015/Day15.txt: -------------------------------------------------------------------------------- 1 | Sugar: capacity 3, durability 0, flavor 0, texture -3, calories 2 2 | Sprinkles: capacity -3, durability 3, flavor 0, texture 0, calories 9 3 | Candy: capacity -1, durability 0, flavor 4, texture 0, calories 1 4 | Chocolate: capacity 0, durability 0, flavor -2, texture 2, calories 8 5 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2015/Day17.txt: -------------------------------------------------------------------------------- 1 | 11 2 | 30 3 | 47 4 | 31 5 | 32 6 | 36 7 | 3 8 | 1 9 | 5 10 | 3 11 | 32 12 | 36 13 | 15 14 | 11 15 | 46 16 | 26 17 | 28 18 | 1 19 | 19 20 | 3 21 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2015/Day20.txt: -------------------------------------------------------------------------------- 1 | 29000000 2 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2015/Day21.txt: -------------------------------------------------------------------------------- 1 | Hit Points: 100 2 | Damage: 8 3 | Armor: 2 4 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2015/Day22.txt: -------------------------------------------------------------------------------- 1 | Hit Points: 55 2 | Damage: 8 3 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2015/Day23.txt: -------------------------------------------------------------------------------- 1 | jio a, +22 2 | inc a 3 | tpl a 4 | tpl a 5 | tpl a 6 | inc a 7 | tpl a 8 | inc a 9 | tpl a 10 | inc a 11 | inc a 12 | tpl a 13 | inc a 14 | inc a 15 | tpl a 16 | inc a 17 | inc a 18 | tpl a 19 | inc a 20 | inc a 21 | tpl a 22 | jmp +19 23 | tpl a 24 | tpl a 25 | tpl a 26 | tpl a 27 | inc a 28 | inc a 29 | tpl a 30 | inc a 31 | tpl a 32 | inc a 33 | inc a 34 | tpl a 35 | inc a 36 | inc a 37 | tpl a 38 | inc a 39 | tpl a 40 | tpl a 41 | jio a, +8 42 | inc b 43 | jie a, +4 44 | tpl a 45 | inc a 46 | jmp +2 47 | hlf a 48 | jmp -7 49 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2015/Day24.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 3 3 | 5 4 | 11 5 | 13 6 | 17 7 | 19 8 | 23 9 | 29 10 | 31 11 | 41 12 | 43 13 | 47 14 | 53 15 | 59 16 | 61 17 | 67 18 | 71 19 | 73 20 | 79 21 | 83 22 | 89 23 | 97 24 | 101 25 | 103 26 | 107 27 | 109 28 | 113 29 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2015/Day25.txt: -------------------------------------------------------------------------------- 1 | To continue, please consult the code grid in the manual. Enter the code at row 3010, column 3019. 2 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2016/Day01.txt: -------------------------------------------------------------------------------- 1 | R5, R4, R2, L3, R1, R1, L4, L5, R3, L1, L1, R4, L2, R1, R4, R4, L2, L2, R4, L4, R1, R3, L3, L1, L2, R1, R5, L5, L1, L1, R3, R5, L1, R4, L5, R5, R1, L185, R4, L1, R51, R3, L2, R78, R1, L4, R188, R1, L5, R5, R2, R3, L5, R3, R4, L1, R2, R2, L4, L4, L5, R5, R4, L4, R2, L5, R2, L1, L4, R4, L4, R2, L3, L4, R2, L3, R3, R2, L2, L3, R4, R3, R1, L4, L2, L5, R4, R4, L1, R1, L5, L1, R3, R1, L2, R1, R1, R3, L4, L1, L3, R2, R4, R2, L2, R1, L5, R3, L3, R3, L1, R4, L3, L3, R4, L2, L1, L3, R2, R3, L2, L1, R4, L3, L5, L2, L4, R1, L4, L4, R3, R5, L4, L1, L1, R4, L2, R5, R1, R1, R2, R1, R5, L1, L3, L5, R2 2 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2016/Day05.txt: -------------------------------------------------------------------------------- 1 | ojvtpuvg 2 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2016/Day11.txt: -------------------------------------------------------------------------------- 1 | The first floor contains a polonium generator, a thulium generator, a thulium-compatible microchip, a promethium generator, a ruthenium generator, a ruthenium-compatible microchip, a cobalt generator, and a cobalt-compatible microchip. 2 | The second floor contains a polonium-compatible microchip and a promethium-compatible microchip. 3 | The third floor contains nothing relevant. 4 | The fourth floor contains nothing relevant. 5 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2016/Day12.txt: -------------------------------------------------------------------------------- 1 | cpy 1 a 2 | cpy 1 b 3 | cpy 26 d 4 | jnz c 2 5 | jnz 1 5 6 | cpy 7 c 7 | inc d 8 | dec c 9 | jnz c -2 10 | cpy a c 11 | inc a 12 | dec b 13 | jnz b -2 14 | cpy c b 15 | dec d 16 | jnz d -6 17 | cpy 19 c 18 | cpy 11 d 19 | inc a 20 | dec d 21 | jnz d -2 22 | dec c 23 | jnz c -5 24 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2016/Day13.txt: -------------------------------------------------------------------------------- 1 | 1350 2 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2016/Day14.txt: -------------------------------------------------------------------------------- 1 | jlmsuwbz 2 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2016/Day15.txt: -------------------------------------------------------------------------------- 1 | Disc #1 has 17 positions; at time=0, it is at position 1. 2 | Disc #2 has 7 positions; at time=0, it is at position 0. 3 | Disc #3 has 19 positions; at time=0, it is at position 2. 4 | Disc #4 has 5 positions; at time=0, it is at position 0. 5 | Disc #5 has 3 positions; at time=0, it is at position 0. 6 | Disc #6 has 13 positions; at time=0, it is at position 5. 7 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2016/Day16.txt: -------------------------------------------------------------------------------- 1 | 01111001100111011 2 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2016/Day17.txt: -------------------------------------------------------------------------------- 1 | yjjvjgan 2 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2016/Day18.txt: -------------------------------------------------------------------------------- 1 | .^^^^^.^^.^^^.^...^..^^.^.^..^^^^^^^^^^..^...^^.^..^^^^..^^^^...^.^.^^^^^^^^....^..^^^^^^.^^^.^^^.^^ 2 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2016/Day19.txt: -------------------------------------------------------------------------------- 1 | 3005290 2 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2016/Day23.txt: -------------------------------------------------------------------------------- 1 | cpy a b 2 | dec b 3 | cpy a d 4 | cpy 0 a 5 | cpy b c 6 | inc a 7 | dec c 8 | jnz c -2 9 | dec d 10 | jnz d -5 11 | dec b 12 | cpy b c 13 | cpy c d 14 | dec d 15 | inc c 16 | jnz d -2 17 | tgl c 18 | cpy -16 c 19 | jnz 1 c 20 | cpy 71 c 21 | jnz 75 d 22 | inc a 23 | inc d 24 | jnz d -2 25 | inc c 26 | jnz c -5 27 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2016/Day25.txt: -------------------------------------------------------------------------------- 1 | cpy a d 2 | cpy 4 c 3 | cpy 633 b 4 | inc d 5 | dec b 6 | jnz b -2 7 | dec c 8 | jnz c -5 9 | cpy d a 10 | jnz 0 0 11 | cpy a b 12 | cpy 0 a 13 | cpy 2 c 14 | jnz b 2 15 | jnz 1 6 16 | dec b 17 | dec c 18 | jnz c -4 19 | inc a 20 | jnz 1 -7 21 | cpy 2 b 22 | jnz c 2 23 | jnz 1 4 24 | dec b 25 | dec c 26 | jnz 1 -4 27 | jnz 0 0 28 | out b 29 | jnz a -19 30 | jnz 1 -21 31 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2017/Day03.txt: -------------------------------------------------------------------------------- 1 | 312051 2 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2017/Day06.txt: -------------------------------------------------------------------------------- 1 | 14 0 15 12 11 11 3 5 1 6 8 4 9 1 8 4 2 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2017/Day10.txt: -------------------------------------------------------------------------------- 1 | 14,58,0,116,179,16,1,104,2,254,167,86,255,55,122,244 2 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2017/Day13.txt: -------------------------------------------------------------------------------- 1 | 0: 4 2 | 1: 2 3 | 2: 3 4 | 4: 5 5 | 6: 8 6 | 8: 6 7 | 10: 4 8 | 12: 6 9 | 14: 6 10 | 16: 8 11 | 18: 8 12 | 20: 6 13 | 22: 8 14 | 24: 8 15 | 26: 8 16 | 28: 12 17 | 30: 12 18 | 32: 9 19 | 34: 14 20 | 36: 12 21 | 38: 12 22 | 40: 12 23 | 42: 12 24 | 44: 10 25 | 46: 12 26 | 48: 12 27 | 50: 10 28 | 52: 14 29 | 56: 12 30 | 58: 14 31 | 62: 14 32 | 64: 14 33 | 66: 12 34 | 68: 14 35 | 70: 14 36 | 72: 17 37 | 74: 14 38 | 76: 14 39 | 80: 20 40 | 82: 14 41 | 90: 24 42 | 92: 14 43 | 98: 14 44 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2017/Day14.txt: -------------------------------------------------------------------------------- 1 | xlqgujun 2 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2017/Day15.txt: -------------------------------------------------------------------------------- 1 | Generator A starts with 634 2 | Generator B starts with 301 3 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2017/Day17.txt: -------------------------------------------------------------------------------- 1 | 304 2 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2017/Day18.txt: -------------------------------------------------------------------------------- 1 | set i 31 2 | set a 1 3 | mul p 17 4 | jgz p p 5 | mul a 2 6 | add i -1 7 | jgz i -2 8 | add a -1 9 | set i 127 10 | set p 464 11 | mul p 8505 12 | mod p a 13 | mul p 129749 14 | add p 12345 15 | mod p a 16 | set b p 17 | mod b 10000 18 | snd b 19 | add i -1 20 | jgz i -9 21 | jgz a 3 22 | rcv b 23 | jgz b -1 24 | set f 0 25 | set i 126 26 | rcv a 27 | rcv b 28 | set p a 29 | mul p -1 30 | add p b 31 | jgz p 4 32 | snd a 33 | set a b 34 | jgz 1 3 35 | snd b 36 | set f 1 37 | add i -1 38 | jgz i -11 39 | snd a 40 | jgz f -16 41 | jgz a -19 42 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2017/Day22.txt: -------------------------------------------------------------------------------- 1 | .....###..#....#.#..##... 2 | ......##.##...........##. 3 | .#..#..#.#.##.##......... 4 | ...#..###..##.#.###.#.#.# 5 | ##....#.##.#..####.####.. 6 | #..##...#.##.##.....##..# 7 | .#.#......#...####...#.## 8 | ###....#######...#####.#. 9 | ##..#.####...#.#.##...... 10 | ##.....###....#.#..#.##.# 11 | .#..##.....#########.##.. 12 | ##...##.###..#.#..#.#...# 13 | ...####..#...#.##.#..#### 14 | .#..##......#####..#.###. 15 | ...#.#.#..##...#####..... 16 | #..###.###.#.....#.#.###. 17 | ##.##.#.#.##.#..#..###### 18 | ####.##..#.###.#...#..### 19 | .........#####.##.###..## 20 | ..#.##.#..#..#...##..#... 21 | ###.###.#.#..##...###.... 22 | ##..#.#.#.#.#.#.#...###.. 23 | #..#.#.....#..#..#..##... 24 | ........#######.#...#.#.. 25 | ..##.###.#.##.#.#.###..## 26 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2017/Day23.txt: -------------------------------------------------------------------------------- 1 | set b 79 2 | set c b 3 | jnz a 2 4 | jnz 1 5 5 | mul b 100 6 | sub b -100000 7 | set c b 8 | sub c -17000 9 | set f 1 10 | set d 2 11 | set e 2 12 | set g d 13 | mul g e 14 | sub g b 15 | jnz g 2 16 | set f 0 17 | sub e -1 18 | set g e 19 | sub g b 20 | jnz g -8 21 | sub d -1 22 | set g d 23 | sub g b 24 | jnz g -13 25 | jnz f 2 26 | sub h -1 27 | set g b 28 | sub g c 29 | jnz g 2 30 | jnz 1 3 31 | sub b -17 32 | jnz 1 -23 33 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2017/Day24.txt: -------------------------------------------------------------------------------- 1 | 25/13 2 | 4/43 3 | 42/42 4 | 39/40 5 | 17/18 6 | 30/7 7 | 12/12 8 | 32/28 9 | 9/28 10 | 1/1 11 | 16/7 12 | 47/43 13 | 34/16 14 | 39/36 15 | 6/4 16 | 3/2 17 | 10/49 18 | 46/50 19 | 18/25 20 | 2/23 21 | 3/21 22 | 5/24 23 | 46/26 24 | 50/19 25 | 26/41 26 | 1/50 27 | 47/41 28 | 39/50 29 | 12/14 30 | 11/19 31 | 28/2 32 | 38/47 33 | 5/5 34 | 38/34 35 | 39/39 36 | 17/34 37 | 42/16 38 | 32/23 39 | 13/21 40 | 28/6 41 | 6/20 42 | 1/30 43 | 44/21 44 | 11/28 45 | 14/17 46 | 33/33 47 | 17/43 48 | 31/13 49 | 11/21 50 | 31/39 51 | 0/9 52 | 13/50 53 | 10/14 54 | 16/10 55 | 3/24 56 | 7/0 57 | 50/50 58 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2018/Day06.txt: -------------------------------------------------------------------------------- 1 | 66, 204 2 | 55, 226 3 | 231, 196 4 | 69, 211 5 | 69, 335 6 | 133, 146 7 | 321, 136 8 | 220, 229 9 | 148, 138 10 | 42, 319 11 | 304, 181 12 | 101, 329 13 | 72, 244 14 | 242, 117 15 | 83, 237 16 | 169, 225 17 | 311, 212 18 | 348, 330 19 | 233, 268 20 | 99, 301 21 | 142, 293 22 | 239, 288 23 | 200, 216 24 | 44, 215 25 | 353, 289 26 | 54, 73 27 | 73, 317 28 | 55, 216 29 | 305, 134 30 | 343, 233 31 | 227, 75 32 | 139, 285 33 | 264, 179 34 | 349, 263 35 | 48, 116 36 | 223, 60 37 | 247, 148 38 | 320, 232 39 | 60, 230 40 | 292, 78 41 | 247, 342 42 | 59, 326 43 | 333, 210 44 | 186, 291 45 | 218, 146 46 | 205, 246 47 | 124, 204 48 | 76, 121 49 | 333, 137 50 | 117, 68 51 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2018/Day09.txt: -------------------------------------------------------------------------------- 1 | 428 players; last marble is worth 72061 points 2 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2018/Day11.txt: -------------------------------------------------------------------------------- 1 | 9005 2 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2018/Day12.txt: -------------------------------------------------------------------------------- 1 | initial state: #......##...#.#.###.#.##..##.#.....##....#.#.##.##.#..#.##........####.###.###.##..#....#...###.## 2 | 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 | ...## => . 31 | ...#. => # 32 | ..### => . 33 | ####. => # 34 | ###.. => # 35 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2018/Day14.txt: -------------------------------------------------------------------------------- 1 | 236021 2 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2018/Day19.txt: -------------------------------------------------------------------------------- 1 | #ip 1 2 | addi 1 16 1 3 | seti 1 8 2 4 | seti 1 5 4 5 | mulr 2 4 3 6 | eqrr 3 5 3 7 | addr 3 1 1 8 | addi 1 1 1 9 | addr 2 0 0 10 | addi 4 1 4 11 | gtrr 4 5 3 12 | addr 1 3 1 13 | seti 2 8 1 14 | addi 2 1 2 15 | gtrr 2 5 3 16 | addr 3 1 1 17 | seti 1 8 1 18 | mulr 1 1 1 19 | addi 5 2 5 20 | mulr 5 5 5 21 | mulr 1 5 5 22 | muli 5 11 5 23 | addi 3 5 3 24 | mulr 3 1 3 25 | addi 3 4 3 26 | addr 5 3 5 27 | addr 1 0 1 28 | seti 0 7 1 29 | setr 1 1 3 30 | mulr 3 1 3 31 | addr 1 3 3 32 | mulr 1 3 3 33 | muli 3 14 3 34 | mulr 3 1 3 35 | addr 5 3 5 36 | seti 0 9 0 37 | seti 0 0 1 38 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2018/Day21.txt: -------------------------------------------------------------------------------- 1 | #ip 2 2 | seti 123 0 3 3 | bani 3 456 3 4 | eqri 3 72 3 5 | addr 3 2 2 6 | seti 0 0 2 7 | seti 0 4 3 8 | bori 3 65536 4 9 | seti 1107552 3 3 10 | bani 4 255 5 11 | addr 3 5 3 12 | bani 3 16777215 3 13 | muli 3 65899 3 14 | bani 3 16777215 3 15 | gtir 256 4 5 16 | addr 5 2 2 17 | addi 2 1 2 18 | seti 27 0 2 19 | seti 0 2 5 20 | addi 5 1 1 21 | muli 1 256 1 22 | gtrr 1 4 1 23 | addr 1 2 2 24 | addi 2 1 2 25 | seti 25 3 2 26 | addi 5 1 5 27 | seti 17 3 2 28 | setr 5 3 4 29 | seti 7 4 2 30 | eqrr 3 0 5 31 | addr 5 2 2 32 | seti 5 8 2 33 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2018/Day22.txt: -------------------------------------------------------------------------------- 1 | depth: 11109 2 | target: 9,731 3 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2019/Day02.txt: -------------------------------------------------------------------------------- 1 | 1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,10,1,19,1,6,19,23,1,23,13,27,2,6,27,31,1,5,31,35,2,10,35,39,1,6,39,43,1,13,43,47,2,47,6,51,1,51,5,55,1,55,6,59,2,59,10,63,1,63,6,67,2,67,10,71,1,71,9,75,2,75,10,79,1,79,5,83,2,10,83,87,1,87,6,91,2,9,91,95,1,95,5,99,1,5,99,103,1,103,10,107,1,9,107,111,1,6,111,115,1,115,5,119,1,10,119,123,2,6,123,127,2,127,6,131,1,131,2,135,1,10,135,0,99,2,0,14,0 2 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2019/Day04.txt: -------------------------------------------------------------------------------- 1 | 172851-675869 -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2019/Day12.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2019/Day16.txt: -------------------------------------------------------------------------------- 1 | 59754835304279095723667830764559994207668723615273907123832849523285892960990393495763064170399328763959561728553125232713663009161639789035331160605704223863754174835946381029543455581717775283582638013183215312822018348826709095340993876483418084566769957325454646682224309983510781204738662326823284208246064957584474684120465225052336374823382738788573365821572559301715471129142028462682986045997614184200503304763967364026464055684787169501819241361777789595715281841253470186857857671012867285957360755646446993278909888646724963166642032217322712337954157163771552371824741783496515778370667935574438315692768492954716331430001072240959235708 2 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2019/Day24.txt: -------------------------------------------------------------------------------- 1 | ....# 2 | #..#. 3 | ##..# 4 | #.### 5 | .#### 6 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2020/Day10.txt: -------------------------------------------------------------------------------- 1 | 104 2 | 83 3 | 142 4 | 123 5 | 87 6 | 48 7 | 102 8 | 159 9 | 122 10 | 69 11 | 127 12 | 151 13 | 147 14 | 64 15 | 152 16 | 90 17 | 117 18 | 132 19 | 63 20 | 109 21 | 27 22 | 47 23 | 7 24 | 52 25 | 59 26 | 11 27 | 161 28 | 12 29 | 148 30 | 155 31 | 129 32 | 10 33 | 135 34 | 17 35 | 153 36 | 96 37 | 3 38 | 93 39 | 82 40 | 55 41 | 34 42 | 65 43 | 89 44 | 126 45 | 19 46 | 72 47 | 20 48 | 38 49 | 103 50 | 146 51 | 14 52 | 105 53 | 53 54 | 77 55 | 120 56 | 39 57 | 46 58 | 24 59 | 139 60 | 95 61 | 140 62 | 33 63 | 21 64 | 84 65 | 56 66 | 1 67 | 32 68 | 31 69 | 28 70 | 4 71 | 73 72 | 128 73 | 49 74 | 18 75 | 62 76 | 81 77 | 66 78 | 121 79 | 54 80 | 160 81 | 158 82 | 138 83 | 94 84 | 43 85 | 2 86 | 114 87 | 111 88 | 110 89 | 78 90 | 13 91 | 99 92 | 108 93 | 141 94 | 40 95 | 25 96 | 154 97 | 26 98 | 35 99 | 88 100 | 76 101 | 145 102 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2020/Day13.txt: -------------------------------------------------------------------------------- 1 | 1000067 2 | 17,x,x,x,x,x,x,x,x,x,x,37,x,x,x,x,x,439,x,29,x,x,x,x,x,x,x,x,x,x,13,x,x,x,x,x,x,x,x,x,23,x,x,x,x,x,x,x,787,x,x,x,x,x,x,x,x,x,41,x,x,x,x,x,x,x,x,19 3 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2020/Day15.txt: -------------------------------------------------------------------------------- 1 | 13 2 | 16 3 | 0 4 | 12 5 | 15 6 | 1 7 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2020/Day17.txt: -------------------------------------------------------------------------------- 1 | #...#.#. 2 | ..#.#.## 3 | ..#..#.. 4 | .....### 5 | ...#.#.# 6 | #.#.##.. 7 | #####... 8 | .#.#.##. 9 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2020/Day22.txt: -------------------------------------------------------------------------------- 1 | Player 1: 2 | 38 3 | 1 4 | 28 5 | 32 6 | 43 7 | 21 8 | 42 9 | 29 10 | 18 11 | 13 12 | 39 13 | 41 14 | 49 15 | 31 16 | 19 17 | 26 18 | 27 19 | 40 20 | 35 21 | 14 22 | 3 23 | 36 24 | 12 25 | 16 26 | 45 27 | 28 | Player 2: 29 | 34 30 | 15 31 | 47 32 | 20 33 | 23 34 | 2 35 | 11 36 | 9 37 | 8 38 | 7 39 | 25 40 | 50 41 | 48 42 | 24 43 | 46 44 | 44 45 | 10 46 | 6 47 | 22 48 | 5 49 | 33 50 | 30 51 | 4 52 | 17 53 | 37 54 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2020/Day23.txt: -------------------------------------------------------------------------------- 1 | 589174263 -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2020/Day25.txt: -------------------------------------------------------------------------------- 1 | 14222596 2 | 4057428 3 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2021/Day06.txt: -------------------------------------------------------------------------------- 1 | 4,2,4,1,5,1,2,2,4,1,1,2,2,2,4,4,1,2,1,1,4,1,2,1,2,2,2,2,5,2,2,3,1,4,4,4,1,2,3,4,4,5,4,3,5,1,2,5,1,1,5,5,1,4,4,5,1,3,1,4,5,5,5,4,1,2,3,4,2,1,2,1,2,2,1,5,5,1,1,1,1,5,2,2,2,4,2,4,2,4,2,1,2,1,2,4,2,4,1,3,5,5,2,4,4,2,2,2,2,3,3,2,1,1,1,1,4,3,2,5,4,3,5,3,1,5,5,2,4,1,1,2,1,3,5,1,5,3,1,3,1,4,5,1,1,3,2,1,1,1,5,2,1,2,4,2,3,3,2,3,5,1,5,1,2,1,5,2,4,1,2,4,4,1,5,1,1,5,2,2,5,5,3,1,2,2,1,1,4,1,5,4,5,5,2,2,1,1,2,5,4,3,2,2,5,4,2,5,4,4,2,3,1,1,1,5,5,4,5,3,2,5,3,4,5,1,4,1,1,3,4,4,1,1,5,1,4,1,2,1,4,1,1,3,1,5,2,5,1,5,2,5,2,5,4,1,1,4,4,2,3,1,5,2,5,1,5,2,1,1,1,2,1,1,1,4,4,5,4,4,1,4,2,2,2,5,3,2,4,4,5,5,1,1,1,1,3,1,2,1 2 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2021/Day11.txt: -------------------------------------------------------------------------------- 1 | 7612648217 2 | 7617237672 3 | 2853871836 4 | 7214367135 5 | 1533365614 6 | 6258172862 7 | 5377675583 8 | 5613268278 9 | 8381134465 10 | 3445428733 11 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2021/Day12.txt: -------------------------------------------------------------------------------- 1 | pg-CH 2 | pg-yd 3 | yd-start 4 | fe-hv 5 | bi-CH 6 | CH-yd 7 | end-bi 8 | fe-RY 9 | ng-CH 10 | fe-CH 11 | ng-pg 12 | hv-FL 13 | FL-fe 14 | hv-pg 15 | bi-hv 16 | CH-end 17 | hv-ng 18 | yd-ng 19 | pg-fe 20 | start-ng 21 | end-FL 22 | fe-bi 23 | FL-ks 24 | pg-start 25 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2021/Day17.txt: -------------------------------------------------------------------------------- 1 | target area: x=124..174, y=-123..-86 2 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2021/Day21.txt: -------------------------------------------------------------------------------- 1 | Player 1 starting position: 8 2 | Player 2 starting position: 9 3 | -------------------------------------------------------------------------------- /src/main/resources/AdventOfCode2021/Day23.txt: -------------------------------------------------------------------------------- 1 | ############# 2 | #...........# 3 | ###C#B#A#D### 4 | #B#C#D#A# 5 | ######### 6 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2015/Day01.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | object Day01: 4 | def part1(input: String): Int = input.count(_ == '(') - input.count(_ == ')') 5 | 6 | def part2(input: String): Int = 7 | input.scanLeft(0)((total, next) => if next == '(' then total + 1 else total - 1).indexOf(-1) 8 | 9 | def main(args: Array[String]): Unit = 10 | val data = io.Source.fromResource("AdventOfCode2015/Day01.txt").mkString.trim 11 | println(part1(data)) 12 | println(part2(data)) 13 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2015/Day02.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | object Day02: 4 | def part1(input: Seq[String]): Int = input.map { line => 5 | val Array(l, w, h) = line.split("x").map(_.toInt) 6 | val sides = Seq(l * w, w * h, h * l) 7 | 2 * sides.sum + sides.min 8 | } 9 | .sum 10 | 11 | def part2(input: Seq[String]): Int = input.map { line => 12 | val Array(l, w, h) = line.split("x").map(_.toInt) 13 | val sides = Seq(l + w, w + h, h + l) 14 | 2 * sides.min + (l * w * h) 15 | } 16 | .sum 17 | 18 | def main(args: Array[String]): Unit = 19 | val data = io.Source.fromResource("AdventOfCode2015/Day02.txt").getLines().toSeq 20 | println(part1(data)) 21 | println(part2(data)) 22 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2015/Day03.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | object Day03: 4 | val directions = Map('^' -> (0, -1), 'v' -> (0, 1), '<' -> (-1, 0), '>' -> (1, 0)) 5 | 6 | case class Point(x: Int, y: Int): 7 | def delta(dx: Int, dy: Int) = Point(x + dx, y + dy) 8 | 9 | def deliver(input: Seq[Char]): Seq[Point] = 10 | input.scanLeft(Point(0, 0))((location, next) => location.delta.tupled(directions(next))) 11 | 12 | def part1(input: String): Int = deliver(input).distinct.size 13 | 14 | def part2(input: String): Int = 15 | val (santa, robot) = input.zipWithIndex.partitionMap((c, i) => if i % 2 == 0 then Left(c) else Right(c)) 16 | (deliver(santa) ++ deliver(robot)).distinct.size 17 | 18 | def main(args: Array[String]): Unit = 19 | val data = io.Source.fromResource("AdventOfCode2015/Day03.txt").mkString.trim 20 | println(part1(data)) 21 | println(part2(data)) 22 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2015/Day04.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | object Day04: 4 | val md5 = java.security.MessageDigest.getInstance("MD5") 5 | 6 | def hash(string: String): Array[Byte] = md5.digest(string.getBytes) 7 | 8 | def search(salt: String, predicate: Array[Byte] => Boolean): Int = 9 | Iterator.from(1).indexWhere(index => predicate(hash(s"$salt$index"))) + 1 10 | 11 | def part1(input: String): Int = search(input, a => a(0) == 0 && a(1) == 0 && (a(2) & 0xF0) == 0) 12 | 13 | def part2(input: String): Int = search(input, a => a(0) == 0 && a(1) == 0 && a(2) == 0) 14 | 15 | def main(args: Array[String]): Unit = 16 | val data = io.Source.fromResource("AdventOfCode2015/Day04.txt").mkString.trim 17 | println(part1(data)) 18 | println(part2(data)) 19 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2015/Day05.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | object Day05: 4 | def regex(patterns: String*): Seq[scala.util.matching.Regex] = patterns.map(_.r.unanchored) 5 | 6 | def part1(input: Seq[String]): Int = 7 | val Seq(vowels, pair, naughty) = regex("[aeiou].*[aeiou].*[aeiou]", "(.)\\1", "ab|cd|pq|xy") 8 | input.count(line => vowels.matches(line) && pair.matches(line) && !naughty.matches(line)) 9 | 10 | def part2(input: Seq[String]): Int = 11 | val Seq(twoPair, triple) = regex("(..).*\\1", "(.).\\1") 12 | input.count(line => twoPair.matches(line) && triple.matches(line)) 13 | 14 | def main(args: Array[String]): Unit = 15 | val data = io.Source.fromResource("AdventOfCode2015/Day05.txt").getLines().toSeq 16 | println(part1(data)) 17 | println(part2(data)) 18 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2015/Day08.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | object Day08: 4 | def part1(input: Seq[String]): Int = input.map { line => 5 | line.length - line.tail.init.replace("\\\\", "S").replace("\\\"", "Q").replaceAll("\\\\x..", "X").length 6 | } 7 | .sum 8 | 9 | def part2(input: Seq[String]): Int = input.map(line => 2 + line.count(c => c == '\\' || c == '\"')).sum 10 | 11 | def main(args: Array[String]): Unit = 12 | val data = io.Source.fromResource("AdventOfCode2015/Day08.txt").getLines().toSeq 13 | println(part1(data)) 14 | println(part2(data)) 15 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2015/Day09.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | object Day09: 4 | def parse(input: Seq[String]): Seq[(Set[String], Int)] = input.map { line => 5 | val Array(first, _, second, _, distance) = line.split(" ") 6 | Set(first, second) -> distance.toInt 7 | } 8 | 9 | def tsp(input: Seq[String]): Iterator[Int] = 10 | val pairs = parse(input).toMap 11 | pairs.keys.flatten.toSeq.permutations.map(_.sliding(2).map(_.toSet).map(pairs).sum) 12 | 13 | def part1(input: Seq[String]): Int = tsp(input).min 14 | 15 | def part2(input: Seq[String]): Int = tsp(input).max 16 | 17 | def main(args: Array[String]): Unit = 18 | val data = io.Source.fromResource("AdventOfCode2015/Day09.txt").getLines().toSeq 19 | println(part1(data)) 20 | println(part2(data)) 21 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2015/Day10.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | import collection.mutable.ArrayBuffer 4 | 5 | object Day10: 6 | def step(initial: ArrayBuffer[Char]): ArrayBuffer[Char] = 7 | val buffer = ArrayBuffer[Char]() 8 | initial.appended('x').foldLeft(0 -> initial.head) { case ((count, previous), next) => 9 | if previous == next then 10 | (count + 1, previous) 11 | else 12 | buffer.append((count + '0').toChar).append(previous) 13 | (1, next) 14 | } 15 | buffer 16 | 17 | def generate(input: String, count: Int): Int = Iterator.iterate(ArrayBuffer.from(input))(step).drop(count).next().size 18 | 19 | def part1(input: String): Int = generate(input, 40) 20 | 21 | def part2(input: String): Int = generate(input, 50) 22 | 23 | def main(args: Array[String]): Unit = 24 | val data = io.Source.fromResource("AdventOfCode2015/Day10.txt").mkString.trim 25 | println(part1(data)) 26 | println(part2(data)) 27 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2015/Day11.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | object Day11: 4 | def increment(password: String): String = 5 | def helper(string: String, index: Int): String = 6 | if string(index) == 'z' then helper(string.updated(index, 'a'), index - 1) 7 | else string.updated(index, (string(index) + 1).toChar) 8 | helper(password, password.size - 1) 9 | 10 | def requirement(password: String): Boolean = 11 | password.sliding(3).exists(w => w(1) - w(0) == 1 && w(2) - w(1) == 1) 12 | && !password.exists(c => c == 'i' || c == 'o' || c == 'l') 13 | && password.sliding(2).filter(w => w(0) == w(1)).toSet.size >= 2 14 | 15 | def next(input: String): String = Iterator.iterate(input)(increment).drop(1).filter(requirement).next() 16 | 17 | def part1(input: String): String = next(input) 18 | 19 | def part2(input: String): String = next(next(input)) 20 | 21 | def main(args: Array[String]): Unit = 22 | val data = io.Source.fromResource("AdventOfCode2015/Day11.txt").mkString.trim 23 | println(part1(data)) 24 | println(part2(data)) 25 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2015/Day13.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | object Day13: 4 | def parse(input: Seq[String]): Map[Seq[String], Int] = 5 | input.map { line => 6 | val tokens = line.init.split(" ") 7 | Seq(tokens(0), tokens(10)) -> (if tokens(2) == "gain" then tokens(3).toInt else -tokens(3).toInt) 8 | } 9 | .toMap.withDefaultValue(0) 10 | 11 | def happiness(pairs: Map[Seq[String], Int], extra: Seq[String]): Int = 12 | val guests = pairs.keys.flatten.toSeq.distinct ++ extra 13 | guests.permutations.map { next => 14 | next.appended(next.head).sliding(2).map(pair => pairs(pair) + pairs(pair.reverse)).sum 15 | } 16 | .max 17 | 18 | def part1(input: Seq[String]): Int = happiness(parse(input), Seq()) 19 | 20 | def part2(input: Seq[String]): Int = happiness(parse(input), Seq("me")) 21 | 22 | def main(args: Array[String]): Unit = 23 | val data = io.Source.fromResource("AdventOfCode2015/Day13.txt").getLines().toSeq 24 | println(part1(data)) 25 | println(part2(data)) 26 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2015/Day14.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | object Day14: 4 | case class Reindeer(speed: Int, fly: Int, rest: Int): 5 | def distance(time: Int): Int = 6 | val total = fly + rest 7 | val complete = time / total 8 | val partial = (time % total).min(fly) 9 | speed * (complete * fly + partial) 10 | 11 | def parse(input: Seq[String]): Seq[Reindeer] = input.map { line => 12 | val Array(speed, fly, rest) = line.split("\\D+").tail.map(_.toInt) 13 | Reindeer(speed, fly, rest) 14 | } 15 | 16 | def part1(input: Seq[String], time: Int): Int = parse(input).map(_.distance(time)).max 17 | 18 | def part2(input: Seq[String], time: Int): Int = 19 | val reindeer = parse(input) 20 | (1 to time) 21 | .map(time => reindeer.map(_.distance(time))) 22 | .map(state => state.map(d => if d == state.max then 1 else 0)) 23 | .transpose.map(_.sum).max 24 | 25 | def main(args: Array[String]): Unit = 26 | val data = io.Source.fromResource("AdventOfCode2015/Day14.txt").getLines().toSeq 27 | println(part1(data, 2503)) 28 | println(part2(data, 2503)) 29 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2015/Day15.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | object Day15: 4 | def recipes(input: Seq[String]): Iterator[Seq[Int]] = 5 | val ingredients = input.map(_.split("[^-\\d]+").tail.map(_.toInt)) 6 | def range(offset: Int) = Iterator.range(0, 101 - offset) 7 | for 8 | a <- range(0) 9 | b <- range(a) 10 | c <- range(a + b) 11 | d <- range(a + b + c) 12 | if a + b + c + d == 100 13 | yield Seq(a, b, c, d).zip(ingredients).map((k, i) => i.map(_ * k)).transpose.map(_.sum.max(0)) 14 | 15 | def part1(input: Seq[String]): Int = recipes(input).map(_.init.product).max 16 | 17 | def part2(input: Seq[String]): Int = recipes(input).filter(_.last == 500).map(_.init.product).max 18 | 19 | def main(args: Array[String]): Unit = 20 | val data = io.Source.fromResource("AdventOfCode2015/Day15.txt").getLines().toSeq 21 | println(part1(data)) 22 | println(part2(data)) 23 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2015/Day17.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | object Day17: 4 | def knapsack(input: Seq[Int]): Iterator[Set[(Int, Int)]] = 5 | input.zipWithIndex.toSet.subsets.filter(_.toSeq.map(_._1).sum == 150) 6 | 7 | def part1(input: Seq[Int]): Int = knapsack(input).size 8 | 9 | def part2(input: Seq[Int]): Int = 10 | val occurrences = knapsack(input).toSeq.groupBy(_.size) 11 | occurrences(occurrences.keys.min).size 12 | 13 | def main(args: Array[String]): Unit = 14 | val data = io.Source.fromResource("AdventOfCode2015/Day17.txt").getLines().map(_.toInt).toSeq 15 | println(part1(data)) 16 | println(part2(data)) 17 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2015/Day20.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | object Day20: 4 | def part1(target: Int): Int = 5 | val limit = target / 10 6 | val houses = Array.fill(limit + 1)(10) 7 | for x <- 2 to limit; y <- x to limit by x do houses(y) += 10 * x 8 | houses.indexWhere(_ >= target) 9 | 10 | def part2(target: Int): Int = 11 | val limit = target / 10 12 | val houses = Array.fill(limit + 1)(10) 13 | for x <- 2 to limit; y <- (x to limit by x).take(50) do houses(y) += 11 * x 14 | houses.indexWhere(_ >= target) 15 | 16 | def main(args: Array[String]): Unit = 17 | val data = io.Source.fromResource("AdventOfCode2015/Day20.txt").mkString.trim.toInt 18 | println(part1(data)) 19 | println(part2(data)) 20 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2015/Day24.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | object Day24: 4 | def balance(input: Seq[Long], groups: Int): Long = 5 | val limit = input.sum / groups 6 | Iterator.from(1).flatMap(input.combinations(_).filter(_.sum == limit).map(_.product)).next() 7 | 8 | def part1(input: Seq[Long]): Long = balance(input, 3) 9 | 10 | def part2(input: Seq[Long]): Long = balance(input, 4) 11 | 12 | def main(args: Array[String]): Unit = 13 | val data = io.Source.fromResource("AdventOfCode2015/Day24.txt").getLines().map(_.toLong).toSeq 14 | println(part1(data)) 15 | println(part2(data)) 16 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2015/Day25.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | object Day25: 4 | def parse(input: String): (Int, Int) = 5 | val Array(row, column) = input.split("\\D+").tail.map(_.toInt) 6 | (row, column) 7 | 8 | def diagonalIndex(row: Int, column: Int): Int = 9 | val n = row + column - 2 10 | val sum = (n * (n + 1)) / 2 11 | sum + column - 1 12 | 13 | def code(n: Int): Int = ((20151125 * BigInt(252533).modPow(n, 33554393)) % 33554393).toInt 14 | 15 | def part1(input: String): Int = code(diagonalIndex.tupled(parse(input))) 16 | 17 | def main(args: Array[String]): Unit = 18 | val data = io.Source.fromResource("AdventOfCode2015/Day25.txt").mkString.trim 19 | println(part1(data)) 20 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2016/Day03.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | object Day03: 4 | def split(line: String): Seq[Int] = line.trim.split(" +").map(_.toInt).toSeq 5 | 6 | def triangle(row: Seq[Int]): Boolean = 7 | val Seq(a, b, c) = row 8 | a < b + c && b < a + c && c < a + b 9 | 10 | def part1(input: Seq[String]): Int = input.map(split).count(triangle) 11 | 12 | def part2(input: Seq[String]): Int = input.map(split).grouped(3).flatMap(_.transpose).count(triangle) 13 | 14 | def main(args: Array[String]): Unit = 15 | val data = io.Source.fromResource("AdventOfCode2016/Day03.txt").getLines().toSeq 16 | println(part1(data)) 17 | println(part2(data)) 18 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2016/Day04.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | object Day04: 4 | case class Room(name: String, id: Int, checksum: String) 5 | 6 | def parse(input: Seq[String]): Seq[Room] = 7 | val regex = """([\w\-]+)-(\d+)\[(\w{5})\]""".r 8 | input.map { case regex(name, id, checksum) => Room(name, id.toInt, checksum) } 9 | 10 | def real(room: Room): Boolean = 11 | val occurrences = room.name.filterNot(_ == '-').groupMapReduce(identity)(_ => 1)(_ + _) 12 | room.checksum == occurrences.toSeq.map((a,b) => (-b,a)).sorted.take(5).map(_._2).mkString 13 | 14 | def decode(room: Room): Room = 15 | room.copy(name = room.name.map(c => if c == '-' then ' ' else ('a' + (c - 'a' + room.id) % 26).toChar)) 16 | 17 | def part1(input: Seq[String]): Int = parse(input).filter(real).map(_.id).sum 18 | 19 | def part2(input: Seq[String]): Int = 20 | parse(input).filter(real).map(decode).find(_.name == "northpole object storage").get.id 21 | 22 | def main(args: Array[String]): Unit = 23 | val data = io.Source.fromResource("AdventOfCode2016/Day04.txt").getLines().toSeq 24 | println(part1(data)) 25 | println(part2(data)) 26 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2016/Day06.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | object Day06: 4 | def frequency(seq: Seq[Char]): Seq[Char] = seq.groupBy(identity).toSeq.sortBy(_._2.size).map(_._1) 5 | 6 | def part1(input: Seq[String]): String = input.transpose.map(frequency(_).last).mkString 7 | 8 | def part2(input: Seq[String]): String = input.transpose.map(frequency(_).head).mkString 9 | 10 | def main(args: Array[String]): Unit = 11 | val data = io.Source.fromResource("AdventOfCode2016/Day06.txt").getLines().toSeq 12 | println(part1(data)) 13 | println(part2(data)) 14 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2016/Day09.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | object Day09: 4 | val regex = """\((\d+)x(\d+)\)(.*)""".r 5 | 6 | def part1(input: String, size: Long = 0): Long = if input.isEmpty then size else input match 7 | case regex(count, repeat, rest) => part1(rest.drop(count.toInt), size + repeat.toLong * count.toInt) 8 | case _ => part1(input.tail, size + 1) 9 | 10 | def part2(input: String, size: Long = 0): Long = if input.isEmpty then size else input match 11 | case regex(count, repeat, rest) => part2(rest.drop(count.toInt), size + repeat.toLong * part2(rest.take(count.toInt))) 12 | case _ => part2(input.tail, size + 1) 13 | 14 | def main(args: Array[String]): Unit = 15 | val data = io.Source.fromResource("AdventOfCode2016/Day09.txt").mkString.trim 16 | println(part1(data)) 17 | println(part2(data)) 18 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2016/Day15.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | object Day15: 4 | case class Disc(index: Int, size: Int, offset: Int): 5 | def pass(time: Int) = (time + index + offset) % size == 0 6 | 7 | def parse(input: Seq[String]): Seq[Disc] = input.map { line => 8 | val tokens = line.split("\\D+").tail.map(_.toInt) 9 | Disc(tokens(0), tokens(1), tokens(3)) 10 | } 11 | 12 | def firstTime(discs: Seq[Disc]): Int = Iterator.from(0).filter(time => discs.forall(_.pass(time))).next() 13 | 14 | def part1(input: Seq[String]): Int = firstTime(parse(input)) 15 | 16 | def part2(input: Seq[String]): Int = 17 | val discs = parse(input) 18 | val expanded = discs.appended(Disc(discs.size + 1, 11, 0)) 19 | firstTime(expanded) 20 | 21 | def main(args: Array[String]): Unit = 22 | val data = io.Source.fromResource("AdventOfCode2016/Day15.txt").getLines().toSeq 23 | println(part1(data)) 24 | println(part2(data)) 25 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2016/Day16.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | object Day16: 4 | def dragon(start: String, target: Int): String = 5 | def step(s: String) = s.appended('0').appendedAll(s.reverse.map(b => if b == '1' then '0' else '1')) 6 | Iterator.iterate(start)(step).dropWhile(_.length < target).next().take(target) 7 | 8 | def checksum(start: String): String = 9 | val groupSize = Integer.lowestOneBit(start.length) 10 | def step(s: String) = s.grouped(groupSize).map(g => if g.count(_ == '1') % 2 == 0 then '1' else '0').mkString 11 | Iterator.iterate(start)(step).dropWhile(_.length % 2 == 0).next() 12 | 13 | def part1(input: String): String = checksum(dragon(input, 272)) 14 | 15 | def part2(input: String): String = checksum(dragon(input, 35651584)) 16 | 17 | def main(args: Array[String]): Unit = 18 | val data = io.Source.fromResource("AdventOfCode2016/Day16.txt").mkString.trim 19 | println(part1(data)) 20 | println(part2(data)) 21 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2016/Day18.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | object Day18: 4 | def safe(input: String, count: Int): Int = 5 | val width = input.length 6 | val start = BigInt(input.map(c => if c == '^' then '1' else '0'), 2) 7 | def step(n: BigInt) = (n << 1).clearBit(width) ^ (n >> 1) 8 | Iterator.iterate(start)(step).map(width - _.bitCount).take(count).sum 9 | 10 | def part1(input: String): Int = safe(input, 40) 11 | 12 | def part2(input: String): Int = safe(input, 400000) 13 | 14 | def main(args: Array[String]): Unit = 15 | val data = io.Source.fromResource("AdventOfCode2016/Day18.txt").mkString.trim 16 | println(part1(data)) 17 | println(part2(data)) 18 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2016/Day19.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | object Day19: 4 | def part1(input: Int): Int = ((input - Integer.highestOneBit(input)) << 1) + 1 5 | 6 | def part2(input: Int): Int = 7 | case class Node(value: Int, var next: Node) 8 | 9 | var node = Node(1, null) 10 | node.next = node 11 | 12 | for n <- 2 to input do 13 | val next = Node(n, node.next) 14 | node.next = next 15 | node = next 16 | 17 | for i <- 1 to input / 2 do 18 | node = node.next 19 | 20 | for i <- input to 2 by -1 do 21 | node.next = node.next.next 22 | if i % 2 == 1 then node = node.next 23 | 24 | node.value 25 | end part2 26 | 27 | def main(args: Array[String]): Unit = 28 | val data = io.Source.fromResource("AdventOfCode2016/Day19.txt").mkString.trim.toInt 29 | println(part1(data)) 30 | println(part2(data)) 31 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2017/Day01.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | object Day01: 4 | def part1(input: Seq[Int]): Int = input 5 | .appended(input.head) 6 | .sliding(2) 7 | .map { case Seq(a, b) => if a == b then a else 0 } 8 | .sum 9 | 10 | def part2(input: Seq[Int]): Int = input 11 | .zipWithIndex 12 | .map { (d, i) => if d == input((i + input.size / 2) % input.size) then d else 0 } 13 | .sum 14 | 15 | def main(args: Array[String]): Unit = 16 | val data = io.Source.fromResource("AdventOfCode2017/Day01.txt").mkString.trim.map(_.asDigit) 17 | println(part1(data)) 18 | println(part2(data)) 19 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2017/Day02.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | object Day02: 4 | def parse(input: Seq[String]): Seq[Seq[Int]] = input.map(_.split("\\D+").map(_.toInt).toSeq) 5 | 6 | def part1(input: Seq[String]): Int = parse(input).map(row => row.max - row.min).sum 7 | 8 | def part2(input: Seq[String]): Int = parse(input).flatMap { row => 9 | row.combinations(2).map { case Seq(a, b) => if a.max(b) % a.min(b) == 0 then a.max(b) / a.min(b) else 0 } 10 | } 11 | .sum 12 | 13 | def main(args: Array[String]): Unit = 14 | val data = io.Source.fromResource("AdventOfCode2017/Day02.txt").getLines().toSeq 15 | println(part1(data)) 16 | println(part2(data)) 17 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2017/Day04.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | object Day04: 4 | def part1(input: Seq[String]): Int = input.count { line => 5 | val array = line.split(" ") 6 | array.size == array.toSet.size 7 | } 8 | 9 | def part2(input: Seq[String]): Int = input.count { line => 10 | val array = line.split(" ").map(_.sorted) 11 | array.size == array.toSet.size 12 | } 13 | 14 | def main(args: Array[String]): Unit = 15 | val data = io.Source.fromResource("AdventOfCode2017/Day04.txt").getLines().toSeq 16 | println(part1(data)) 17 | println(part2(data)) 18 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2017/Day05.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | import scala.annotation.tailrec 4 | 5 | object Day05: 6 | def part1(input: Seq[Int]): Int = 7 | @tailrec 8 | def helper(jumps: Seq[Int], index: Int, steps: Int): Int = 9 | if index >= input.size then steps 10 | else helper(jumps.updated(index, jumps(index) + 1), index + jumps(index), steps + 1) 11 | 12 | helper(input, 0, 0) 13 | end part1 14 | 15 | def part2(input: Seq[Int]): Int = 16 | @tailrec 17 | def helper(jumps: Seq[Int], index: Int, steps: Int): Int = 18 | if index >= input.size then steps 19 | else if jumps(index) >= 3 then helper(jumps.updated(index, jumps(index) - 1), index + jumps(index), steps + 1) 20 | else helper(jumps.updated(index, jumps(index) + 1), index + jumps(index), steps + 1) 21 | 22 | helper(input, 0, 0) 23 | end part2 24 | 25 | def main(args: Array[String]): Unit = 26 | val data = io.Source.fromResource("AdventOfCode2017/Day05.txt").getLines().map(_.toInt).toSeq 27 | println(part1(data)) 28 | println(part2(data)) 29 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2017/Day09.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | object Day09: 4 | case class State(groupDepth: Int, groupScore: Int, garbage: Boolean, garbageScore: Int, ignoreNext: Boolean): 5 | def step(next: Char): State = next match 6 | case _ if ignoreNext => copy(ignoreNext = false) 7 | case '!' => copy(ignoreNext = true) 8 | case '>' => copy(garbage = false) 9 | case _ if garbage => copy(garbageScore = garbageScore + 1) 10 | case '{' => copy(groupDepth = groupDepth + 1, groupScore = groupScore + groupDepth) 11 | case '}' => copy(groupDepth = groupDepth - 1) 12 | case '<' => copy(garbage = true) 13 | case _ => this 14 | 15 | def stream(input: String): State = 16 | val initial = State(1, 0, false, 0, false) 17 | input.foldLeft(initial)((state, next) => state.step(next)) 18 | 19 | def part1(input: String): Int = stream(input).groupScore 20 | 21 | def part2(input: String): Int = stream(input).garbageScore 22 | 23 | def main(args: Array[String]): Unit = 24 | val data = io.Source.fromResource("AdventOfCode2017/Day09.txt").mkString.trim 25 | println(part1(data)) 26 | println(part2(data)) 27 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2017/Day10.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | object Day10: 4 | def knot(lengths: Seq[Int]): Seq[Int] = 5 | val initial = (Seq.range(0, 256), 0) 6 | val (data, index) = lengths.zipWithIndex.foldLeft(initial) { case ((data, index), (length, skip)) => 7 | val next = data.take(length).reverse ++ data.drop(length) 8 | val offset = (length + skip) & 0xFF 9 | (next.drop(offset) ++ next.take(offset), (index - offset) & 0xFF) 10 | } 11 | data.drop(index) ++ data.take(index) 12 | 13 | def part1(input: String): Int = 14 | val lengths = input.split(",").map(_.toInt).toSeq 15 | knot(lengths).take(2).product 16 | 17 | def part2(input: String): String = 18 | val lengths = input.map(_.toInt) ++ Seq(17, 31, 73, 47, 23) 19 | val repeated = Seq.fill(64)(lengths).flatten 20 | knot(repeated).grouped(16).map(_.reduce(_ ^ _)).map("%02x".format(_)).mkString 21 | 22 | def main(args: Array[String]): Unit = 23 | val data = io.Source.fromResource("AdventOfCode2017/Day10.txt").mkString.trim 24 | println(part1(data)) 25 | println(part2(data)) 26 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2017/Day11.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | object Day11: 4 | case class Hex(q: Int, r: Int): 5 | def manhattan: Int = q.abs.max(r.abs) 6 | def step(next: String): Hex = next match 7 | case "n" => Hex(q + 1, r - 1) 8 | case "s" => Hex(q - 1, r + 1) 9 | case "ne" => Hex(q + 1, r) 10 | case "sw" => Hex(q - 1, r) 11 | case "nw" => Hex(q, r - 1) 12 | case "se" => Hex(q, r + 1) 13 | 14 | def walk(input: String): Seq[Int] = input.split(",").scanLeft(Hex(0, 0))(_.step(_)).map(_.manhattan).toSeq 15 | 16 | def part1(input: String): Int = walk(input).last 17 | 18 | def part2(input: String): Int = walk(input).max 19 | 20 | def main(args: Array[String]): Unit = 21 | val data = io.Source.fromResource("AdventOfCode2017/Day11.txt").mkString.trim 22 | println(part1(data)) 23 | println(part2(data)) 24 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2017/Day12.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | object Day12: 4 | def cliques(input: Seq[String]): Set[Set[Int]] = input 5 | .map(_.split("\\D+").map(_.toInt).toSet) 6 | .foldLeft(Set.empty[Set[Int]]) { (groups, direct) => 7 | val (other, linked) = groups.partition(_.intersect(direct).size == 0) 8 | other + (linked.flatten ++ direct) 9 | } 10 | 11 | def part1(input: Seq[String]): Int = cliques(input).filter(_.contains(0)).flatten.size 12 | 13 | def part2(input: Seq[String]): Int = cliques(input).size 14 | 15 | def main(args: Array[String]): Unit = 16 | val data = io.Source.fromResource("AdventOfCode2017/Day12.txt").getLines().toSeq 17 | println(part1(data)) 18 | println(part2(data)) 19 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2017/Day13.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | object Day13: 4 | def parse(input: Seq[String]): Seq[(Int, Int)] = input.map { line => 5 | val Array(depth, range) = line.split(": ").map(_.toInt) 6 | depth -> range 7 | } 8 | 9 | def severity(firewall: Seq[(Int, Int)], delay: Int): Seq[Int] = firewall.flatMap { (depth, range) => 10 | val caught = (depth + delay) % (2 * range - 2) == 0 11 | Option.when(caught)(depth * range) 12 | } 13 | 14 | def part1(input: Seq[String]): Int = severity(parse(input), 0).sum 15 | 16 | def part2(input: Seq[String]): Int = 17 | val firewall = parse(input) 18 | Iterator.from(0).indexWhere(severity(firewall, _).isEmpty) 19 | 20 | def main(args: Array[String]): Unit = 21 | val data = io.Source.fromResource("AdventOfCode2017/Day13.txt").getLines().toSeq 22 | println(part1(data)) 23 | println(part2(data)) 24 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2017/Day15.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | object Day15: 4 | def parse(input: Seq[String]): (Iterator[Long], Iterator[Long]) = 5 | val Seq(a, b) = input.map(_.filter(_.isDigit).toLong) 6 | (generator(a, 16807), generator(b, 48271)) 7 | 8 | def generator(start: Long, factor: Long): Iterator[Long] = 9 | Iterator.iterate(start)(n => (n * factor) % 2147483647).drop(1) 10 | 11 | def judge(a: Long, b: Long): Boolean = (a & 0xFFFF) == (b & 0xFFFF) 12 | 13 | def part1(input: Seq[String]): Int = 14 | val (a, b) = parse(input) 15 | a.zip(b).take(40000000).count(judge) 16 | 17 | def part2(input: Seq[String]): Int = 18 | val (a, b) = parse(input) 19 | a.filter(_ % 4 == 0).zip(b.filter(_ % 8 == 0)).take(5000000).count(judge) 20 | 21 | def main(args: Array[String]): Unit = 22 | val data = io.Source.fromResource("AdventOfCode2017/Day15.txt").getLines().toSeq 23 | println(part1(data)) 24 | println(part2(data)) 25 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2017/Day17.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | object Day17: 4 | def part1(input: Int): Int = 5 | var index = 0 6 | val buffer = collection.mutable.ArrayBuffer(0) 7 | 8 | for i <- 1 to 2017 do 9 | index = (index + input + 1) % i 10 | buffer.insert(index, i) 11 | 12 | buffer(index + 1) 13 | end part1 14 | 15 | def part2(input: Int): Int = 16 | var index = 0 17 | var result = -1 18 | 19 | for i <- 1 to 50000000 do 20 | index = (index + input + 1) % i 21 | if index == 0 then result = i 22 | 23 | result 24 | end part2 25 | 26 | def main(args: Array[String]): Unit = 27 | val data = 304 28 | println(part1(data)) 29 | println(part2(data)) -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2018/Day01.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | import scala.annotation.tailrec 4 | 5 | object Day01: 6 | def part1(input: Seq[Int]): Int = input.sum 7 | 8 | def part2(input: Seq[Int]): Int = 9 | def helper(index: Int, frequency: Int, previous: Set[Int]): Int = 10 | val nextFrequency = frequency + input(index % input.size) 11 | if previous.contains(nextFrequency) then nextFrequency 12 | else helper(index + 1, nextFrequency, previous + nextFrequency) 13 | 14 | helper(0, 0, Set()) 15 | end part2 16 | 17 | def main(args: Array[String]): Unit = 18 | val data = io.Source.fromResource("AdventOfCode2018/Day01.txt").getLines().map(_.toInt).toSeq 19 | println(part1(data)) 20 | println(part2(data)) 21 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2018/Day02.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | object Day02: 4 | def part1(input: Seq[String]): Int = 5 | val occurences = input.map(_.groupMapReduce(identity)(_ => 1)(_ + _).values.toSet) 6 | occurences.count(_.contains(2)) * occurences.count(_.contains(3)) 7 | 8 | def part2(input: Seq[String]): String = 9 | input.combinations(2).map { case Seq(first, second) => 10 | first.zip(second).collect { case (a, b) if a == b => a }.mkString 11 | } 12 | .filter(_.size == input.head.size - 1).next() 13 | 14 | def main(args: Array[String]): Unit = 15 | val data = io.Source.fromResource("AdventOfCode2018/Day02.txt").getLines().toSeq 16 | println(part1(data)) 17 | println(part2(data)) 18 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2018/Day03.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | object Day03: 4 | case class Point(x: Int, y: Int) 5 | 6 | def parse(input: Seq[String]): (Seq[Seq[Point]], Map[Point, Int]) = 7 | val regex = """#(\d+) @ (\d+),(\d+): (\d+)x(\d+)""".r 8 | val claims = input 9 | .map { case regex(groups*) => groups.map(_.toInt) } 10 | .map { case Seq(id, left, top, width, height) => 11 | for x <- left until left + width; y <- top until top + height yield Point(x, y) 12 | } 13 | val overlaps = claims.flatten.groupMapReduce(identity)(_ => 1)(_ + _) 14 | (claims, overlaps) 15 | end parse 16 | 17 | def part1(input: Seq[String]): Int = 18 | val (_, overlaps) = parse(input) 19 | overlaps.map(_._2).count(_ > 1) 20 | 21 | def part2(input: Seq[String]): Int = 22 | val (claims, overlaps) = parse(input) 23 | 1 + claims.indexWhere(claim => claim.forall(point => overlaps(point) == 1)) 24 | 25 | def main(args: Array[String]): Unit = 26 | val data = io.Source.fromResource("AdventOfCode2018/Day03.txt").getLines().toSeq 27 | println(part1(data)) 28 | println(part2(data)) 29 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2018/Day05.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | import scala.annotation.tailrec 4 | 5 | object Day05: 6 | def react(l: Char, r: Char): Boolean = (l.toLower == r.toLower) && (l.isLower ^ r.isLower) 7 | 8 | def shorten(input: String): Int = 9 | @tailrec 10 | def helper(left: List[Char], right: List[Char]): Int = (left, right) match 11 | case (left, Nil) => left.size 12 | case (left :: ls, right :: rs) if react(left, right) => helper(ls, rs) 13 | case (left, right :: rs) => helper(right :: left, rs) 14 | 15 | helper(Nil, input.toList) 16 | end shorten 17 | 18 | def part1(input: String): Int = shorten(input) 19 | 20 | def part2(input: String): Int = 21 | val variations = for unitType <- 'a' to 'z' yield input.filter(_.toLower != unitType) 22 | variations.map(shorten).min 23 | 24 | def main(args: Array[String]): Unit = 25 | val data = io.Source.fromResource("AdventOfCode2018/Day05.txt").mkString.trim 26 | println(part1(data)) 27 | println(part2(data)) 28 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2018/Day10.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | object Day10: 4 | case class Point(x: Int, y: Int, dx: Int, dy: Int): 5 | def next: Point = Point(x + dx, y + dy, dx, dy) 6 | 7 | def main(args: Array[String]): Unit = 8 | val data = io.Source.fromResource("AdventOfCode2018/Day10.txt").getLines().toSeq 9 | var points = data.map { line => 10 | val Array(x, y, dx, dy) = line.split("[^-\\d]+").tail.map(_.toInt) 11 | Point(x, y, dx, dy) 12 | } 13 | 14 | var (left, right, top, bottom, seconds) = (0, 0, 0, 0, 0) 15 | var area = 550L 16 | 17 | while area >= 550L do 18 | points = points.map(_.next) 19 | left = points.map(_.x).min 20 | right = points.map(_.x).max 21 | top = points.map(_.y).min 22 | bottom = points.map(_.y).max 23 | area = (right - left).toLong * (bottom - top).toLong 24 | seconds += 1 25 | end while 26 | 27 | for y <- top to bottom do 28 | for x <- left to right do 29 | print(if points.exists(point => point.x == x && point.y == y) then '#' else ' ') 30 | println() 31 | println(s"Seconds: $seconds") 32 | end main 33 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2018/Day19.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | // Reverse engineering the instructions shows that the code is computing 4 | // the sum of every factor of an integer value. 5 | // The original code implements this in 0(N^2) quadratic complexity using 2 nested loops. 6 | // Switching the first register to 1 computes a larger (and hence dramatically slower) value 7 | // The hardcoded values for part 1 and part2 are extracted from reading and hand stepping 8 | // through the code. 9 | object Day19: 10 | def factorSum(n: Int, x: Int = 1, total: Int = 0): Int = 11 | if n % x == 0 then 12 | val y = n / x 13 | if y < x then total else factorSum(n, x + 1, total + x + y) 14 | else factorSum(n, x + 1, total) 15 | 16 | def part1: Int = factorSum(950) 17 | 18 | def part2: Int = factorSum(10551350) 19 | 20 | def main(args: Array[String]): Unit = 21 | println(part1) 22 | println(part2) 23 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2018/Day25.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | object Day25: 4 | case class Point(x: Int, y: Int, z: Int, w: Int): 5 | def manhattan(other: Point): Int = (x - other.x).abs + (y - other.y).abs + (z - other.z).abs + (w - other.w).abs 6 | 7 | def part1(input: Seq[String]): Int = input 8 | .map { _.split(",").map(_.toInt) } 9 | .map { case Array(x, y, z, w) => Point(x, y, w, z) } 10 | .foldLeft(Set.empty[Set[Point]]) { (constellations, point) => 11 | val (near, far) = constellations.partition(_.exists(_.manhattan(point) <= 3)) 12 | far + (near.flatten + point) 13 | } 14 | .size 15 | 16 | def main(args: Array[String]): Unit = 17 | val data = io.Source.fromResource("AdventOfCode2018/Day25.txt").getLines().toSeq 18 | println(part1(data)) 19 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2019/Day01.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | object Day01: 4 | def fuel(mass: Int): Int = mass / 3 - 2 5 | def tsiolkovsky(mass: Int): Int = if mass < 7 then 0 else fuel(mass) + tsiolkovsky(fuel(mass)) 6 | 7 | def part1(input: Seq[Int]): Int = input.map(fuel).sum 8 | def part2(input: Seq[Int]): Int = input.map(tsiolkovsky).sum 9 | 10 | def main(args: Array[String]): Unit = 11 | val data = io.Source.fromResource("AdventOfCode2019/Day01.txt").getLines().map(_.toInt).toSeq 12 | println(part1(data)) 13 | println(part2(data)) 14 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2019/Day02.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | object Day02: 4 | def exec(code: Seq[Int]): Int = 5 | def helper(ip: Int, code: Seq[Int]): Int = 6 | code(ip) match 7 | case 1 => helper(ip + 4, code.updated(code(ip + 3), code(code(ip + 1)) + code(code(ip + 2)))) 8 | case 2 => helper(ip + 4, code.updated(code(ip + 3), code(code(ip + 1)) * code(code(ip + 2)))) 9 | case 99 => code.head 10 | helper(0, code) 11 | end exec 12 | 13 | def part1(input: Seq[Int]): Int = exec(input.updated(1, 12).updated(2, 2)) 14 | 15 | def part2(input: Seq[Int]): Int = 16 | val permutations = for noun <- 1 to 99; verb <- 1 to 99 yield (noun, verb) 17 | val (noun, verb) = permutations.dropWhile((noun, verb) => exec(input.updated(1, noun).updated(2, verb)) != 19690720).head 18 | 100 * noun + verb 19 | 20 | def main(args: Array[String]): Unit = 21 | val data = io.Source.fromResource("AdventOfCode2019/Day02.txt").mkString.trim.split(",").map(_.toInt).toSeq 22 | println(part1(data)) 23 | println(part2(data)) 24 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2019/Day04.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | object Day04: 4 | def part1(input: Seq[Int]): Int = 5 | (input.head to input.last).count { number => 6 | def window = number.toString.map(_.asDigit).sliding(2) 7 | val rule1 = window.forall { case Seq(a, b) => a <= b } 8 | val rule2 = window.exists { case Seq(a, b) => a == b } 9 | rule1 && rule2 10 | } 11 | 12 | def part2(input: Seq[Int]): Int = 13 | (input.head to input.last).count { number => 14 | def window(size: Int) = number.toString.map(_.asDigit).sliding(size) 15 | val rule1 = window(2).forall { case Seq(a, b) => a <= b } 16 | val rule2 = window(2).collect { case Seq(a, b) if a == b => a }.toSet 17 | val rule3 = window(3).collect { case Seq(a, b, c) if a == b && b == c => a }.toSet 18 | rule1 && (rule2 -- rule3).nonEmpty 19 | } 20 | 21 | def main(args: Array[String]): Unit = 22 | val data = Seq(172851, 675869) 23 | println(part1(data)) 24 | println(part2(data)) 25 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2019/Day06.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | object Day06: 4 | def parse(input: Seq[String]): Map[String, List[String]] = 5 | val parent = input.map(_.split("\\)")).map(a => a(1) -> a(0)).toMap 6 | val cache = collection.mutable.Map("COM" -> List("COM")) 7 | def orbit(planet: String): List[String] = cache.getOrElseUpdate(planet, planet :: orbit(parent(planet))) 8 | parent.map((planet, _) => planet -> orbit(planet)) 9 | 10 | def part1(input: Seq[String]): Int = parse(input).values.map(_.tail.size).sum 11 | 12 | def part2(input: Seq[String]): Int = 13 | val orbits = parse(input) 14 | val (you, san) = (orbits("YOU"), orbits("SAN")) 15 | you.tail.indexWhere(san.contains) + san.tail.indexWhere(you.contains) 16 | 17 | def main(args: Array[String]): Unit = 18 | val data = io.Source.fromResource("AdventOfCode2019/Day06.txt").getLines().toSeq 19 | println(part1(data)) 20 | println(part2(data)) 21 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2019/Day08.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | object Day08: 4 | def part1(input: Seq[Int]): Int = 5 | input.grouped(25 * 6).map(group => (group.count(_ == 0), group.count(_ == 1) * group.count(_ == 2))).minBy(_._1)._2 6 | 7 | def part2(input: Seq[Int]): Seq[Int] = input.grouped(25 * 6).foldLeft(Seq.fill(25 * 6)(2)) { (image, layer) => 8 | image.zip(layer).map((previous, current) => if previous == 2 then current else previous) 9 | } 10 | 11 | def main(args: Array[String]): Unit = 12 | val data = io.Source.fromResource("AdventOfCode2019/Day08.txt").mkString.trim.map(_.asDigit) 13 | println(part1(data)) 14 | val image = part2(data) 15 | for y <- 0 until 6 do 16 | println() 17 | for x <- 0 until 25 do 18 | print(if image(y * 25 + x) == 1 then '#' else ' ') 19 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2019/Day16.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | object Day16: 4 | def part1(input: String): String = 5 | def phase(input: Seq[Int]): Seq[Int] = (0 until input.size).map { n => 6 | val raw = input.zipWithIndex.map { (next, index) => 7 | ((index + 1) / (n + 1)) % 4 match 8 | case 0 | 2 => 0 9 | case 1 => next 10 | case 3 => -next 11 | } 12 | (raw.sum % 10).abs 13 | } 14 | 15 | val initial = input.map(_.asDigit) 16 | Iterator.iterate(initial)(phase).drop(100).next().take(8).mkString 17 | end part1 18 | 19 | def part2(input: String): String = 20 | def phase(input: Seq[Int]): Seq[Int] = input.scanRight(0)(_ + _).map(_ % 10) 21 | 22 | val index = input.take(7).toInt 23 | val initial = (input * 10000).drop(index).map(_.asDigit) 24 | Iterator.iterate(initial)(phase).drop(100).next().take(8).mkString 25 | end part2 26 | 27 | def main(args: Array[String]): Unit = 28 | val data = io.Source.fromResource("AdventOfCode2019/Day16.txt").mkString.trim 29 | println(part1(data)) 30 | println(part2(data)) 31 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2019/Day19.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | import Day09.IntCode 4 | 5 | object Day19: 6 | def part1(memory: Seq[Long]): Long = 7 | val points = for x <- 0 until 50; y <- 0 until 50 yield IntCode(memory).withInput(x, y).allOutput 8 | points.flatten.sum 9 | 10 | def part2(memory: Seq[Long]): Long = 11 | def test(x: Long, y: Long) = IntCode(memory).withInput(x, y).allOutput.head == 1L 12 | 13 | def helper(x: Long, y: Long): Long = 14 | val top = test(x, y - 99) 15 | val left = test(x - 99, y) 16 | if top && left then 10000 * (x - 99) + (y - 99) 17 | else if top then helper(x + 1, y) 18 | else helper(x, y + 1) 19 | 20 | helper(99, 99) 21 | end part2 22 | 23 | def main(args: Array[String]): Unit = 24 | val data = io.Source.fromResource("AdventOfCode2019/Day19.txt").mkString.trim.split(",").map(_.toLong).toSeq 25 | println(part1(data)) 26 | println(part2(data)) 27 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2019/Day21.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | import Day09.IntCode 4 | 5 | object Day21: 6 | val walk = Seq("OR A J", "AND B J", "AND C J", "NOT J J", "AND D J") 7 | val run = Seq("OR E T", "OR H T", "AND T J") 8 | 9 | def survey(memory: Seq[Long], script: Seq[String]): Long = 10 | val input = script.map(_ + "\n").mkString.map(_.toLong) 11 | IntCode(memory).withInput(input*).allOutput.last 12 | 13 | def part1(memory: Seq[Long]): Long = survey(memory, walk.appended("WALK")) 14 | 15 | def part2(memory: Seq[Long]): Long = survey(memory, walk ++ run.appended("RUN")) 16 | 17 | def main(args: Array[String]): Unit = 18 | val data = io.Source.fromResource("AdventOfCode2019/Day21.txt").mkString.trim.split(",").map(_.toLong).toSeq 19 | println(part1(data)) 20 | println(part2(data)) 21 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2020/Day01.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | object Day01: 4 | def find(input: Seq[Int], size: Int): Int = input.toSet.subsets(size).find(_.sum == 2020).get.product 5 | 6 | def part1(input: Seq[Int]): Int = find(input, 2) 7 | 8 | def part2(input: Seq[Int]): Int = find(input, 3) 9 | 10 | def main(args: Array[String]): Unit = 11 | val data = io.Source.fromResource("AdventOfCode2020/Day01.txt").getLines().map(_.toInt).toSeq 12 | println(part1(data)) 13 | println(part2(data)) 14 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2020/Day02.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | object Day02: 4 | val pattern = """(\d+)-(\d+) ([a-z]): ([a-z]+)""".r 5 | 6 | def part1(input: Seq[String]): Int = input.count { case pattern(lower, upper, letter, password) => 7 | val occurrences = password.count(_ == letter.head) 8 | lower.toInt <= occurrences && occurrences <= upper.toInt 9 | } 10 | 11 | def part2(input: Seq[String]): Int = input.count { case pattern(lower, upper, letter, password) => 12 | val first = password.charAt(lower.toInt - 1) == letter.head 13 | val second = password.charAt(upper.toInt - 1) == letter.head 14 | first ^ second 15 | } 16 | 17 | def main(args: Array[String]): Unit = 18 | val data = io.Source.fromResource("AdventOfCode2020/Day02.txt").getLines().toSeq 19 | println(part1(data)) 20 | println(part2(data)) 21 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2020/Day03.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | object Day03: 4 | def slope(trees: Seq[String])(right: Int, down: Int): Long = 5 | val ys = (0 until trees.size by down).zipWithIndex.drop(1) 6 | ys.count((y, index) => trees(y)((right * index) % trees.head.size) == '#') 7 | 8 | def risk(input: Seq[String], slopes: Seq[(Int, Int)]): Long = slopes.map(slope(input)).product 9 | 10 | def part1(input: Seq[String]): Long = risk(input, Seq((3, 1))) 11 | 12 | def part2(input: Seq[String]): Long = risk(input, Seq((1, 1), (3, 1), (5, 1), (7, 1), (1, 2))) 13 | 14 | def main(args: Array[String]): Unit = 15 | val data = io.Source.fromResource("AdventOfCode2020/Day03.txt").getLines().toSeq 16 | println(part1(data)) 17 | println(part2(data)) 18 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2020/Day05.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | object Day05: 4 | def seatId(line: String): Int = 5 | val binary = line.map(c => if c == 'B' || c == 'R' then 1 else 0) 6 | Integer.parseInt(binary.mkString, 2) 7 | 8 | def part1(input: Seq[String]): Int = input.map(seatId).max 9 | 10 | def part2(input: Seq[String]): Int = 11 | val ids = input.map(seatId) 12 | val missing = (ids.min to ids.max).toSet -- ids 13 | missing.head 14 | 15 | def main(args: Array[String]): Unit = 16 | val data = io.Source.fromResource("AdventOfCode2020/Day05.txt").getLines().toSeq 17 | println(part1(data)) 18 | println(part2(data)) 19 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2020/Day06.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | object Day06: 4 | val whitespace = Set(' ', '\n') 5 | 6 | def parse(input: String)(answers: String => Set[Char]): Int = input.trim.split("\n\n").map(answers).map(_.size).sum 7 | 8 | def part1(input: String): Int = parse(input)(_.toSet -- whitespace) 9 | 10 | def part2(input: String): Int = parse(input) { line => 11 | val sets = line.split("\n").map(_.toSet -- whitespace) 12 | sets.tail.foldLeft(sets.head)((total, next) => total.intersect(next)) 13 | } 14 | 15 | def main(args: Array[String]): Unit = 16 | val data = io.Source.fromResource("AdventOfCode2020/Day06.txt").mkString 17 | println(part1(data)) 18 | println(part2(data)) 19 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2020/Day07.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | object Day07: 4 | def parse(input: Seq[String]): Map[String, Seq[(Int, String)]] = 5 | val regex = "(\\d+) (.+) bags?".r 6 | input.map { line => 7 | val Array(key, values) = line.split(" bags contain ") 8 | val bags = values.dropRight(1).split(", ").toSeq.collect { 9 | case regex(number, color) => number.toInt -> color 10 | } 11 | (key, bags) 12 | } 13 | .toMap 14 | 15 | def part1(input: Seq[String]): Int = 16 | val rules = parse(input).view.mapValues(_.map(_._2)) 17 | def helper(bag: String): Boolean = rules(bag).contains("shiny gold") || rules(bag).exists(helper) 18 | rules.keys.count(helper) 19 | 20 | def part2(input: Seq[String]): Int = 21 | val rules = parse(input) 22 | def helper(bag: String): Int = 1 + rules(bag).map((number, bag) => number * helper(bag)).sum 23 | helper("shiny gold") - 1 24 | 25 | def main(args: Array[String]): Unit = 26 | val data = io.Source.fromResource("AdventOfCode2020/Day07.txt").getLines().toSeq 27 | println(part1(data)) 28 | println(part2(data)) 29 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2020/Day09.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | object Day09: 4 | def part1(input: Seq[Long], preamble: Int): Long = input.sliding(preamble + 1) 5 | .map { window => 6 | if window.dropRight(1).toSet.subsets(2).map(_.sum).contains(window.last) then 0 else window.last 7 | } 8 | .find(_ > 0).get 9 | 10 | def part2(input: Seq[Long], preamble: Int): Long = 11 | val target = part1(input, preamble) 12 | val state = Iterator 13 | .iterate((0, 2, input(0) + input(1))) { state => 14 | val (start, end, total) = state 15 | if total < target then (start, end + 1, total + input(end)) 16 | else if total > target then (start + 1, end, total - input(start)) 17 | else state 18 | } 19 | .dropWhile(_._3 != target).next 20 | val slice = input.slice(state._1, state._2) 21 | slice.min + slice.max 22 | 23 | def main(args: Array[String]): Unit = 24 | val data = io.Source.fromResource("AdventOfCode2020/Day09.txt").getLines().map(_.toLong).toSeq 25 | println(part1(data, 25)) 26 | println(part2(data, 25)) 27 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2020/Day10.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | object Day10: 4 | def part1(input: Seq[Int]): Long = 5 | val steps = (Seq(0, input.max + 3) ++ input).sorted.sliding(2).map(w => w(1) - w(0)).toSeq.groupBy(identity) 6 | steps(1).size * steps(3).size 7 | 8 | def part2(input: Seq[Int]): Long = 9 | val arrangements = input.sorted.foldLeft(Map(0 -> 1L).withDefaultValue(0L)) { (map, next) => 10 | map.updated(next, map(next - 1) + map(next - 2) + map(next - 3)) 11 | } 12 | arrangements(input.max) 13 | 14 | def main(args: Array[String]): Unit = 15 | val data = io.Source.fromResource("AdventOfCode2020/Day10.txt").getLines().map(_.toInt).toSeq 16 | println(part1(data)) 17 | println(part2(data)) 18 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2020/Day13.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | object Day13: 4 | def part1(input: Seq[String]): Long = 5 | val time = input(0).toInt 6 | val buses = input(1).split(",").filter(_ != "x").map(_.toInt).toSeq 7 | val (id, departs) = buses.map(id => id -> (id - time % id)).minBy(_._2) 8 | id * departs 9 | 10 | def part2(input: Seq[String]): Long = 11 | val buses = input(1).split(",").zipWithIndex.collect { case (rawId, offset) if rawId != "x" => 12 | val id = rawId.toInt 13 | id -> ((id - offset % id) % id) 14 | } 15 | 16 | val (time, _) = buses.foldLeft((0L, 1L)) { case ((time, step), (id, remainder)) => 17 | val nextTime = Iterator.iterate(time)(_ + step).dropWhile(_ % id != remainder).next() 18 | (nextTime, step * id) 19 | } 20 | 21 | time 22 | end part2 23 | 24 | def main(args: Array[String]): Unit = 25 | val data = io.Source.fromResource("AdventOfCode2020/Day13.txt").getLines().toSeq 26 | println(part1(data)) 27 | println(part2(data)) 28 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2020/Day15.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | object Day15: 4 | def play(input: Seq[Int], turn: Int): Int = 5 | val map = input.dropRight(1).zipWithIndex.toMap 6 | val (_, result) = (input.length until turn).foldLeft((map, input.last)) { case ((map, last), index) => 7 | if map.contains(last) then 8 | val delta = index - 1 - map(last) 9 | (map.updated(last, index - 1), delta) 10 | else 11 | (map.updated(last, index - 1), 0) 12 | } 13 | result 14 | 15 | def part1(input: Seq[Int]): Int = play(input, 2020) 16 | 17 | def part2(input: Seq[Int]): Int = play(input, 30000000) 18 | 19 | def main(args: Array[String]): Unit = 20 | val data = io.Source.fromResource("AdventOfCode2020/Day15.txt").getLines().map(_.toInt).toSeq 21 | println(part1(data)) 22 | println(part2(data)) 23 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2020/Day25.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | object Day25: 4 | def part1(input: Seq[Int]): BigInt = 5 | val Seq(cardPub, doorPub) = input 6 | val doorLoopSize = Iterator.iterate(1)(n => (n * 7) % 20201227).indexWhere(_ == doorPub) 7 | BigInt(cardPub).modPow(doorLoopSize, 20201227) 8 | 9 | def main(args: Array[String]): Unit = 10 | val data = io.Source.fromResource("AdventOfCode2020/Day25.txt").getLines().map(_.toInt).toSeq 11 | println(part1(data)) 12 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2021/Day01.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | object Day01: 4 | def part1(input: Seq[Int]): Int = input.sliding(2).count { case Seq(x, y) => y > x } 5 | 6 | def part2(input: Seq[Int]): Int = input.sliding(4).count { case Seq(x, _, _, y) => y > x } 7 | 8 | def main(args: Array[String]): Unit = 9 | val data = io.Source.fromResource("AdventOfCode2021/Day01.txt").getLines().map(_.toInt).toSeq 10 | println(part1(data)) 11 | println(part2(data)) 12 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2021/Day05.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | object Day05: 4 | case class Line(x1: Int, y1: Int, x2: Int, y2: Int): 5 | def isOrthogonal: Boolean = x1 == x2 || y1 == y2 6 | def points: Seq[(Int, Int)] = 7 | val xs = x1 to x2 by (if x1 < x2 then 1 else -1) 8 | val ys = y1 to y2 by (if y1 < y2 then 1 else -1) 9 | xs.zipAll(ys, x1, y1) 10 | 11 | def parse(input: Seq[String]): Seq[Line] = input.map { line => 12 | val Array(x1, y1, x2, y2) = line.split("\\D+").map(_.toInt) 13 | Line(x1, y1, x2, y2) 14 | } 15 | 16 | def overlap(lines: Seq[Line]): Int = lines.flatMap(_.points).groupBy(identity).count(_._2.length > 1) 17 | 18 | def part1(input: Seq[String]): Int = overlap(parse(input).filter(_.isOrthogonal)) 19 | 20 | def part2(input: Seq[String]): Int = overlap(parse(input)) 21 | 22 | def main(args: Array[String]): Unit = 23 | val data = io.Source.fromResource("AdventOfCode2021/Day05.txt").getLines().toSeq 24 | println(part1(data)) 25 | println(part2(data)) 26 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2021/Day06.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | object Day06: 4 | def simulate(input: Seq[Int], days: Int): Long = 5 | val fish = Array.tabulate(9)(i => input.count(_ == i).toLong) 6 | for day <- 0 until days do fish((day + 7) % 9) += fish(day % 9) 7 | fish.sum 8 | 9 | def part1(input: Seq[Int]): Long = simulate(input, 80) 10 | 11 | def part2(input: Seq[Int]): Long = simulate(input, 256) 12 | 13 | def main(args: Array[String]): Unit = 14 | val data = io.Source.fromResource("AdventOfCode2021/Day06.txt").mkString.trim.split(",").map(_.toInt).toSeq 15 | println(part1(data)) 16 | println(part2(data)) 17 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2021/Day07.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | object Day07: 4 | def linearCost(x1: Int, x2: Int): Int = (x1 - x2).abs 5 | 6 | def triangleCost(x1: Int, x2: Int): Int = (linearCost(x1, x2) * (linearCost(x1, x2) + 1)) / 2 7 | 8 | def lowestCost(input: Seq[Int], cost: (Int, Int) => Int): Int = (input.min to input.max).map(x => input.map(cost(x, _)).sum).min 9 | 10 | def part1(input: Seq[Int]): Int = lowestCost(input, linearCost) 11 | 12 | def part2(input: Seq[Int]): Int = lowestCost(input, triangleCost) 13 | 14 | def main(args: Array[String]): Unit = 15 | val data = io.Source.fromResource("AdventOfCode2021/Day07.txt").mkString.trim.split(",").map(_.toInt).toSeq 16 | println(part1(data)) 17 | println(part2(data)) 18 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2021/Day10.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | object Day10: 4 | val opening = Map('(' -> 1, '[' -> 2, '{' -> 3, '<' -> 4) 5 | val closing = Map(')' -> 3, ']' -> 57, '}' -> 1197, '>' -> 25137) 6 | val matching = Map(')' -> '(', ']' -> '[', '}' -> '{', '>' -> '<') 7 | 8 | type Checked = Either[Char, List[Char]] 9 | 10 | def check(line: String): Checked = line.foldLeft[Checked](Right(Nil)) { 11 | case (Right(stack), next) if opening.contains(next) => Right(next :: stack) 12 | case (Right(head :: tail), next) if matching(next) == head => Right(tail) 13 | case (Left(left), _) => Left(left) 14 | case (_, next) => Left(next) 15 | } 16 | 17 | def part1(input: Seq[String]): Long = input.partitionMap(check)._1.map(closing).sum 18 | 19 | def part2(input: Seq[String]): Long = 20 | val results = input.partitionMap(check)._2.map(_.foldLeft(0L)((total, next) => 5 * total + opening(next))) 21 | results.sorted.apply(results.length / 2) 22 | 23 | def main(args: Array[String]): Unit = 24 | val data = io.Source.fromResource("AdventOfCode2021/Day10.txt").getLines().toSeq 25 | println(part1(data)) 26 | println(part2(data)) 27 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2021/Day17.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | object Day17: 4 | def bruteForce(input: Seq[Int]): Seq[Int] = 5 | val Seq(left, right, bottom, top) = input 6 | 7 | def fire(dx : Int, dy: Int): Boolean = Iterator 8 | .iterate((0, 0, dx, dy))((x, y, dx, dy) => (x + dx, y + dy, (dx - 1).max(0), dy - 1)) 9 | .takeWhile((x, y, _, _) => x <= right && y >= bottom) 10 | .exists((x, y, _, _) => x >= left && y <= top) 11 | 12 | for dx <- math.sqrt(left).toInt to right; dy <- bottom to -bottom if fire(dx, dy) yield (dy * (dy + 1)) / 2 13 | end bruteForce 14 | 15 | def parse(input: String): Seq[Int] = input.split("[^-\\d]+").tail.map(_.toInt).toSeq 16 | 17 | def part1(input: String): Int = bruteForce(parse(input)).max 18 | 19 | def part2(input: String): Int = bruteForce(parse(input)).size 20 | 21 | def main(args: Array[String]): Unit = 22 | val data = io.Source.fromResource("AdventOfCode2021/Day17.txt").mkString.trim 23 | println(part1(data)) 24 | println(part2(data)) 25 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2022/Day01.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | object Day01: 4 | def parse(input: String): Seq[Int] = 5 | input.split("\n\n").map(_.split("\n").map(_.toInt).sum).toSeq 6 | 7 | def part1(input: String): Int = parse(input).max 8 | 9 | def part2(input: String): Int = parse(input).sorted.takeRight(3).sum 10 | 11 | def main(args: Array[String]): Unit = 12 | val data = io.Source.fromResource("AdventOfCode2022/Day01.txt").mkString 13 | println(part1(data)) 14 | println(part2(data)) 15 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2022/Day02.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | object Day02: 4 | def part1(input: Seq[String]): Int = 5 | val order = Seq("", "B X", "C Y", "A Z", "A X", "B Y", "C Z", "C X", "A Y", "B Z").zipWithIndex.toMap 6 | input.map(order).sum 7 | 8 | def part2(input: Seq[String]): Int = 9 | val order = Seq("", "B X", "C X", "A X", "A Y", "B Y", "C Y", "C Z", "A Z", "B Z").zipWithIndex.toMap 10 | input.map(order).sum 11 | 12 | def main(args: Array[String]): Unit = 13 | val data = io.Source.fromResource("AdventOfCode2022/Day02.txt").getLines().toSeq 14 | println(part1(data)) 15 | println(part2(data)) 16 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2022/Day03.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | object Day03: 4 | def priority(item: Char): Int = if (item.isUpper) item - 'A' + 27 else item - 'a' + 1 5 | 6 | def part1(input: Seq[String]): Int = input 7 | .map { line => 8 | val (first, second) = line.splitAt(line.length / 2) 9 | val item = first.intersect(second) 10 | priority(item.head) 11 | } 12 | .sum 13 | 14 | def part2(input: Seq[String]): Int = input 15 | .grouped(3) 16 | .map { case Seq(first, second, third) => 17 | val badge = first.intersect(second).intersect(third) 18 | priority(badge.head) 19 | } 20 | .sum 21 | 22 | def main(args: Array[String]): Unit = 23 | val data = io.Source.fromResource("AdventOfCode2022/Day03.txt").getLines().toSeq 24 | println(part1(data)) 25 | println(part2(data)) 26 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2022/Day04.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | object Day04: 4 | def parse(line: String): (Int, Int, Int, Int) = 5 | val Array(a, b, c, d) = line.split("\\D").map(_.toInt) 6 | (a, b, c, d) 7 | 8 | def part1(input: Seq[String]): Int = input.map(parse) 9 | .count((a, b, c, d) => (a >= c && b <= d) || (c >= a && d <= b)) 10 | 11 | def part2(input: Seq[String]): Int = input.map(parse) 12 | .count((a, b, c, d) => a <= d && c <= b) 13 | 14 | def main(args: Array[String]): Unit = 15 | val data = io.Source.fromResource("AdventOfCode2022/Day04.txt").getLines().toSeq 16 | println(part1(data)) 17 | println(part2(data)) 18 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2022/Day06.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | object Day06: 4 | def find(input: String, size: Int): Int = input.sliding(size).indexWhere(_.toSet.size == size) + size 5 | 6 | def part1(input: String): Int = find(input, 4) 7 | 8 | def part2(input: String): Int = find(input, 14) 9 | 10 | def main(args: Array[String]): Unit = 11 | val data = io.Source.fromResource("AdventOfCode2022/Day06.txt").mkString 12 | println(part1(data)) 13 | println(part2(data)) 14 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2022/Day07.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | object Day07: 4 | def build(input: Seq[String]): Seq[Int] = 5 | val root = List.empty[String] 6 | val initial = (root, Map(root -> 0)) 7 | val (_, sizes) = input.foldLeft(initial) { case ((path, sizes), line) => 8 | line match 9 | case "$ cd .." => (path.tail, sizes) 10 | case s"$$ cd $name" => (name :: path, sizes.updated(name :: path, 0)) 11 | case s"$size $name" if size.head.isDigit => 12 | (path, path.tails.foldLeft(sizes)((acc, next) => acc.updated(next, sizes(next) + size.toInt))) 13 | case _ => (path, sizes) 14 | } 15 | sizes.values.toSeq 16 | 17 | def part1(input: Seq[String]): Int = 18 | val sizes = build(input) 19 | sizes.filter(_ <= 100000).sum 20 | 21 | def part2(input: Seq[String]): Int = 22 | val sizes = build(input) 23 | val needed = 30000000 - (70000000 - sizes.max) 24 | sizes.filter(_ >= needed).min 25 | 26 | def main(args: Array[String]): Unit = 27 | val data = io.Source.fromResource("AdventOfCode2022/Day07.txt").getLines().toSeq 28 | println(part1(data)) 29 | println(part2(data)) 30 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2022/Day10.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | object Day10: 4 | def parse(input: String): Array[Int] = 5 | input.split("\\s+").map(_.toIntOption.getOrElse(0)).scanLeft(1)(_ + _) 6 | 7 | def part1(input: String): Int = 8 | val signal = parse(input) 9 | (20 to 220 by 40).map(cycle => cycle * signal(cycle - 1)).sum 10 | 11 | def part2(input: String): String = parse(input) 12 | .init.grouped(40) 13 | .map(_.zipWithIndex.map((x, col) => if (x - col).abs <= 1 then '#' else '.')) 14 | .map(_.mkString).mkString("\n") 15 | 16 | def main(args: Array[String]): Unit = 17 | val data = io.Source.fromResource("AdventOfCode2022/Day10.txt").mkString 18 | println(part1(data)) 19 | println(part2(data)) 20 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2022/Day13.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | object Day13: 4 | def simplify(input: Seq[String]): Seq[String] = input.filter(_.nonEmpty).map(_.replace("10", "A")) 5 | 6 | def compare(left: String, right: String): Boolean = (left.head, right.head) match 7 | case (a, b) if a == b => compare(left.tail, right.tail) 8 | case (']', _) => true 9 | case (_, ']') => false 10 | case ('[', b) => compare(left.tail, s"$b]" + right.tail) 11 | case (a, '[') => compare(s"$a]" + left.tail, right.tail) 12 | case (a, b) => a < b 13 | 14 | def part1(input: Seq[String]): Int = 15 | val pairs = simplify(input).grouped(2).zipWithIndex 16 | pairs.collect { case (Seq(left, right), index) if compare(left, right) => index + 1 }.sum 17 | 18 | def part2(input: Seq[String]): Int = 19 | val dividers = Seq("[[2]]", "[[6]]") 20 | val sorted = (simplify(input) ++ dividers).sortWith(compare) 21 | dividers.map(sorted.indexOf(_) + 1).product 22 | 23 | def main(args: Array[String]): Unit = 24 | val data = io.Source.fromResource("AdventOfCode2022/Day13.txt").getLines().toSeq 25 | println(part1(data)) 26 | println(part2(data)) 27 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2022/Day20.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | object Day20: 4 | def decrypt(input: Seq[Int], key: Long, rounds: Int): Long = 5 | val mixed = collection.mutable.ArrayBuffer.from(input.map(_ * key).zipWithIndex) 6 | for _ <- 1 to rounds do 7 | for index <- input.indices do 8 | val from = mixed.indexWhere(_._2 == index) 9 | val pair @ (number, _) = mixed.remove(from) 10 | val remainder = (number % mixed.size).toInt 11 | val to = (from + remainder + mixed.size) % mixed.size 12 | mixed.insert(to, pair) 13 | end for 14 | end for 15 | val start = mixed.indexWhere(_._1 == 0) 16 | (1 to 3).map(offset => mixed((start + 1000 * offset) % mixed.size)._1).sum 17 | 18 | def part1(input: Seq[Int]): Long = decrypt(input, 1L, 1) 19 | 20 | def part2(input: Seq[Int]): Long = decrypt(input, 811589153L, 10) 21 | 22 | def main(args: Array[String]): Unit = 23 | val data = io.Source.fromResource("AdventOfCode2022/Day20.txt").getLines().map(_.toInt).toSeq 24 | println(part1(data)) 25 | println(part2(data)) 26 | -------------------------------------------------------------------------------- /src/main/scala/AdventOfCode2022/Day25.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | object Day25: 4 | def fromSnafu(s: String): Long = s.foldLeft(0L) { (total, c) => 5 | val digit = c match 6 | case '0' => 0 7 | case '1' => 1 8 | case '2' => 2 9 | case '=' => -2 10 | case '-' => -1 11 | 5 * total + digit 12 | } 13 | 14 | def toSnafu(i: Long): String = if i == 0 then "" else 15 | val suffix = i % 5 match 16 | case 0 => "0" 17 | case 1 => "1" 18 | case 2 => "2" 19 | case 3 => "=" 20 | case 4 => "-" 21 | toSnafu((i + 2) / 5) + suffix 22 | 23 | def part1(input: Seq[String]): String = toSnafu(input.map(fromSnafu).sum) 24 | 25 | def main(args: Array[String]): Unit = 26 | val data = io.Source.fromResource("AdventOfCode2022/Day25.txt").getLines().toSeq 27 | println(part1(data)) 28 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2015/Day01Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day01Suite extends AnyFunSuite: 6 | val sample = "()())" 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day01.part1(sample) == -1) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day01.part2(sample) == 5) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2015/Day02Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day02Suite extends AnyFunSuite: 6 | val sample = Seq("2x3x4", "1x1x10") 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day02.part1(sample) == 101) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day02.part2(sample) == 48) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2015/Day03Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day03Suite extends AnyFunSuite: 6 | val sample = "^v^v^v^v^v" 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day03.part1(sample) == 2) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day03.part2(sample) == 11) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2015/Day04Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day04Suite extends AnyFunSuite 6 | // No unit tests possible 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2015/Day05Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day05Suite extends AnyFunSuite: 6 | val sample1 = Seq( 7 | "ugknbfddgicrmopn", 8 | "aaa", 9 | "jchzalrnumimnmhp", 10 | "haegwjzuvuyypxyu", 11 | "dvszwmarrgswjxmb") 12 | 13 | test("Part 1 should handle sample input correctly") { 14 | assert(Day05.part1(sample1) == 2) 15 | } 16 | 17 | val sample2 = Seq( 18 | "qjhvhtzxzqqjkmpb", 19 | "xxyxx", 20 | "uurcxstgmygtbstg", 21 | "ieodomkazucvgmuy") 22 | 23 | test("Part 2 should handle sample input correctly") { 24 | assert(Day05.part2(sample2) == 2) 25 | } 26 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2015/Day06Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day06Suite extends AnyFunSuite 6 | // No unit tests possible 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2015/Day07Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day07Suite extends AnyFunSuite 6 | // No unit tests possible 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2015/Day08Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day08Suite extends AnyFunSuite: 6 | val sample = """ 7 | "" 8 | "abc" 9 | "abc\"aaa" 10 | "\x27" 11 | """.split("\\s+").filter(_.nonEmpty).toSeq 12 | 13 | test("Part 1 should handle sample input correctly") { 14 | assert(Day08.part1(sample) == 12) 15 | } 16 | 17 | test("Part 2 should handle sample input correctly") { 18 | assert(Day08.part2(sample) == 19) 19 | } 20 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2015/Day09Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day09Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "London to Dublin = 464", 8 | "London to Belfast = 518", 9 | "Dublin to Belfast = 141") 10 | 11 | test("Part 1 should handle sample input correctly") { 12 | assert(Day09.part1(sample) == 605) 13 | } 14 | 15 | test("Part 2 should handle sample input correctly") { 16 | assert(Day09.part2(sample) == 982) 17 | } 18 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2015/Day10Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day10Suite extends AnyFunSuite 6 | // No unit tests possible 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2015/Day11Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day11Suite extends AnyFunSuite: 6 | val sample = "abcdefgh" 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day11.part1(sample) == "abcdffaa") 10 | } 11 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2015/Day12Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day12Suite extends AnyFunSuite: 6 | val sample1 = """{"a":{"b":4},"c":-1}""" 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day12.part1(sample1) == 3) 10 | } 11 | 12 | val sample2 = """[1,{"c":"red","b":2},3]""" 13 | 14 | test("Part 2 should handle sample input correctly") { 15 | assert(Day12.part2(sample2) == 4) 16 | } 17 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2015/Day13Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day13Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "Alice would gain 54 happiness units by sitting next to Bob.", 8 | "Alice would lose 79 happiness units by sitting next to Carol.", 9 | "Alice would lose 2 happiness units by sitting next to David.", 10 | "Bob would gain 83 happiness units by sitting next to Alice.", 11 | "Bob would lose 7 happiness units by sitting next to Carol.", 12 | "Bob would lose 63 happiness units by sitting next to David.", 13 | "Carol would lose 62 happiness units by sitting next to Alice.", 14 | "Carol would gain 60 happiness units by sitting next to Bob.", 15 | "Carol would gain 55 happiness units by sitting next to David.", 16 | "David would gain 46 happiness units by sitting next to Alice.", 17 | "David would lose 7 happiness units by sitting next to Bob.", 18 | "David would gain 41 happiness units by sitting next to Carol.") 19 | 20 | test("Part 1 should handle sample input correctly") { 21 | assert(Day13.part1(sample) == 330) 22 | } 23 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2015/Day14Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day14Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "Comet can fly 14 km/s for 10 seconds, but then must rest for 127 seconds.", 8 | "Dancer can fly 16 km/s for 11 seconds, but then must rest for 162 seconds.") 9 | 10 | test("Part 1 should handle sample input correctly") { 11 | assert(Day14.part1(sample, 1000) == 1120) 12 | } 13 | 14 | test("Part 2 should handle sample input correctly") { 15 | assert(Day14.part2(sample, 1000) == 689) 16 | } 17 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2015/Day15Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day15Suite extends AnyFunSuite 6 | // No unit tests possible 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2015/Day16Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day16Suite extends AnyFunSuite 6 | // No unit tests possible 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2015/Day17Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day17Suite extends AnyFunSuite 6 | // No unit tests possible 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2015/Day18Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day18Suite extends AnyFunSuite 6 | // No unit tests possible 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2015/Day19Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day19Suite extends AnyFunSuite: 6 | val sample1 = Seq( 7 | "H => HO", 8 | "H => OH", 9 | "O => HH", 10 | "", 11 | "HOH") 12 | 13 | test("Part 1 should handle sample input correctly") { 14 | assert(Day19.part1(sample1) == 4) 15 | } 16 | 17 | val sample2 = Seq( 18 | "e => H", 19 | "e => O", 20 | "H => HO", 21 | "H => OH", 22 | "O => HH", 23 | "", 24 | "HOHOHO") 25 | 26 | test("Part 2 should handle sample input correctly") { 27 | assert(Day19.part2(sample2) == 6) 28 | } 29 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2015/Day20Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day20Suite extends AnyFunSuite 6 | // No unit tests possible 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2015/Day21Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day21Suite extends AnyFunSuite 6 | // No unit tests possible 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2015/Day22Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day22Suite extends AnyFunSuite 6 | // No unit tests possible 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2015/Day23Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day23Suite extends AnyFunSuite 6 | // No unit tests possible 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2015/Day24Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day24Suite extends AnyFunSuite: 6 | val sample = Seq(1L, 2L, 3L, 4L, 5L, 7L, 8L, 9L, 10L, 11L) 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day24.part1(sample) == 99) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day24.part2(sample) == 44) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2015/Day25Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2015 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day25Suite extends AnyFunSuite 6 | // No unit tests possible 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2016/Day01Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day01Suite extends AnyFunSuite: 6 | val sample1 = Seq("R5", "L5", "R5", "R3") 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day01.part1(sample1) == 12) 10 | } 11 | 12 | val sample2 = Seq("R8", "R4", "R4", "R8") 13 | 14 | test("Part 2 should handle sample input correctly") { 15 | assert(Day01.part2(sample2) == 4) 16 | } 17 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2016/Day02Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day02Suite extends AnyFunSuite: 6 | val sample = Seq("ULL", "RRDDD", "LURDL", "UUUUD") 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day02.part1(sample) == "1985") 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day02.part2(sample) == "5DB3") 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2016/Day03Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day03Suite extends AnyFunSuite 6 | // No unit tests possible 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2016/Day04Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day04Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "aaaaa-bbb-z-y-x-123[abxyz]", 8 | "a-b-c-d-e-f-g-h-987[abcde]", 9 | "not-a-real-room-404[oarel]", 10 | "totally-real-room-200[decoy]") 11 | 12 | test("Part 1 should handle sample input correctly") { 13 | assert(Day04.part1(sample) == 1514) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2016/Day05Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day05Suite extends AnyFunSuite: 6 | val sample = "abc" 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day05.part1(sample) == "18f47a30") 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day05.part2(sample) == "05ace8e3") 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2016/Day06Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day06Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "eedadn", 8 | "drvtee", 9 | "eandsr", 10 | "raavrd", 11 | "atevrs", 12 | "tsrnev", 13 | "sdttsa", 14 | "rasrtv", 15 | "nssdts", 16 | "ntnada", 17 | "svetve", 18 | "tesnvt", 19 | "vntsnd", 20 | "vrdear", 21 | "dvrsen", 22 | "enarar") 23 | 24 | test("Part 1 should handle sample input correctly") { 25 | assert(Day06.part1(sample) == "easter") 26 | } 27 | 28 | test("Part 2 should handle sample input correctly") { 29 | assert(Day06.part2(sample) == "advent") 30 | } 31 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2016/Day07Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day07Suite extends AnyFunSuite: 6 | val sample1 = Seq( 7 | "abba[mnop]qrst", 8 | "abcd[bddb]xyyx", 9 | "aaaa[qwer]tyui", 10 | "ioxxoj[asdfgh]zxcvbn") 11 | 12 | test("Part 1 should handle sample input correctly") { 13 | assert(Day07.part1(sample1) == 2) 14 | } 15 | 16 | val sample2 = Seq( 17 | "aba[bab]xyz", 18 | "xyx[xyx]xyx", 19 | "aaa[kek]eke", 20 | "zazbz[bzb]cdb") 21 | 22 | test("Part 2 should handle sample input correctly") { 23 | assert(Day07.part2(sample2) == 3) 24 | } 25 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2016/Day08Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day08Suite extends AnyFunSuite 6 | // No unit tests possible 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2016/Day09Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day09Suite extends AnyFunSuite: 6 | val sample1= "X(8x2)(3x3)ABCY" 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day09.part1(sample1) == 18) 10 | } 11 | 12 | val sample2 = "(25x3)(3x3)ABC(2x3)XY(5x2)PQRSTX(18x9)(3x2)TWO(5x7)SEVEN" 13 | 14 | test("Part 2 should handle sample input correctly") { 15 | assert(Day09.part2(sample2) == 445) 16 | } 17 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2016/Day10Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day10Suite extends AnyFunSuite 6 | // No unit tests possible 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2016/Day11Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day11Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "The first floor contains a hydrogen-compatible microchip and a lithium-compatible microchip.", 8 | "The second floor contains a hydrogen generator.", 9 | "The third floor contains a lithium generator.", 10 | "The fourth floor contains nothing relevant.") 11 | 12 | test("Part 1 should handle sample input correctly") { 13 | assert(Day11.part1(sample) == 11) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2016/Day12Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day12Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "cpy 41 a", 8 | "inc a", 9 | "inc a", 10 | "dec a", 11 | "jnz a 2", 12 | "dec a") 13 | 14 | test("Part 1 should handle sample input correctly") { 15 | assert(Day12.part1(sample) == 42) 16 | } 17 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2016/Day13Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day13Suite extends AnyFunSuite 6 | // No unit tests possible 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2016/Day14Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day14Suite extends AnyFunSuite: 6 | val sample = "abc" 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day14.part1(sample) == 22728) 10 | } 11 | 12 | // Part 2 is too slow -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2016/Day15Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day15Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "Disc #1 has 5 positions; at time=0, it is at position 4.", 8 | "Disc #2 has 2 positions; at time=0, it is at position 1.") 9 | 10 | test("Part 1 should handle sample input correctly") { 11 | assert(Day15.part1(sample) == 5) 12 | } 13 | 14 | test("Part 2 should handle sample input correctly") { 15 | assert(Day15.part2(sample) == 85) 16 | } 17 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2016/Day16Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day16Suite extends AnyFunSuite 6 | // No unit tests possible 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2016/Day17Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day17Suite extends AnyFunSuite: 6 | val sample = "ihgpwlah" 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day17.part1(sample) == "DDRRRD") 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day17.part2(sample) == 370) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2016/Day18Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day18Suite extends AnyFunSuite: 6 | val sample = ".^^.^.^^^^" 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day18.safe(sample, 10) == 38) 10 | } 11 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2016/Day19Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day19Suite extends AnyFunSuite: 6 | val sample = 5 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day19.part1(sample) == 3) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day19.part2(sample) == 2) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2016/Day20Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day20Suite extends AnyFunSuite: 6 | val sample = Seq("5-8", "0-2", "4-7") 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day20.part1(sample, 9) == 3) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day20.part2(sample, 9) == 2) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2016/Day21Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day21Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "swap position 4 with position 0", 8 | "swap letter d with letter b", 9 | "reverse positions 0 through 4", 10 | "rotate left 1 step", 11 | "move position 1 to position 4", 12 | "move position 3 to position 0", 13 | "rotate based on position of letter b", 14 | "rotate based on position of letter d") 15 | 16 | test("Part 1 should handle sample input correctly") { 17 | assert(Day21.part1(sample, "abcde") == "decab") 18 | } 19 | 20 | test("Part 2 should handle sample input correctly") { 21 | assert(Day21.part2(sample, "decab") == "abcde") 22 | } 23 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2016/Day22Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day22Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "root@ebhq-gridcenter# df -h", 8 | "Filesystem Size Used Avail Use%", 9 | "/dev/grid/node-x0-y0 10T 8T 2T 80%", 10 | "/dev/grid/node-x0-y1 11T 6T 5T 54%", 11 | "/dev/grid/node-x0-y2 32T 28T 4T 87%", 12 | "/dev/grid/node-x1-y0 9T 7T 2T 77%", 13 | "/dev/grid/node-x1-y1 8T 0T 8T 0%", 14 | "/dev/grid/node-x1-y2 11T 7T 4T 63%", 15 | "/dev/grid/node-x2-y0 10T 6T 4T 60%", 16 | "/dev/grid/node-x2-y1 9T 8T 1T 88%", 17 | "/dev/grid/node-x2-y2 9T 6T 3T 66%", 18 | ) 19 | 20 | test("Part 1 should handle sample input correctly") { 21 | assert(Day22.part1(sample) == 7) 22 | } 23 | 24 | test("Part 2 should handle sample input correctly") { 25 | assert(Day22.part2(sample) == 7) 26 | } 27 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2016/Day23Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day23Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "cpy 2 a", 8 | "tgl a", 9 | "tgl a", 10 | "tgl a", 11 | "cpy 1 a", 12 | "dec a", 13 | "dec a") 14 | 15 | test("Part 1 should handle sample input correctly") { 16 | assert(Day23.part1(sample) == 3) 17 | } 18 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2016/Day24Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day24Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "###########", 8 | "#0.1.....2#", 9 | "#.#######.#", 10 | "#4.......3#", 11 | "###########") 12 | 13 | test("Part 1 should handle sample input correctly") { 14 | assert(Day24.part1(sample) == 14) 15 | } 16 | 17 | test("Part 2 should handle sample input correctly") { 18 | assert(Day24.part2(sample) == 20) 19 | } 20 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2016/Day25Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2016 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day25Suite extends AnyFunSuite 6 | // No unit tests possible 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2017/Day01Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day01Suite extends AnyFunSuite: 6 | val sample1 = Seq(9,1,1,2,1,2,1,2,9) 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day01.part1(sample1) == 10) 10 | } 11 | 12 | val sample2 = Seq(1,2,3,4,2,5) 13 | 14 | test("Part 2 should handle sample input correctly") { 15 | assert(Day01.part2(sample2) == 4) 16 | } 17 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2017/Day02Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day02Suite extends AnyFunSuite: 6 | val sample1 = Seq( 7 | "5 1 9 5", 8 | "7 5 3", 9 | "2 4 6 8") 10 | 11 | test("Part 1 should handle sample input correctly") { 12 | assert(Day02.part1(sample1) == 18) 13 | } 14 | 15 | val sample2 = Seq( 16 | "5 9 2 8", 17 | "9 4 7 3", 18 | "3 8 6 5") 19 | 20 | test("Part 2 should handle sample input correctly") { 21 | assert(Day02.part2(sample2) == 9) 22 | } 23 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2017/Day03Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day03Suite extends AnyFunSuite: 6 | val sample = 12 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day03.part1(sample) == 3) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day03.part2(sample) == 23) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2017/Day04Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day04Suite extends AnyFunSuite: 6 | val sample1 = Seq( 7 | "aa bb cc dd ee", 8 | "aa bb cc dd aa", 9 | "aa bb cc dd aaa") 10 | 11 | test("Part 1 should handle sample input correctly") { 12 | assert(Day04.part1(sample1) == 2) 13 | } 14 | 15 | val sample2 = Seq( 16 | "abcde fghij", 17 | "abcde xyz ecdab", 18 | "a ab abc abd abf abj", 19 | "iiii oiii ooii oooi oooo", 20 | "oiii ioii iioi iiio") 21 | 22 | test("Part 2 should handle sample input correctly") { 23 | assert(Day04.part2(sample2) == 3) 24 | } 25 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2017/Day05Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day05Suite extends AnyFunSuite: 6 | val sample = Seq(0, 3, 0, 1, -3) 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day05.part1(sample) == 5) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day05.part2(sample) == 10) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2017/Day06Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day06Suite extends AnyFunSuite: 6 | val sample = "0 2 7 0" 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day06.part1(sample) == 5) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day06.part2(sample) == 4) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2017/Day07Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day07Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "pbga (66)", 8 | "xhth (57)", 9 | "ebii (61)", 10 | "havc (66)", 11 | "ktlj (57)", 12 | "fwft (72) -> ktlj, cntj, xhth", 13 | "qoyq (66)", 14 | "padx (45) -> pbga, havc, qoyq", 15 | "tknk (41) -> ugml, padx, fwft", 16 | "jptl (61)", 17 | "ugml (68) -> gyxo, ebii, jptl", 18 | "gyxo (61)", 19 | "cntj (57)") 20 | 21 | test("Part 1 should handle sample input correctly") { 22 | assert(Day07.part1(sample) == "tknk") 23 | } 24 | 25 | test("Part 2 should handle sample input correctly") { 26 | assert(Day07.part2(sample) == 60) 27 | } 28 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2017/Day08Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day08Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "b inc 5 if a > 1", 8 | "a inc 1 if b < 5", 9 | "c dec -10 if a >= 1", 10 | "c inc -20 if c == 10") 11 | 12 | test("Part 1 should handle sample input correctly") { 13 | assert(Day08.part1(sample) == 1) 14 | } 15 | 16 | test("Part 2 should handle sample input correctly") { 17 | assert(Day08.part2(sample) == 10) 18 | } 19 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2017/Day09Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day09Suite extends AnyFunSuite: 6 | val sample1 = "{{},{},{},{}}" 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day09.part1(sample1) == 3) 10 | } 11 | 12 | val sample2 = "<{o\"i!a,<{i" 13 | 14 | test("Part 2 should handle sample input correctly") { 15 | assert(Day09.part2(sample2) == 10) 16 | } 17 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2017/Day10Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day10Suite extends AnyFunSuite: 6 | val sample1 = "1,2,3" 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day10.part1(sample1) == 0) 10 | } 11 | 12 | val sample2 = "AoC 2017" 13 | 14 | test("Part 2 should handle sample input correctly") { 15 | assert(Day10.part2(sample2) == "33efeb34ea91902bb2f59c9920caa6cd") 16 | } 17 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2017/Day11Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day11Suite extends AnyFunSuite: 6 | val sample = "se,sw,se,sw,sw,s,n" 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day11.part1(sample) == 3) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day11.part2(sample) == 4) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2017/Day12Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day12Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "0 <-> 2", 8 | "1 <-> 1", 9 | "2 <-> 0, 3, 4", 10 | "3 <-> 2, 4", 11 | "4 <-> 2, 3, 6", 12 | "5 <-> 6", 13 | "6 <-> 4, 5") 14 | 15 | test("Part 1 should handle sample input correctly") { 16 | assert(Day12.part1(sample) == 6) 17 | } 18 | 19 | test("Part 2 should handle sample input correctly") { 20 | assert(Day12.part2(sample) == 2) 21 | } 22 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2017/Day13Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day13Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "0: 3", 8 | "1: 2", 9 | "4: 4", 10 | "6: 4") 11 | 12 | test("Part 1 should handle sample input correctly") { 13 | assert(Day13.part1(sample) == 24) 14 | } 15 | 16 | test("Part 2 should handle sample input correctly") { 17 | assert(Day13.part2(sample) == 10) 18 | } 19 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2017/Day14Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day14Suite extends AnyFunSuite: 6 | val sample = "flqrgnkx" 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day14.part1(sample) == 8108) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day14.part2(sample) == 1242) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2017/Day15Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day15Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "Generator A starts with 65", 8 | "Generator B starts with 8921") 9 | 10 | test("Part 1 should handle sample input correctly") { 11 | assert(Day15.part1(sample) == 588) 12 | } 13 | 14 | test("Part 2 should handle sample input correctly") { 15 | assert(Day15.part2(sample) == 309) 16 | } 17 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2017/Day16Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day16Suite extends AnyFunSuite 6 | // No unit tests possible 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2017/Day17Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day17Suite extends AnyFunSuite: 6 | val sample = 3 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day17.part1(3) == 638) 10 | } 11 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2017/Day18Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day18Suite extends AnyFunSuite: 6 | val sample1 = Seq( 7 | "set a 1", 8 | "add a 2", 9 | "mul a a", 10 | "mod a 5", 11 | "snd a", 12 | "set a 0", 13 | "rcv a", 14 | "jgz a -1", 15 | "set a 1", 16 | "jgz a -2 ") 17 | 18 | test("Part 1 should handle sample input correctly") { 19 | assert(Day18.part1(sample1) == 4) 20 | } 21 | 22 | val sample2 = Seq( 23 | "snd 1", 24 | "snd 2", 25 | "snd p", 26 | "rcv a", 27 | "rcv b", 28 | "rcv c", 29 | "rcv d") 30 | 31 | test("Part 2 should handle sample input correctly") { 32 | assert(Day18.part2(sample2) == 3) 33 | } 34 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2017/Day19Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day19Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | " | ", 8 | " | +--+ ", 9 | " A | C ", 10 | " F---|----E|--+ ", 11 | " | | | D ", 12 | " +B-+ +--+ ", 13 | " ") 14 | 15 | test("Part 1 should handle sample input correctly") { 16 | assert(Day19.part1(sample) == "ABCDEF") 17 | } 18 | 19 | test("Part 2 should handle sample input correctly") { 20 | assert(Day19.part2(sample) == 38) 21 | } 22 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2017/Day20Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day20Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "p=< 3,0,0>, v=< 2,0,0>, a=<-1,0,0>", 8 | "p=< 4,0,0>, v=< 0,0,0>, a=<-2,0,0>") 9 | 10 | test("Part 1 should handle sample input correctly") { 11 | assert(Day20.part1(sample) == 0) 12 | } 13 | 14 | test("Part 2 should handle sample input correctly") { 15 | assert(Day20.part2(sample) == 2) 16 | } 17 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2017/Day21Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day21Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "../.# => ##./#../...", 8 | ".#./..#/### => #..#/..../..../#..#") 9 | 10 | test("Part 1 should handle sample input correctly") { 11 | assert(Day21.fractal(sample, 2) == 12) 12 | } 13 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2017/Day22Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day22Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "..#", 8 | "#..", 9 | "...") 10 | 11 | test("Part 1 should handle sample input correctly") { 12 | assert(Day22.part1(sample) == 5587) 13 | } 14 | 15 | test("Part 2 should handle sample input correctly") { 16 | assert(Day22.part2(sample) == 2511944) 17 | } 18 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2017/Day23Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day23Suite extends AnyFunSuite 6 | // No unit tests possible 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2017/Day24Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day24Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "0/2", 8 | "2/2", 9 | "2/3", 10 | "3/4", 11 | "3/5", 12 | "0/1", 13 | "10/1", 14 | "9/10") 15 | 16 | test("Part 1 should handle sample input correctly") { 17 | assert(Day24.part1(sample) == 31) 18 | } 19 | 20 | test("Part 2 should handle sample input correctly") { 21 | assert(Day24.part2(sample) == 19) 22 | } 23 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2017/Day25Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2017 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day25Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "Begin in state A.", 8 | "Perform a diagnostic checksum after 6 steps.", 9 | "", 10 | "In state A:", 11 | " If the current value is 0:", 12 | " - Write the value 1.", 13 | " - Move one slot to the right.", 14 | " - Continue with state B.", 15 | " If the current value is 1:", 16 | " - Write the value 0.", 17 | " - Move one slot to the left.", 18 | " - Continue with state B.", 19 | "", 20 | "In state B:", 21 | " If the current value is 0:", 22 | " - Write the value 1.", 23 | " - Move one slot to the left.", 24 | " - Continue with state A.", 25 | "If the current value is 1:", 26 | " - Write the value 1.", 27 | " - Move one slot to the right.", 28 | " - Continue with state A.") 29 | 30 | test("Part 1 should handle sample input correctly") { 31 | assert(Day25.part1(sample) == 3) 32 | } 33 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2018/Day01Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day01Suite extends AnyFunSuite: 6 | val sample = Seq(1, -2, 3, 1) 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day01.part1(sample) == 3) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day01.part2(sample) == 2) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2018/Day02Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day02Suite extends AnyFunSuite: 6 | val sample1 = Seq( 7 | "abcdef", 8 | "bababc", 9 | "abbcde", 10 | "abcccd", 11 | "aabcdd", 12 | "abcdee", 13 | "ababab") 14 | 15 | test("Part 1 should handle sample input correctly") { 16 | assert(Day02.part1(sample1) == 12) 17 | } 18 | 19 | val sample2 = Seq( 20 | "abcde", 21 | "fghij", 22 | "klmno", 23 | "pqrst", 24 | "fguij", 25 | "axcye", 26 | "wvxyz") 27 | 28 | test("Part 2 should handle sample input correctly") { 29 | assert(Day02.part2(sample2) == "fgij") 30 | } 31 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2018/Day03Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day03Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "#1 @ 1,3: 4x4", 8 | "#2 @ 3,1: 4x4", 9 | "#3 @ 5,5: 2x2") 10 | 11 | test("Part 1 should handle sample input correctly") { 12 | assert(Day03.part1(sample) == 4) 13 | } 14 | 15 | test("Part 2 should handle sample input correctly") { 16 | assert(Day03.part2(sample) == 3) 17 | } 18 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2018/Day05Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day05Suite extends AnyFunSuite: 6 | val sample = "dabAcCaCBAcCcaDA" 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day05.part1(sample) == 10) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day05.part2(sample) == 4) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2018/Day06Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day06Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "1, 1", 8 | "1, 6", 9 | "8, 3", 10 | "3, 4", 11 | "5, 5", 12 | "8, 9") 13 | 14 | test("Part 1 should handle sample input correctly") { 15 | assert(Day06.part1(sample) == 17) 16 | } 17 | 18 | test("Part 2 should handle sample input correctly") { 19 | assert(Day06.part2(sample, 32) == 16) 20 | } 21 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2018/Day07Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day07Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "Step C must be finished before step A can begin.", 8 | "Step C must be finished before step F can begin.", 9 | "Step A must be finished before step B can begin.", 10 | "Step A must be finished before step D can begin.", 11 | "Step B must be finished before step E can begin.", 12 | "Step D must be finished before step E can begin.", 13 | "Step F must be finished before step E can begin.") 14 | 15 | test("Part 1 should handle sample input correctly") { 16 | assert(Day07.part1(sample) == "CABDFE") 17 | } 18 | 19 | test("Part 2 should handle sample input correctly") { 20 | assert(Day07.part2(sample, 2, 0) == 15) 21 | } 22 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2018/Day08Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day08Suite extends AnyFunSuite: 6 | val sample = Seq(2, 3, 0, 3, 10, 11, 12, 1, 1, 0, 1, 99, 2, 1, 1, 2) 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day08.part1(sample) == 138) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day08.part2(sample) == 66) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2018/Day09Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day09Suite extends AnyFunSuite: 6 | val sample = "9 players; last marble is worth 25 points" 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day09.part1(sample) == 32) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day09.part2(sample) == 22563) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2018/Day10Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day10Suite extends AnyFunSuite 6 | // No unit tests possible 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2018/Day11Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day11Suite extends AnyFunSuite: 6 | test("Part 1 should handle sample input correctly") { 7 | assert(Day11.part1(18) == "33,45") 8 | } 9 | 10 | // Test is correct but slow 11 | // test("Part 2 should handle sample input correctly") { 12 | // assert(Day11.part2(18) == "90,269,16") 13 | // } 14 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2018/Day12Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day12Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "initial state: #..#.#..##......###...###", 8 | "", 9 | "...## => #", 10 | "..#.. => #", 11 | ".#... => #", 12 | ".#.#. => #", 13 | ".#.## => #", 14 | ".##.. => #", 15 | ".#### => #", 16 | "#.#.# => #", 17 | "#.### => #", 18 | "##.#. => #", 19 | "##.## => #", 20 | "###.. => #", 21 | "###.# => #", 22 | "####. => #") 23 | 24 | test("Part 1 should handle sample input correctly") { 25 | assert(Day12.part1(sample) == 325) 26 | } 27 | 28 | test("Part 2 should handle sample input correctly") { 29 | assert(Day12.part2(sample) == 50000000501L) 30 | } 31 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2018/Day13Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day13Suite extends AnyFunSuite: 6 | val sample1 = Seq( 7 | """/->-\ """, 8 | """| | /----\""", 9 | """| /-+--+-\ |""", 10 | """| | | | v |""", 11 | """\-+-/ \-+--/""", 12 | """ \------/ """) 13 | 14 | test("Part 1 should handle sample input correctly") { 15 | assert(Day13.part1(sample1) == "7,3") 16 | } 17 | 18 | val sample2 = Seq( 19 | """/>-<\ """, 20 | """| | """, 21 | """| /<+-\""", 22 | """| | | v""", 23 | """\>+/""") 26 | 27 | test("Part 2 should handle sample input correctly") { 28 | assert(Day13.part2(sample2) == "6,4") 29 | } 30 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2018/Day14Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day14Suite extends AnyFunSuite: 6 | val sample = 9 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day14.part1(sample) == "5158916779") 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day14.part2(sample) == 13) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2018/Day15Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day15Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "#######", 8 | "#.G...#", 9 | "#...EG#", 10 | "#.#.#G#", 11 | "#..G#E#", 12 | "#.....#", 13 | "#######") 14 | 15 | test("Part 1 should handle sample input correctly") { 16 | assert(Day15.part1(sample) == 27730) 17 | } 18 | 19 | test("Part 2 should handle sample input correctly") { 20 | assert(Day15.part2(sample) == 4988) 21 | } 22 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2018/Day16Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day16Suite extends AnyFunSuite 6 | // No unit tests possible 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2018/Day17Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day17Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "x=495, y=2..7", 8 | "y=7, x=495..501", 9 | "x=501, y=3..7", 10 | "x=498, y=2..4", 11 | "x=506, y=1..2", 12 | "x=498, y=10..13", 13 | "x=504, y=10..13", 14 | "y=13, x=498..504") 15 | 16 | test("Part 1 should handle sample input correctly") { 17 | assert(Day17.part1(sample) == 57) 18 | } 19 | 20 | test("Part 2 should handle sample input correctly") { 21 | assert(Day17.part2(sample) == 29) 22 | } 23 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2018/Day18Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day18Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | ".#.#...|#.", 8 | ".....#|##|", 9 | ".|..|...#.", 10 | "..|#.....#", 11 | "#.#|||#|#|", 12 | "...#.||...", 13 | ".|....|...", 14 | "||...#|.#|", 15 | "|.||||..|.", 16 | "...#.|..|.") 17 | 18 | test("Part 1 should handle sample input correctly") { 19 | assert(Day18.part1(sample) == 1147) 20 | } 21 | 22 | // Part 2 sample data has no cycle 23 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2018/Day19Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day19Suite extends AnyFunSuite 6 | // No unit tests needed 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2018/Day20Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day20Suite extends AnyFunSuite: 6 | val sample = "^WSSEESWWWNW(S|NENNEEEENN(ESSSSW(NWSW|SSEN)|WSWWN(E|WWS(E|SS))))$" 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day20.part1(sample) == 31) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day20.part2(sample, 10) == 39) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2018/Day21Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day21Suite extends AnyFunSuite 6 | // No unit tests possible 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2018/Day22Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day22Suite extends AnyFunSuite: 6 | val sample = Seq("depth: 510", "target: 10,10") 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day22.part1(sample) == 114) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day22.part2(sample) == 45) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2018/Day23Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day23Suite extends AnyFunSuite: 6 | val sample1 = Seq( 7 | "pos=<0,0,0>, r=4", 8 | "pos=<1,0,0>, r=1", 9 | "pos=<4,0,0>, r=3", 10 | "pos=<0,2,0>, r=1", 11 | "pos=<0,5,0>, r=3", 12 | "pos=<0,0,3>, r=1", 13 | "pos=<1,1,1>, r=1", 14 | "pos=<1,1,2>, r=1", 15 | "pos=<1,3,1>, r=1") 16 | 17 | test("Part 1 should handle sample input correctly") { 18 | assert(Day23.part1(sample1) == 7) 19 | } 20 | 21 | val sample2 = Seq( 22 | "pos=<10,12,12>, r=2", 23 | "pos=<12,14,12>, r=2", 24 | "pos=<16,12,12>, r=4", 25 | "pos=<14,14,14>, r=6", 26 | "pos=<50,50,50>, r=200", 27 | "pos=<10,10,10>, r=5") 28 | 29 | test("Part 2 should handle sample input correctly") { 30 | assert(Day23.part2(sample2) == 36) 31 | } 32 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2018/Day24Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day24Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "Immune System:", 8 | "17 units each with 5390 hit points (weak to radiation, bludgeoning) with an attack that does 4507 fire damage at initiative 2", 9 | "989 units each with 1274 hit points (immune to fire; weak to bludgeoning, slashing) with an attack that does 25 slashing damage at initiative 3", 10 | "", 11 | "Infection:", 12 | "801 units each with 4706 hit points (weak to radiation) with an attack that does 116 bludgeoning damage at initiative 1", 13 | "4485 units each with 2961 hit points (immune to radiation; weak to fire, cold) with an attack that does 12 slashing damage at initiative 4") 14 | 15 | test("Part 1 should handle sample input correctly") { 16 | assert(Day24.part1(sample) == 5216) 17 | } 18 | 19 | test("Part 2 should handle sample input correctly") { 20 | assert(Day24.part2(sample) == 51) 21 | } 22 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2018/Day25Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2018 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day25Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "0,0,0,0", 8 | "15,0,0,0", 9 | "9,0,0,0", 10 | "3,0,0,0", 11 | "12,0,0,0", 12 | "6,0,0,0", 13 | "30,0,0,0", 14 | "33,0,0,0", 15 | "40,0,0,0") 16 | 17 | test("Part 1 should handle sample input correctly") { 18 | assert(Day25.part1(sample) == 3) 19 | } 20 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2019/Day01Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day01Suite extends AnyFunSuite: 6 | val sample = Seq(100756) 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day01.part1(sample) == 33583) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day01.part2(sample) == 50346) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2019/Day02Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day02Suite extends AnyFunSuite: 6 | val sample = Seq(1, 9, 10, 3, 2, 3, 11, 0, 99, 30, 40, 50, 0) 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day02.part1(sample) == 100) 10 | } 11 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2019/Day03Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day03Suite extends AnyFunSuite: 6 | val sample = Seq("U7,R6,D4,L4", "R8,U5,L5,D3") 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day03.part1(sample) == 6) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day03.part2(sample) == 30) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2019/Day04Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day04Suite extends AnyFunSuite: 6 | val sample = Seq(100000, 200000) 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day04.part1(sample) == 1231) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day04.part2(sample) == 898) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2019/Day05Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day05Suite extends AnyFunSuite 6 | // No tests possible -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2019/Day06Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day06Suite extends AnyFunSuite: 6 | val sample1 = Seq("COM)B", "B)C", "C)D", "D)E", "E)F", "B)G", "G)H", "D)I", "E)J", "J)K", "K)L") 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day06.part1(sample1) == 42) 10 | } 11 | 12 | val sample2 = Seq("COM)B", "B)C", "C)D", "D)E", "E)F", "B)G", "G)H", "D)I", "E)J", "J)K", "K)L", "K)YOU", "I)SAN") 13 | 14 | test("Part 2 should handle sample input correctly") { 15 | assert(Day06.part2(sample2) == 4) 16 | } 17 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2019/Day07Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day07Suite extends AnyFunSuite: 6 | val sample1 = Seq(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) 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day07.part1(sample1) == 65210) 10 | } 11 | 12 | val sample2 = Seq(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) 13 | 14 | test("Part 2 should handle sample input correctly") { 15 | assert(Day07.part2(sample2) == 139629729) 16 | } 17 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2019/Day08Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day08Suite extends AnyFunSuite 6 | // No unit tests possible -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2019/Day09Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day09Suite extends AnyFunSuite: 6 | val sample = Seq(1102,34915192,34915192,7,4,7,99,0).map(_.toLong) 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day09.part1(sample) == 1219070632396864L) 10 | } 11 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2019/Day10Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day10Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | ".#..##.###...#######", 8 | "##.############..##.", 9 | ".#.######.########.#", 10 | ".###.#######.####.#.", 11 | "#####.##.#.##.###.##", 12 | "..#####..#.#########", 13 | "####################", 14 | "#.####....###.#.#.##", 15 | "##.#################", 16 | "#####.##.###..####..", 17 | "..######..##.#######", 18 | "####.##.####...##..#", 19 | ".#####..#.######.###", 20 | "##...#.##########...", 21 | "#.##########.#######", 22 | ".####.#.###.###.#.##", 23 | "....##.##.###..#####", 24 | ".#.#.###########.###", 25 | "#.#.#.#####.####.###", 26 | "###.##.####.##.#..##") 27 | 28 | test("Part 1 should handle sample input correctly") { 29 | assert(Day10.part1(sample) == 210) 30 | } 31 | 32 | test("Part 2 should handle sample input correctly") { 33 | assert(Day10.part2(sample) == 802) 34 | } 35 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2019/Day11Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day11Suite extends AnyFunSuite 6 | // No unit tests possible -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2019/Day12Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day12Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "", 8 | "", 9 | "", 10 | "") 11 | 12 | test("Part 1 should handle sample input correctly") { 13 | assert(Day12.part1(sample) == 183) 14 | } 15 | 16 | test("Part 2 should handle sample input correctly") { 17 | assert(Day12.part2(sample) == 2772) 18 | } 19 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2019/Day13Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day13Suite extends AnyFunSuite 6 | // No unit tests possible -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2019/Day14Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day14Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "157 ORE => 5 NZVS", 8 | "165 ORE => 6 DCFZ", 9 | "44 XJWVT, 5 KHKGT, 1 QDVJ, 29 NZVS, 9 GPVTF, 48 HKGWZ => 1 FUEL", 10 | "12 HKGWZ, 1 GPVTF, 8 PSHF => 9 QDVJ", 11 | "179 ORE => 7 PSHF", 12 | "177 ORE => 5 HKGWZ", 13 | "7 DCFZ, 7 PSHF => 2 XJWVT", 14 | "165 ORE => 2 GPVTF", 15 | "3 DCFZ, 7 NZVS, 5 HKGWZ, 10 PSHF => 8 KHKGT") 16 | 17 | test("Part 1 should handle sample input correctly") { 18 | assert(Day14.part1(sample) == 13312L) 19 | } 20 | 21 | test("Part 2 should handle sample input correctly") { 22 | assert(Day14.part2(sample) == 82892753L) 23 | } 24 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2019/Day15Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day15Suite extends AnyFunSuite 6 | // No unit tests possible -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2019/Day16Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day16Suite extends AnyFunSuite: 6 | val sample1 = "80871224585914546619083218645595" 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day16.part1(sample1) == "24176176") 10 | } 11 | 12 | val sample2 = "03036732577212944063491565474664" 13 | 14 | test("Part 2 should handle sample input correctly") { 15 | assert(Day16.part2(sample2) == "84462026") 16 | } 17 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2019/Day17Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day17Suite extends AnyFunSuite 6 | // No unit tests possible 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2019/Day18Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day18Suite extends AnyFunSuite: 6 | val sample1 = Seq( 7 | "########################", 8 | "#f.D.E.e.C.b.A.@.a.B.c.#", 9 | "######################.#", 10 | "#d.....................#", 11 | "########################") 12 | 13 | test("Part 1 should handle sample input correctly") { 14 | assert(Day18.part1(sample1) == 86) 15 | } 16 | 17 | val sample2 = Seq( 18 | "#############", 19 | "#g#f.D#..h#l#", 20 | "#F###e#E###.#", 21 | "#dCba@#@BcIJ#", 22 | "#############", 23 | "#nK.L@#@G...#", 24 | "#M###N#H###.#", 25 | "#o#m..#i#jk.#", 26 | "#############") 27 | 28 | test("Part 2 should handle sample input correctly") { 29 | assert(Day18.part1(sample2) == 72) 30 | } 31 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2019/Day19Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day19Suite extends AnyFunSuite 6 | // No unit tests possible -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2019/Day21Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day21Suite extends AnyFunSuite 6 | // No unit tests possible -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2019/Day22Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day22Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "deal into new stack", 8 | "cut -2", 9 | "deal with increment 7", 10 | "cut 8", 11 | "cut -4", 12 | "deal with increment 7", 13 | "cut 3", 14 | "deal with increment 9", 15 | "deal with increment 3", 16 | "cut -1") 17 | 18 | test("Part 1 should handle sample input correctly") { 19 | assert(Day22.part1(sample) == 1219L) 20 | } 21 | 22 | test("Part 2 should handle sample input correctly") { 23 | assert(Day22.part2(sample) == 117607927195067L) 24 | } 25 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2019/Day23Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day23Suite extends AnyFunSuite 6 | // No unit tests possible 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2019/Day24Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day24Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "....#", 8 | "#..#.", 9 | "#..##", 10 | "..#..", 11 | "#....") 12 | 13 | test("Part 1 should handle sample input correctly") { 14 | assert(Day24.part1(sample) == 2129920) 15 | } 16 | 17 | test("Part 2 should handle sample input correctly") { 18 | assert(Day24.part2(sample, 10) == 99) 19 | } 20 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2019/Day25Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2019 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day25Suite extends AnyFunSuite 6 | // No unit tests possible -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2020/Day01Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day01Suite extends AnyFunSuite: 6 | val sample = Seq(1721, 979, 366, 299, 675, 1456) 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day01.part1(sample) == 514579) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day01.part2(sample) == 241861950) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2020/Day02Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day02Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "1-3 a: abcde", 8 | "1-3 b: cdefg", 9 | "2-9 c: ccccccccc") 10 | 11 | test("Part 1 should handle sample input correctly") { 12 | assert(Day02.part1(sample) == 2) 13 | } 14 | 15 | test("Part 2 should handle sample input correctly") { 16 | assert(Day02.part2(sample) == 1) 17 | } 18 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2020/Day03Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day03Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "..##.......", 8 | "#...#...#..", 9 | ".#....#..#.", 10 | "..#.#...#.#", 11 | ".#...##..#.", 12 | "..#.##.....", 13 | ".#.#.#....#", 14 | ".#........#", 15 | "#.##...#...", 16 | "#...##....#", 17 | ".#..#...#.#") 18 | 19 | test("Part 1 should handle sample input correctly") { 20 | assert(Day03.part1(sample) == 7) 21 | } 22 | 23 | test("Part 2 should handle sample input correctly") { 24 | assert(Day03.part2(sample) == 336) 25 | } 26 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2020/Day04Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day04Suite extends AnyFunSuite: 6 | val sample = """ 7 | ecl:gry pid:860033327 eyr:2020 hcl:#fffffd 8 | byr:1937 iyr:2017 cid:147 hgt:183cm 9 | 10 | iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884 11 | hcl:#cfa07d byr:1929 12 | 13 | hcl:#ae17e1 iyr:2013 14 | eyr:2024 15 | ecl:brn pid:760753108 byr:1931 16 | hgt:179cm 17 | 18 | hcl:#cfa07d eyr:2025 pid:166559648 19 | iyr:2011 ecl:brn hgt:59in 20 | """ 21 | 22 | test("Part 1 should handle sample input correctly") { 23 | assert(Day04.part1(sample) == 2) 24 | } 25 | 26 | test("Part 2 should handle sample input correctly") { 27 | assert(Day04.part2(sample) == 2) 28 | } 29 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2020/Day05Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day05Suite extends AnyFunSuite: 6 | val sample = Seq("FBFBBFFLRR", "FBFBBFFRLR") 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day05.part1(sample) == 357) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day05.part2(sample) == 356) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2020/Day06Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day06Suite extends AnyFunSuite: 6 | val sample = """ 7 | abc 8 | 9 | a 10 | b 11 | c 12 | 13 | ab 14 | ac 15 | 16 | a 17 | a 18 | a 19 | a 20 | 21 | b 22 | """ 23 | 24 | test("Part 1 should handle sample input correctly") { 25 | assert(Day06.part1(sample) == 11) 26 | } 27 | 28 | test("Part 2 should handle sample input correctly") { 29 | assert(Day06.part2(sample) == 6) 30 | } 31 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2020/Day07Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day07Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "light red bags contain 1 bright white bag, 2 muted yellow bags.", 8 | "dark orange bags contain 3 bright white bags, 4 muted yellow bags.", 9 | "bright white bags contain 1 shiny gold bag.", 10 | "muted yellow bags contain 2 shiny gold bags, 9 faded blue bags.", 11 | "shiny gold bags contain 1 dark olive bag, 2 vibrant plum bags.", 12 | "dark olive bags contain 3 faded blue bags, 4 dotted black bags.", 13 | "vibrant plum bags contain 5 faded blue bags, 6 dotted black bags.", 14 | "faded blue bags contain no other bags.", 15 | "dotted black bags contain no other bags.") 16 | 17 | test("Part 1 should handle sample input correctly") { 18 | assert(Day07.part1(sample) == 4) 19 | } 20 | 21 | test("Part 2 should handle sample input correctly") { 22 | assert(Day07.part2(sample) == 32) 23 | } 24 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2020/Day08Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day08Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "nop +0", 8 | "acc +1", 9 | "jmp +4", 10 | "acc +3", 11 | "jmp -3", 12 | "acc -99", 13 | "acc +1", 14 | "jmp -4", 15 | "acc +6") 16 | 17 | test("Part 1 should handle sample input correctly") { 18 | assert(Day08.part1(sample) == 5) 19 | } 20 | 21 | test("Part 2 should handle sample input correctly") { 22 | assert(Day08.part2(sample) == 8) 23 | } 24 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2020/Day09Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day09Suite extends AnyFunSuite: 6 | val sample = Seq(35, 20, 15, 25, 47, 40, 62, 55, 65, 95, 102, 117, 150, 182, 127, 219, 299, 277, 309, 576).map(_.toLong) 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day09.part1(sample, 5) == 127) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day09.part2(sample, 5) == 62) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2020/Day10Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day10Suite extends AnyFunSuite: 6 | val sample = Seq(16, 10, 15, 5, 1, 11, 7, 19 ,6 ,12, 4) 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day10.part1(sample) == 35L) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day10.part2(sample) == 8L) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2020/Day11Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day11Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "L.LL.LL.LL", 8 | "LLLLLLL.LL", 9 | "L.L.L..L..", 10 | "LLLL.LL.LL", 11 | "L.LL.LL.LL", 12 | "L.LLLLL.LL", 13 | "..L.L.....", 14 | "LLLLLLLLLL", 15 | "L.LLLLLL.L", 16 | "L.LLLLL.LL") 17 | 18 | test("Part 1 should handle sample input correctly") { 19 | assert(Day11.part1(sample) == 37) 20 | } 21 | 22 | test("Part 2 should handle sample input correctly") { 23 | assert(Day11.part2(sample) == 26) 24 | } 25 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2020/Day12Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day12Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "F10", 8 | "N3", 9 | "F7", 10 | "R90", 11 | "F11") 12 | 13 | test("Part 1 should handle sample input correctly") { 14 | assert(Day12.part1(sample) == 25) 15 | } 16 | 17 | test("Part 2 should handle sample input correctly") { 18 | assert(Day12.part2(sample) == 286) 19 | } 20 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2020/Day13Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day13Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "939", 8 | "7,13,x,x,59,x,31,19") 9 | 10 | test("Part 1 should handle sample input correctly") { 11 | assert(Day13.part1(sample) == 295L) 12 | } 13 | 14 | test("Part 2 should handle sample input correctly") { 15 | assert(Day13.part2(sample) == 1068781L) 16 | } 17 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2020/Day14Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day14Suite extends AnyFunSuite: 6 | val sample1 = Seq( 7 | "mask = XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X", 8 | "mem[8] = 11", 9 | "mem[7] = 101", 10 | "mem[8] = 0") 11 | 12 | test("Part 1 should handle sample input correctly") { 13 | assert(Day14.part1(sample1) == 165) 14 | } 15 | 16 | val sample2 = Seq( 17 | "mask = 000000000000000000000000000000X1001X", 18 | "mem[42] = 100", 19 | "mask = 00000000000000000000000000000000X0XX", 20 | "mem[26] = 1") 21 | 22 | test("Part 2 should handle sample input correctly") { 23 | assert(Day14.part2(sample2) == 208) 24 | } 25 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2020/Day15Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day15Suite extends AnyFunSuite: 6 | val sample = Seq(0, 3, 6) 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day15.part1(sample) == 436) 10 | } 11 | 12 | // Test is correct but slow 13 | // test("Part 2 should handle sample input correctly") { 14 | // assert(Day15.part2(sample) == 175594) 15 | // } 16 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2020/Day16Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day16Suite extends AnyFunSuite: 6 | val sample1 = Seq( 7 | "class: 1-3 or 5-7", 8 | "row: 6-11 or 33-44", 9 | "seat: 13-40 or 45-50", 10 | "", 11 | "your ticket:", 12 | "7,1,14", 13 | "", 14 | "nearby tickets:", 15 | "7,3,47", 16 | "40,4,50", 17 | "55,2,20", 18 | "38,6,12") 19 | 20 | test("Part 1 should handle sample input correctly") { 21 | assert(Day16.part1(sample1) == 71L) 22 | } 23 | 24 | val sample2 = Seq( 25 | "departure: 0-1 or 4-19", 26 | "row: 0-5 or 8-19", 27 | "seat: 0-13 or 16-19", 28 | "", 29 | "your ticket:", 30 | "11,12,13", 31 | "", 32 | "nearby tickets:", 33 | "3,9,18", 34 | "15,1,5", 35 | "5,14,9") 36 | 37 | test("Part 2 should handle sample input correctly") { 38 | assert(Day16.part2(sample2) == 12L) 39 | } 40 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2020/Day17Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day17Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | ".#.", 8 | "..#", 9 | "###") 10 | 11 | test("Part 1 should handle sample input correctly") { 12 | assert(Day17.part1(sample) == 112) 13 | } 14 | 15 | test("Part 2 should handle sample input correctly") { 16 | assert(Day17.part2(sample) == 848) 17 | } 18 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2020/Day18Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day18Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "1 + 2 * 3 + 4 * 5 + 6", 8 | "1 + (2 * 3) + (4 * (5 + 6))", 9 | "2 * 3 + (4 * 5)", 10 | "5 + (8 * 3 + 9 + 3 * 4 * 3)", 11 | "5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4))", 12 | "((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2") 13 | 14 | test("Part 1 should handle sample input correctly") { 15 | assert(Day18.part1(sample) == 26457L) 16 | } 17 | 18 | test("Part 2 should handle sample input correctly") { 19 | assert(Day18.part2(sample) == 694173L) 20 | } 21 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2020/Day21Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day21Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "mxmxvkd kfcds sqjhc nhms (contains dairy, fish)", 8 | "trh fvjkl sbzzf mxmxvkd (contains dairy)", 9 | "sqjhc fvjkl (contains soy)", 10 | "sqjhc mxmxvkd sbzzf (contains fish)") 11 | 12 | test("Part 1 should handle sample input correctly") { 13 | assert(Day21.part1(sample) == 5) 14 | } 15 | 16 | test("Part 2 should handle sample input correctly") { 17 | assert(Day21.part2(sample) == "mxmxvkd,sqjhc,fvjkl") 18 | } 19 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2020/Day22Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day22Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "Player 1:", "9", "2", "6", "3", "1", 8 | "", 9 | "Player 2:", "5", "8", "4", "7", "10") 10 | 11 | test("Part 1 should handle sample input correctly") { 12 | assert(Day22.part1(sample) == 306) 13 | } 14 | 15 | test("Part 2 should handle sample input correctly") { 16 | assert(Day22.part2(sample) == 291) 17 | } 18 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2020/Day23Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day23Suite extends AnyFunSuite: 6 | val sample = "389125467" 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day23.part1(sample) == "67384529") 10 | } 11 | 12 | // Test is correct but too slow 13 | // test("Part 2 should handle sample input correctly") { 14 | // assert(Day23.part2(sample) == 149245887792L) 15 | // } 16 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2020/Day25Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2020 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day25Suite extends AnyFunSuite: 6 | val sample = Seq(5764801, 17807724) 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day25.part1(sample) == 14897079L) 10 | } 11 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2021/Day01Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day01Suite extends AnyFunSuite: 6 | val sample = Seq(199, 200, 208, 210, 200, 207, 240, 269, 260, 263) 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day01.part1(sample) == 7) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day01.part2(sample) == 5) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2021/Day02Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day02Suite extends AnyFunSuite: 6 | val sample = Seq("forward 5", "down 5", "forward 8", "up 3", "down 8", "forward 2") 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day02.part1(sample) == 150) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day02.part2(sample) == 900) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2021/Day03Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day03Suite extends AnyFunSuite: 6 | val sample = Seq("00100", "11110", "10110", "10111", "10101", "01111", "00111", "11100", "10000", "11001", "00010", "01010") 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day03.part1(sample) == 198) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day03.part2(sample) == 230) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2021/Day04Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day04Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "7,4,9,5,11,17,23,2,0,14,21,24,10,16,13,6,15,25,12,22,18,20,8,19,3,26,1", 8 | "", 9 | "22 13 17 11 0", 10 | " 8 2 23 4 24", 11 | "21 9 14 16 7", 12 | " 6 10 3 18 5", 13 | " 1 12 20 15 19", 14 | "", 15 | " 3 15 0 2 22", 16 | " 9 18 13 17 5", 17 | "19 8 7 25 23", 18 | "20 11 10 24 4", 19 | "14 21 16 12 6", 20 | "", 21 | "14 21 17 24 4", 22 | "10 16 15 9 19", 23 | "18 8 23 26 20", 24 | "22 11 13 6 5", 25 | " 2 0 12 3 7") 26 | 27 | test("Part 1 should handle sample input correctly") { 28 | assert(Day04.part1(sample) == 4512) 29 | } 30 | 31 | test("Part 2 should handle sample input correctly") { 32 | assert(Day04.part2(sample) == 1924) 33 | } 34 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2021/Day05Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day05Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "0,9 -> 5,9", 8 | "8,0 -> 0,8", 9 | "9,4 -> 3,4", 10 | "2,2 -> 2,1", 11 | "7,0 -> 7,4", 12 | "6,4 -> 2,0", 13 | "0,9 -> 2,9", 14 | "3,4 -> 1,4", 15 | "0,0 -> 8,8", 16 | "5,5 -> 8,2") 17 | 18 | test("Part 1 should handle sample input correctly") { 19 | assert(Day05.part1(sample) == 5) 20 | } 21 | 22 | test("Part 2 should handle sample input correctly") { 23 | assert(Day05.part2(sample) == 12) 24 | } 25 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2021/Day06Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day06Suite extends AnyFunSuite: 6 | val sample = Seq(3,4,3,1,2) 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day06.part1(sample) == 5934L) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day06.part2(sample) == 26984457539L) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2021/Day07Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day07Suite extends AnyFunSuite: 6 | val sample = Seq(16,1,2,0,4,2,7,1,2,14) 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day07.part1(sample) == 37) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day07.part2(sample) == 168) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2021/Day09Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day09Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "2199943210", 8 | "3987894921", 9 | "9856789892", 10 | "8767896789", 11 | "9899965678") 12 | 13 | test("Part 1 should handle sample input correctly") { 14 | assert(Day09.part1(sample) == 15) 15 | } 16 | 17 | test("Part 2 should handle sample input correctly") { 18 | assert(Day09.part2(sample) == 1134) 19 | } 20 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2021/Day10Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day10Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "[({(<(())[]>[[{[]{<()<>>", 8 | "[(()[<>])]({[<{<<[]>>(", 9 | "{([(<{}[<>[]}>{[]{[(<()>", 10 | "(((({<>}<{<{<>}{[]{[]{}", 11 | "[[<[([]))<([[{}[[()]]]", 12 | "[{[{({}]{}}([{[{{{}}([]", 13 | "{<[[]]>}<{[{[{[]{()[[[]", 14 | "[<(<(<(<{}))><([]([]()", 15 | "<{([([[(<>()){}]>(<<{{", 16 | "<{([{{}}[<[[[<>{}]]]>[]]") 17 | 18 | test("Part 1 should handle sample input correctly") { 19 | assert(Day10.part1(sample) == 26397L) 20 | } 21 | 22 | test("Part 2 should handle sample input correctly") { 23 | assert(Day10.part2(sample) == 288957L) 24 | } 25 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2021/Day11Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day11Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "5483143223", 8 | "2745854711", 9 | "5264556173", 10 | "6141336146", 11 | "6357385478", 12 | "4167524645", 13 | "2176841721", 14 | "6882881134", 15 | "4846848554", 16 | "5283751526") 17 | 18 | test("Part 1 should handle sample input correctly") { 19 | assert(Day11.part1(sample) == 1656) 20 | } 21 | 22 | test("Part 2 should handle sample input correctly") { 23 | assert(Day11.part2(sample) == 195) 24 | } 25 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2021/Day12Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day12Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "start-A", 8 | "start-b", 9 | "A-c", 10 | "A-b", 11 | "b-d", 12 | "A-end", 13 | "b-end" 14 | ) 15 | 16 | test("Part 1 should handle sample input correctly") { 17 | assert(Day12.part1(sample) == 10) 18 | } 19 | 20 | test("Part 2 should handle sample input correctly") { 21 | assert(Day12.part2(sample) == 36) 22 | } 23 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2021/Day13Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day13Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "6,10", 8 | "0,14", 9 | "9,10", 10 | "0,3", 11 | "10,4", 12 | "4,11", 13 | "6,0", 14 | "6,12", 15 | "4,1", 16 | "0,13", 17 | "10,12", 18 | "3,4", 19 | "3,0", 20 | "8,4", 21 | "1,10", 22 | "2,14", 23 | "8,10", 24 | "9,0", 25 | "", 26 | "fold along y=7", 27 | "fold along x=5") 28 | 29 | test("Part 1 should handle sample input correctly") { 30 | assert(Day13.part1(sample).size == 17) 31 | } 32 | 33 | test("Part 2 should handle sample input correctly") { 34 | assert(Day13.part2(sample).size == 16) 35 | } 36 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2021/Day14Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day14Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "NNCB", 8 | "", 9 | "CH -> B", 10 | "HH -> N", 11 | "CB -> H", 12 | "NH -> C", 13 | "HB -> C", 14 | "HC -> B", 15 | "HN -> C", 16 | "NN -> C", 17 | "BH -> H", 18 | "NC -> B", 19 | "NB -> B", 20 | "BN -> B", 21 | "BB -> N", 22 | "BC -> B", 23 | "CC -> N", 24 | "CN -> C") 25 | 26 | test("Part 1 should handle sample input correctly") { 27 | assert(Day14.part1(sample) == 1588L) 28 | } 29 | 30 | test("Part 2 should handle sample input correctly") { 31 | assert(Day14.part2(sample) == 2188189693529L) 32 | } 33 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2021/Day15Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day15Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "1163751742", 8 | "1381373672", 9 | "2136511328", 10 | "3694931569", 11 | "7463417111", 12 | "1319128137", 13 | "1359912421", 14 | "3125421639", 15 | "1293138521", 16 | "2311944581") 17 | 18 | test("Part 1 should handle sample input correctly") { 19 | assert(Day15.part1(sample) == 40) 20 | } 21 | 22 | test("Part 2 should handle sample input correctly") { 23 | assert(Day15.part2(sample) == 315) 24 | } 25 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2021/Day16Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day16Suite extends AnyFunSuite: 6 | val sample1 = Seq( 7 | "8A004A801A8002F478", 8 | "620080001611562C8802118E34", 9 | "C0015000016115A2E0802F182340", 10 | "A0016C880162017C3686B18A3D4780") 11 | 12 | test("Part 1 should handle sample input correctly") { 13 | assert(Day16.part1(sample1) == 82) 14 | } 15 | 16 | val sample2 = Seq( 17 | "C200B40A82", 18 | "04005AC33890", 19 | "880086C3E88112", 20 | "CE00C43D881120", 21 | "D8005AC2A8F0", 22 | "F600BC2D8F", 23 | "9C005AC2F8F0", 24 | "9C0141080250320F1802104A08") 25 | 26 | test("Part 2 should handle sample input correctly") { 27 | assert(Day16.part2(sample2) == 75) 28 | } 29 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2021/Day17Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day17Suite extends AnyFunSuite: 6 | val sample = "target area: x=20..30, y=-10..-5" 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day17.part1(sample) == 45) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day17.part2(sample) == 112) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2021/Day18Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day18Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "[[[0,[5,8]],[[1,7],[9,6]]],[[4,[1,2]],[[1,4],2]]]", 8 | "[[[5,[2,8]],4],[5,[[9,9],0]]]", 9 | "[6,[[[6,2],[5,6]],[[7,6],[4,7]]]]", 10 | "[[[6,[0,7]],[0,9]],[4,[9,[9,0]]]]", 11 | "[[[7,[6,4]],[3,[1,3]]],[[[5,5],1],9]]", 12 | "[[6,[[7,3],[3,2]]],[[[3,8],[5,7]],4]]", 13 | "[[[[5,4],[7,7]],8],[[8,3],8]]", 14 | "[[9,3],[[9,9],[6,[4,9]]]]", 15 | "[[2,[[7,7],7]],[[5,8],[[9,3],[0,2]]]]", 16 | "[[[[5,2],5],[8,[3,7]]],[[5,[7,5]],[4,4]]]") 17 | 18 | test("Part 1 should handle sample input correctly") { 19 | assert(Day18.part1(sample) == 4140) 20 | } 21 | 22 | test("Part 2 should handle sample input correctly") { 23 | assert(Day18.part2(sample) == 3993) 24 | } 25 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2021/Day20Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day20Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "..#.#..#####.#.#.#.###.##.....###.##.#..###.####..#####..#....#..#..##..###..######.###...####..#..#####..##..#.#####...##.#.#..#.##..#.#......#.###.######.###.####...#.##.##..#..#..#####.....#.#....###..#.##......#.....#..#..#..##..#...##.######.####.####.#.#...#.......#..#.#.#...####.##.#......#..#...##.#.##..#...##.#.##..###.#......#.#.......#.#.#.####.###.##...#.....####.#..#..#.##.#....##..#.####....##...##..#...#......#.#.......#.......##..####..#...#.#.#...##..#.#..###..#####........#..####......#..#", 8 | "", 9 | "#..#.", 10 | "#....", 11 | "##..#", 12 | "..#..", 13 | "..###") 14 | 15 | test("Part 1 should handle sample input correctly") { 16 | assert(Day20.part1(sample) == 35) 17 | } 18 | 19 | test("Part 2 should handle sample input correctly") { 20 | assert(Day20.part2(sample) == 3351) 21 | } 22 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2021/Day21Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day21Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "Player 1 starting position: 4", 8 | "Player 2 starting position: 8") 9 | 10 | test("Part 1 should handle sample input correctly") { 11 | assert(Day21.part1(sample) == 739785) 12 | } 13 | 14 | test("Part 2 should handle sample input correctly") { 15 | assert(Day21.part2(sample) == 444356092776315L) 16 | } 17 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2021/Day23Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day23Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "#############", 8 | "#...........#", 9 | "###B#C#B#D###", 10 | " #A#D#C#A#", 11 | " #########") 12 | 13 | // Tests are correct but too slow 14 | // test("Part 1 should handle sample input correctly") { 15 | // assert(Day23.part1(sample) == 12521) 16 | // } 17 | // 18 | // test("Part 2 should handle sample input correctly") { 19 | // assert(Day23.part2(sample) == 44169) 20 | // } 21 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2021/Day24Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day24Suite extends AnyFunSuite 6 | // No tests possible for Day 24 7 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2021/Day25Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2021 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day25Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "v...>>.vv>", 8 | ".vv>>.vv..", 9 | ">>.>v>...v", 10 | ">>v>>.>.v.", 11 | "v>v.vv.v..", 12 | ">.>>..v...", 13 | ".vv..>.>v.", 14 | "v.v..>>v.v", 15 | "....v..v.>") 16 | 17 | test("Part 1 should handle sample input correctly") { 18 | assert(Day25.part1(sample) == 58) 19 | } 20 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2022/Day01Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day01Suite extends AnyFunSuite: 6 | val sample = """ 7 | |1000 8 | |2000 9 | |3000 10 | | 11 | |4000 12 | | 13 | |5000 14 | |6000 15 | | 16 | |7000 17 | |8000 18 | |9000 19 | | 20 | |10000 21 | """.stripMargin.trim 22 | 23 | test("Part 1 should handle sample input correctly") { 24 | assert(Day01.part1(sample) == 24000) 25 | } 26 | 27 | test("Part 2 should handle sample input correctly") { 28 | assert(Day01.part2(sample) == 45000) 29 | } 30 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2022/Day02Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day02Suite extends AnyFunSuite: 6 | val sample = Seq("A Y", "B X", "C Z") 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day02.part1(sample) == 15) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day02.part2(sample) == 12) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2022/Day03Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day03Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "vJrwpWtwJgWrhcsFMMfFFhFp", 8 | "jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL", 9 | "PmmdzqPrVvPwwTWBwg", 10 | "wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn", 11 | "ttgJtRGJQctTZtZT", 12 | "CrZsJsPPZsGzwwsLwLmpwMDw" 13 | ) 14 | 15 | test("Part 1 should handle sample input correctly") { 16 | assert(Day03.part1(sample) == 157) 17 | } 18 | 19 | test("Part 2 should handle sample input correctly") { 20 | assert(Day03.part2(sample) == 70) 21 | } 22 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2022/Day04Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day04Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "2-4,6-8", 8 | "2-3,4-5", 9 | "5-7,7-9", 10 | "2-8,3-7", 11 | "6-6,4-6", 12 | "2-6,4-8" 13 | ) 14 | 15 | test("Part 1 should handle sample input correctly") { 16 | assert(Day04.part1(sample) == 2) 17 | } 18 | 19 | test("Part 2 should handle sample input correctly") { 20 | assert(Day04.part2(sample) == 4) 21 | } 22 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2022/Day05Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day05Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | " [D] ", 8 | "[N] [C] ", 9 | "[Z] [M] [P]", 10 | " 1 2 3 ", 11 | "", 12 | "move 1 from 2 to 1", 13 | "move 3 from 1 to 3", 14 | "move 2 from 2 to 1", 15 | "move 1 from 1 to 2") 16 | 17 | test("Part 1 should handle sample input correctly") { 18 | assert(Day05.part1(sample) == "CMZ") 19 | } 20 | 21 | test("Part 2 should handle sample input correctly") { 22 | assert(Day05.part2(sample) == "MCD") 23 | } 24 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2022/Day06Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day06Suite extends AnyFunSuite: 6 | test("Part 1 should handle sample input correctly") { 7 | assert(Day06.part1("bvwbjplbgvbhsrlpgdmjqwftvncz") == 5) 8 | } 9 | 10 | test("Part 2 should handle sample input correctly") { 11 | assert(Day06.part2("mjqjpqmgbljsphdztnvjfqwrcgsmlb") == 19) 12 | } 13 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2022/Day07Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day07Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "$ cd /", 8 | "$ ls", 9 | "dir a", 10 | "14848514 b.txt", 11 | "8504156 c.dat", 12 | "dir d", 13 | "$ cd a", 14 | "$ ls", 15 | "dir e", 16 | "29116 f", 17 | "2557 g", 18 | "62596 h.lst", 19 | "$ cd e", 20 | "$ ls", 21 | "584 i", 22 | "$ cd ..", 23 | "$ cd ..", 24 | "$ cd d", 25 | "$ ls", 26 | "4060174 j", 27 | "8033020 d.log", 28 | "5626152 d.ext", 29 | "7214296 k", 30 | ) 31 | 32 | test("Part 1 should handle sample input correctly") { 33 | assert(Day07.part1(sample) == 95437) 34 | } 35 | 36 | test("Part 2 should handle sample input correctly") { 37 | assert(Day07.part2(sample) == 24933642) 38 | } 39 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2022/Day08Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day08Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "30373", 8 | "25512", 9 | "65332", 10 | "33549", 11 | "35390" 12 | ) 13 | 14 | test("Part 1 should handle sample input correctly") { 15 | assert(Day08.part1(sample) == 21) 16 | } 17 | 18 | test("Part 2 should handle sample input correctly") { 19 | assert(Day08.part2(sample) == 8) 20 | } 21 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2022/Day09Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day09Suite extends AnyFunSuite: 6 | test("Part 1 should handle sample input correctly") { 7 | assert(Day09.part1(Seq("R 4", "U 4", "L 3", "D 1", "R 4", "D 1", "L 5", "R 2")) == 13) 8 | } 9 | 10 | test("Part 2 should handle sample input correctly") { 11 | assert(Day09.part2(Seq("R 5", "U 8", "L 8", "D 3", "R 17", "D 10", "L 25", "U 20")) == 36) 12 | } 13 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2022/Day12Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day12Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "Sabqponm", 8 | "abcryxxl", 9 | "accszExk", 10 | "acctuvwj", 11 | "abdefghi") 12 | 13 | test("Part 1 should handle sample input correctly") { 14 | assert(Day12.part1(sample) == 31) 15 | } 16 | 17 | test("Part 2 should handle sample input correctly") { 18 | assert(Day12.part2(sample) == 29) 19 | } 20 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2022/Day13Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day13Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "[1,1,3,1,1]", 8 | "[1,1,5,1,1]", 9 | "", 10 | "[[1],[2,3,4]]", 11 | "[[1],4]", 12 | "", 13 | "[9]", 14 | "[[8,7,6]]", 15 | "", 16 | "[[4,4],4,4]", 17 | "[[4,4],4,4,4]", 18 | "", 19 | "[7,7,7,7]", 20 | "[7,7,7]", 21 | "", 22 | "[]", 23 | "[3]", 24 | "", 25 | "[[[]]]", 26 | "[[]]", 27 | "", 28 | "[1,[2,[3,[4,[5,6,7]]]],8,9]", 29 | "[1,[2,[3,[4,[5,6,0]]]],8,9]") 30 | 31 | test("Part 1 should handle sample input correctly") { 32 | assert(Day13.part1(sample) == 13) 33 | } 34 | 35 | test("Part 2 should handle sample input correctly") { 36 | assert(Day13.part2(sample) == 140) 37 | } 38 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2022/Day14Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day14Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "498,4 -> 498,6 -> 496,6", 8 | "503,4 -> 502,4 -> 502,9 -> 494,9") 9 | 10 | test("Part 1 should handle sample input correctly") { 11 | assert(Day14.part1(sample) == 24) 12 | } 13 | 14 | test("Part 2 should handle sample input correctly") { 15 | assert(Day14.part2(sample) == 93) 16 | } 17 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2022/Day16Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day16Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "Valve AA has flow rate=0; tunnels lead to valves DD, II, BB", 8 | "Valve BB has flow rate=13; tunnels lead to valves CC, AA", 9 | "Valve CC has flow rate=2; tunnels lead to valves DD, BB", 10 | "Valve DD has flow rate=20; tunnels lead to valves CC, AA, EE", 11 | "Valve EE has flow rate=3; tunnels lead to valves FF, DD", 12 | "Valve FF has flow rate=0; tunnels lead to valves EE, GG", 13 | "Valve GG has flow rate=0; tunnels lead to valves FF, HH", 14 | "Valve HH has flow rate=22; tunnel leads to valve GG", 15 | "Valve II has flow rate=0; tunnels lead to valves AA, JJ", 16 | "Valve JJ has flow rate=21; tunnel leads to valve II") 17 | 18 | test("Part 1 should handle sample input correctly") { 19 | assert(Day16.part1(sample) == 1651) 20 | } 21 | 22 | test("Part 2 should handle sample input correctly") { 23 | assert(Day16.part2(sample) == 1707) 24 | } 25 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2022/Day17Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day17Suite extends AnyFunSuite: 6 | val sample = ">>><<><>><<<>><>>><<<>>><<<><<<>><>><<>>" 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day17.part1(sample) == 3068) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day17.part2(sample) == 1514285714288L) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2022/Day18Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day18Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "2,2,2", 8 | "1,2,2", 9 | "3,2,2", 10 | "2,1,2", 11 | "2,3,2", 12 | "2,2,1", 13 | "2,2,3", 14 | "2,2,4", 15 | "2,2,6", 16 | "1,2,5", 17 | "3,2,5", 18 | "2,1,5", 19 | "2,3,5") 20 | 21 | test("Part 1 should handle sample input correctly") { 22 | assert(Day18.part1(sample) == 64) 23 | } 24 | 25 | test("Part 2 should handle sample input correctly") { 26 | assert(Day18.part2(sample) == 58) 27 | } 28 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2022/Day19Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day19Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "Blueprint 1: Each ore robot costs 4 ore. Each clay robot costs 2 ore. Each obsidian robot costs 3 ore and 14 clay. Each geode robot costs 2 ore and 7 obsidian.", 8 | "Blueprint 2: Each ore robot costs 2 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 8 clay. Each geode robot costs 3 ore and 12 obsidian.") 9 | 10 | test("Part 1 should handle sample input correctly") { 11 | assert(Day19.part1(sample) == 33) 12 | } 13 | 14 | test("Part 2 should handle sample input correctly") { 15 | assert(Day19.part2(sample) == 1157) 16 | } 17 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2022/Day20Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day20Suite extends AnyFunSuite: 6 | val sample = Seq(1, 2, -3, 3, -2, 0, 4) 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day20.part1(sample) == 3) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day20.part2(sample) == 1623178306L) 14 | } 15 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2022/Day21Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day21Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "root: pppw + sjmn", 8 | "dbpl: 5", 9 | "cczh: sllz + lgvd", 10 | "zczc: 2", 11 | "ptdq: humn - dvpt", 12 | "dvpt: 3", 13 | "lfqf: 4", 14 | "humn: 5", 15 | "ljgn: 2", 16 | "sjmn: drzm * dbpl", 17 | "sllz: 4", 18 | "pppw: cczh / lfqf", 19 | "lgvd: ljgn * ptdq", 20 | "drzm: hmdt - zczc", 21 | "hmdt: 32") 22 | 23 | test("Part 1 should handle sample input correctly") { 24 | assert(Day21.part1(sample) == 152) 25 | } 26 | 27 | test("Part 2 should handle sample input correctly") { 28 | assert(Day21.part2(sample) == 301) 29 | } 30 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2022/Day22Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day22Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | " ...#", 8 | " .#..", 9 | " #...", 10 | " ....", 11 | "...#.......#", 12 | "........#...", 13 | "..#....#....", 14 | "..........#.", 15 | " ...#....", 16 | " .....#..", 17 | " .#......", 18 | " ......#.", 19 | "", 20 | "10R5L5R10L4R5L5") 21 | 22 | test("Part 1 should handle sample input correctly") { 23 | assert(Day22.part1(sample) == 6032) 24 | } 25 | 26 | test("Part 2 should handle sample input correctly") { 27 | assert(Day22.part2(sample, 4) == 5031) 28 | } 29 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2022/Day23Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day23Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "....#..", 8 | "..###.#", 9 | "#...#.#", 10 | ".#...##", 11 | "#.###..", 12 | "##.#.##", 13 | ".#..#..") 14 | 15 | test("Part 1 should handle sample input correctly") { 16 | assert(Day23.part1(sample) == 110) 17 | } 18 | 19 | test("Part 2 should handle sample input correctly") { 20 | assert(Day23.part2(sample) == 20) 21 | } 22 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2022/Day24Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day24Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "#.######", 8 | "#>>.<^<#", 9 | "#.<..<<#", 10 | "#>v.><>#", 11 | "#<^v^^>#", 12 | "######.#") 13 | 14 | test("Part 1 should handle sample input correctly") { 15 | assert(Day24.part1(sample) == 18) 16 | } 17 | 18 | test("Part 2 should handle sample input correctly") { 19 | assert(Day24.part2(sample) == 54) 20 | } 21 | -------------------------------------------------------------------------------- /src/test/scala/AdventOfCode2022/Day25Suite.scala: -------------------------------------------------------------------------------- 1 | package AdventOfCode2022 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day25Suite extends AnyFunSuite: 6 | val sample = Seq( 7 | "1=-0-2", 8 | "12111", 9 | "2=0=", 10 | "21", 11 | "2=01", 12 | "111", 13 | "20012", 14 | "112", 15 | "1=-1=", 16 | "1-12", 17 | "12", 18 | "1=", 19 | "122") 20 | 21 | test("Part 1 should handle sample input correctly") { 22 | assert(Day25.part1(sample) == "2=-1=0") 23 | } 24 | -------------------------------------------------------------------------------- /src/test/scala/template/Day00.scala: -------------------------------------------------------------------------------- 1 | package template 2 | 3 | object Day00: 4 | val sample = Seq() 5 | 6 | def part1(input: Seq[String]): Int = 123 7 | 8 | def part2(input: Seq[String]): Int = 456 9 | 10 | def main(args: Array[String]): Unit = 11 | part1(sample) 12 | // val data = io.Source.fromResource("AdventOfCode20xx/Day00.txt").getLines().toSeq 13 | // println(part1(data)) 14 | // println(part2(data)) 15 | -------------------------------------------------------------------------------- /src/test/scala/template/Day00Suite.scala: -------------------------------------------------------------------------------- 1 | package template 2 | 3 | import org.scalatest.funsuite.AnyFunSuite 4 | 5 | class Day00Suite extends AnyFunSuite: 6 | val sample = Seq() 7 | 8 | test("Part 1 should handle sample input correctly") { 9 | assert(Day00.part1(sample) == 123) 10 | } 11 | 12 | test("Part 2 should handle sample input correctly") { 13 | assert(Day00.part2(sample) == 456) 14 | } 15 | --------------------------------------------------------------------------------