From 1a303d9632beda382f4841b67d6765b83f464344 Mon Sep 17 00:00:00 2001 From: chrisly42 Date: Wed, 25 Dec 2024 06:47:45 +0100 Subject: [PATCH] Day 25. --- src/aoc2024/Day25.kt | 91 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/aoc2024/Day25.kt diff --git a/src/aoc2024/Day25.kt b/src/aoc2024/Day25.kt new file mode 100644 index 0000000..0dd3955 --- /dev/null +++ b/src/aoc2024/Day25.kt @@ -0,0 +1,91 @@ +package aoc2024 + +import CharGrid +import println +import readInput + +/* +--- Day 25: Code Chronicle --- +https://adventofcode.com/2024/day/25 +*/ +fun main() { + + val inlineTestInput = """ +##### +.#### +.#### +.#### +.#.#. +.#... +..... + +##### +##.## +.#.## +...## +...#. +...#. +..... + +..... +#.... +#.... +#...# +#.#.# +#.### +##### + +..... +..... +#.#.. +###.. +###.# +###.# +##### + +..... +..... +..... +#.... +#.#.. +#.#.# +##### +""" + + fun part1(input: List): Int { + var p = 0 + val topRow = IntRange(0, 4) + val locks = ArrayList() + val keys = ArrayList() + while (p < input.size) { + val grid = CharGrid(input.subList(p, p + 7)) + if (topRow.all { grid[it, 0] == '#' }) { + val lock = topRow.map { rc -> (topRow.find { grid[rc, it + 1] != '#' } ?: 5) }.toIntArray() + locks.add(lock) + } else { + val key = topRow.map { rc -> 5 - (topRow.find { grid[rc, 5 - it] != '#' } ?: 5) }.toIntArray() + keys.add(key) + } + p += 8 + } + return locks.sumOf { lock -> keys.count { key -> key.zip(lock).all { it.first >= it.second } } } + } + + fun part2(input: List): Int { + return 0 + } + + // test if implementation meets criteria from the description, like: + val testInput = inlineTestInput.trim().reader().readLines() + //val testInput = readInput("aoc2024/Day25_test") + val testInputPart1Result = part1(testInput) + println("Part 1 Test: $testInputPart1Result") + val testInputPart2Result = part2(testInput) + println("Part 2 Test: $testInputPart2Result") + check(testInputPart1Result == 3) + check(testInputPart2Result == 0) + + val input = readInput("aoc2024/Day25") + part1(input).println() + part2(input).println() +}