diff --git a/Day11.scala b/Day11.scala new file mode 100644 index 0000000..749ec87 --- /dev/null +++ b/Day11.scala @@ -0,0 +1,34 @@ +package aoc.day11 + +import aoc._ +import scala.annotation.tailrec + +val board = lines.toSeq + +// part 1 + +val countByRow = board.map(_.count(_ == '#')).toList +val countByCol = (0 until board(0).length()).map(col => board.count(row => row(col) == '#')).toList + +@tailrec def totalDist(expandBy: Int)(count: Long, leftDist: Long, accum: Long)(counts: List[Int]): Long = + counts match + case Nil => accum + case 0 :: next => totalDist(expandBy)(count, leftDist + expandBy * count /* expanded case */, accum)(next) + case cur :: next => + totalDist(expandBy)(count + cur, leftDist + count + cur, accum + cur * leftDist)(next) + +def totalDist(expandBy: Int)(counts: List[Int]): Long = totalDist(expandBy)(0, 0, 0)(counts) + +def part1 = + inline def count(r: List[Int]): Long = totalDist(2)(r) + val res = count(countByRow) + count(countByCol) + println(res) + +def part2 = + inline def count(r: List[Int]): Long = totalDist(1_000_000)(r) + val res = count(countByRow) + count(countByCol) + println(res) + +@main def Day11(part: Int) = part match + case 1 => part1 + case 2 => part2 diff --git a/inputs/day11.input b/inputs/day11.input new file mode 100644 index 0000000..c8ea1d6 --- /dev/null +++ b/inputs/day11.input @@ -0,0 +1,140 @@ +........................#...............................................#................................#................................#. +....#..............#......................#............#....................................................................#............... +................................#.............................................................#............................................. +.........#.....................................#...................#........................................................................ +....................................................#.......................#..............................#................................ +..#................................................................................................#................#......................# +.........................................................#.........................#.....#.................................................. +..................................#.............................#...............................................#.............#............. +.......#.....#...........................#..............................................................#.............................#..... +......................#...............................#................................................................#.................... +............................#.................#........................#.....................................#.............................. +....#.................................#...............................................#..................................................... +...............#...........................................................#............................................................#... +..................................#...........................................................#...................#...........#............. +....................................................................................................................................#....... +................................................................#................#..........................#............................... +...#..............#........#.........#.............#........................................................................................ +.........................................................#.............#.............#..............#...................#................... +........#................................................................................................................................... +..............................................................................................#.................................#........#.. +....................#.......................................#.....................................................#......................... +#..............................#.......#......#...................................#......#.................................................. +...........#.......................................#......................................................................#................. +.......................................................................................................................................#.... +............................................................................................................................................ +.........................#...................................#...............................#.............................................. +..................................#.......................................................................#.............#................... +.........................................#...........................#...............................#.........#..........................#. +............#......#............................................#...............................#...................................#....... +.............................#.....................................................#........................................................ +....#........................................#...............................#.................................................#............ +......................#............................#.....#.........#........................................................................ +.........................................................................................................#.................................. +.......#........................#................................................#.......................................................... +...............................................#..........................#................#..........................................#..... +.#................#.............................................................................................#......#.................... +..............................................................................................................................#............. +..........................#........................#.............................................#.......................................... +.............#..........................#............................................#..............................#....................... +........#..............................................#.....................#..........................#..................#................ +............................................................#.....#..................................................................#...... +....................#.........................#..........................#..................#...................#........................... +..............................#...................................................#................#........................................ +.........................................#..............................................#..................................................# +.#........#.........................................#.....................................................#.....................#........... +.........................................................#.........................................................#........................ +......#...........................#......................................................................................................... +................................................#........................................................................................#.. +...................................................................#...............#........................................................ +.....................#................................#..............................................................................#...... +...........#................................................................................#.....#......................................... +....#........................#............................................#..............................................#.................. +................#.......#........................................................#........................................................#. +#...................................................................................................................#....................... +....................#...................#..............#.................................#...................#.............................. +.............#....................#.................................................#..................#...................#................ +.................................................................................................................#.....................#.... +................................................................................#........................................................... +.......................#.............#....................#................................................................................. +.......#.............................................................................................#..............#....................... +...................#.....................................................................................................................#.. +......................................................#..................#.......................................................#.......... +..........................#..................................................................#.............................................. +............#.................................#.........................................#...................#............#.................. +.....................#......................................#......................................................#..........#............. +.#.........................................................................#......#...................#..................................... +............................................................................................................................................ +................................#...........................................................#............................................... +........................................#..........................#..................................................#.................#... +....#........................................#.....................................................#.............................#.......... +..........................................................#................................................................................. +...............#............................................................................................................................ +..........#............#............................#.............................#...........................................#......#...... +....................................#........................................................#...............#.............................. +...........................................#..............................#...............................................................#. +.#...........................#.......................................................................#...................................... +.........................................................#...........#....................................#................................. +......#.......#...................#...........................#.......................#.........#..................#........................ +............................................................................#.........................................................#..... +.....................#.........................................................................................#........#................... +..........................#.............................................#................#........................................#......... +............................................................................................................................................ +....#.....#.....#..................................#.........#.....................#....................#................................... +........................................#.....................................................................................#............. +...............................................................................................#............................................ +.......#........................#...........................................#............................................................#.. +....................#......#....................#........................................................................................... +.........................................................#...........#..........#.............................#...........#................. +......................................................................................#..................................................... +....................................................................................................#................#..........#.....#..... +............#.........#.....................#...............#..............................................#................................ +.......#............................#....................................................................................................... +.......................................................................#......................#................#...................#........ +............................................................................................................................................ +........................................................................................................................#................... +..........#..........#.......................#.........................................................................................#.... +...................................................................#.................#...........#.......................................... +........................................#................#.................................................................................. +................#....................................................................................................#...................... +............................................................................................................................................ +.......#....................#.................................................................#...............#.........................#... +.................................#...........#.....#...........................................................................#............ +...........#.......................................................#....................#................................................... +........................................#...............................................................................#................... +............................................................................................................................................ +.....................................................................................................#...................................... +................#.........................................#..................#................................................#.......#..... +....#................................#.............#...................................#.....................#.......#...................... +.........................#......................................#........................................................................... +...........................................................................................#.......#........................................ +..........#.....................#..............#........................#................................................................... +..#......................................................................................................................................... +....................#.....................................#.......................#......................................................... +..........................#.............#...............................................................................#.........#......... +......................................................................................#..................................................... +.....................................................................#..........................#........................................... +.......#.........#...........................................................#.......................#........#............#............#... +........................#....................................#.............................................................................. +.......................................#............................................#....................#.........................#........ +..............................................#....................................................................#........................ +..............#..................#.....................................#..........................#......................................... +..........................................#..........#..........................#........................................................... +.....#......................................................................................#................#.............................. +.....................#................................................................#.......................................#............. +.....................................................................#...................................................................... +...........#.....#............................#.....................................................................................#....... +................................#.....#..........................#........#..........................................#....................#. +...........................#.................................................................#........#.......#............................. +#........................................................................................................................................... +........#........................................#...................................#...................................................... +.............................................................................................................................#.............. +.................................#..............................#........................#.........#........#............................... +............#.....#..........................#.......................#....................................................................#. +........................#........................................................#.......................................................... +............................................................#..............#......................................#......................... +...#........................................................................................#............................................... +...........................................................................................................#......................#......... +..........#.......................................................................................#......................................... +......................#................#............................................#.................................................#..... +...........................#.....................#........#...................................................#.............................