Skip to content

Commit

Permalink
Day 25: Full of Hot Air
Browse files Browse the repository at this point in the history
  • Loading branch information
ephemient committed Dec 25, 2022
1 parent c4a55f9 commit 3705cc9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ Development occurs in language-specific directories:
|[Day22.hs](hs/src/Day22.hs)|[Day22.kt](kt/src/commonMain/kotlin/com/github/ephemient/aoc2022/Day22.kt)|[day22.py](py/aoc2022/day22.py)|[day22.rs](rs/src/day22.rs)|
|[Day23.hs](hs/src/Day23.hs)|[Day23.kt](kt/src/commonMain/kotlin/com/github/ephemient/aoc2022/Day23.kt)|[day23.py](py/aoc2022/day23.py)|[day23.rs](rs/src/day23.rs)|
|[Day24.hs](hs/src/Day24.hs)|[Day24.kt](kt/src/commonMain/kotlin/com/github/ephemient/aoc2022/Day24.kt)|[day24.py](py/aoc2022/day24.py)|[day24.rs](rs/src/day24.rs)|
|[Day25.hs](hs/src/Day25.hs)|
|[Day25.hs](hs/src/Day25.hs)|[Day25.kt](kt/src/commonMain/kotlin/com/github/ephemient/aoc2022/Day25.kt)|
25 changes: 25 additions & 0 deletions kt/src/commonMain/kotlin/com/github/ephemient/aoc2022/Day25.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.github.ephemient.aoc2022

@Day
class Day25(private val lines: List<String>) {
@Day.Part
fun part1(): String = buildString {
var n = lines.sumOf { line ->
line.fold(0L) { k, c ->
5 * k + when (c) {
'=' -> -2
'-' -> -1
else -> c.digitToInt()
}
}
}
while (n != 0L) {
n = n.floorDiv(5) + when (val d = n.mod(5)) {
3 -> 1.also { append('=') }
4 -> 1.also { append('-') }
else -> 0.also { append(d.digitToChar()) }
}
}
reverse()
}
}
11 changes: 11 additions & 0 deletions kt/src/commonTest/kotlin/com/github/ephemient/aoc2022/Day25Test.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.github.ephemient.aoc2022

import kotlin.test.Test
import kotlin.test.assertEquals

class Day25Test {
@Test
fun part1() {
assertEquals("2=-1=0", Day25(getTestInput(25)).part1())
}
}
13 changes: 13 additions & 0 deletions kt/src/jvmTest/resources/day25.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
1=-0-2
12111
2=0=
21
2=01
111
20012
112
1=-1=
1-12
12
1=
122

0 comments on commit 3705cc9

Please sign in to comment.