Skip to content

Commit

Permalink
2024 - Day 11 - reformatted - both part1 & part2 now calls solve(iter…
Browse files Browse the repository at this point in the history
…ations)
  • Loading branch information
fmmr committed Dec 11, 2024
1 parent 2477c5d commit b77135e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/main/kotlin/no/rodland/advent_2024/Day11.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ import no.rodland.advent.Day
// Fredrik Rødland 2024

class Day11(val input: List<String>) : Day<Long, Long, List<Long>> {

private val parsed = input.parse()

override fun partOne(): Long {
val memoization = mutableMapOf<Pair<Long, Int>, Long>()
return parsed.map { it.numberStones(25, memoization) }.sumOf { it }
return solve(25)
}

override fun partTwo(): Long {
return solve(75)
}

private fun solve(iterations: Int): Long {
val memoization = mutableMapOf<Pair<Long, Int>, Long>()
return parsed.map { it.numberStones(75, memoization) }.sumOf { it }
return parsed.map { it.numberStones(iterations, memoization) }.sumOf { it }
}

private fun Long.numberStones(i: Int, memoization: MutableMap<Pair<Long, Int>, Long>): Long {
Expand Down

0 comments on commit b77135e

Please sign in to comment.