Skip to content

Commit

Permalink
✨ day 25
Browse files Browse the repository at this point in the history
  • Loading branch information
twentylemon committed Dec 25, 2024
1 parent 8688066 commit 2c5d1f3
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
Binary file added src/main/resources/year2024/day25.txt
Binary file not shown.
18 changes: 18 additions & 0 deletions src/main/scala/org/lemon/advent/year2024/Day25.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.lemon.advent.year2024

import org.lemon.advent.lib._
import org.lemon.advent.lib.`2d`._

private object Day25:

def parse(input: String) =
import org.lemon.advent.lib.parse.{given, _}
input match
case Chunk(areas @ _*) => areas.map(Coord.gridToMap)

def part1(input: String) =
val grids = parse(input)
val locks = grids.filter(_(Coord(0, 0)) == '#')
val keys = grids.filterNot(_(Coord(0, 0)) == '#')
locks.cartesianProduct(keys)
.count((lock, key) => lock.forall((coord, cell) => cell != '#' || key(coord) != '#'))
53 changes: 53 additions & 0 deletions src/test/scala/org/lemon/advent/year2024/Day25Test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.lemon.advent.year2024

import org.lemon.advent._
import org.lemon.advent.year2024.Day25._

class Day25Test extends UnitTest:

test("part 1 example") {
val in = """|#####
|.####
|.####
|.####
|.#.#.
|.#...
|.....
|
|#####
|##.##
|.#.##
|...##
|...#.
|...#.
|.....
|
|.....
|#....
|#....
|#...#
|#.#.#
|#.###
|#####
|
|.....
|.....
|#.#..
|###..
|###.#
|###.#
|#####
|
|.....
|.....
|.....
|#....
|#.#..
|#.#.#
|#####""".stripMargin
part1(in) shouldBe 3
}

test("part 1") {
part1(read(file(2024)(25))) shouldBe 2900
}

0 comments on commit 2c5d1f3

Please sign in to comment.