Skip to content

Commit

Permalink
2024 - Day 14 - parsing to robots.
Browse files Browse the repository at this point in the history
  • Loading branch information
fmmr committed Dec 14, 2024
1 parent cd76203 commit dd689c9
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/main/kotlin/no/rodland/advent_2024/Day14.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package no.rodland.advent_2024

import no.rodland.advent.Day
import no.rodland.advent.Pos

// template generated: 14/12/2024
// Fredrik Rødland 2024

class Day14(val input: List<String>) : Day<Long, Long, List<Day14.Robot>> {

private val robots = input.parse()

override fun partOne(): Long {
return 2
}

override fun partTwo(): Long {
return 2
}

override fun List<String>.parse(): List<Robot> {
return map { line ->
// p=0,4 v=3,-3
val (px, py) = line.substringAfter("p=").substringBefore(" v=").split(",").map { it.toInt() }
val (vx, vy) = line.substringAfter("v=").split(",").map { it.toInt() }
Robot(Pos(px, py), Pos(vx, vy))
}
}

data class Robot(val pos: Pos, val vel: Pos)

override val day = "14".toInt()
}
82 changes: 82 additions & 0 deletions src/test/kotlin/no/rodland/advent_2024/Day14Test.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package no.rodland.advent_2024

import no.rodland.advent.*
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import readFile

//
// run: download_aoc_input.sh to download input
//

@Suppress("ClassName")
@DisableSlow
internal class Day14Test {
private val data14 = "2024/input_14.txt".readFile()
private val test14 = "2024/input_14_test.txt".readFile()

private val resultTestOne = 2L
private val resultTestTwo = 2L
private val resultOne = 2L
private val resultTwo = 2L

val test = defaultTestSuiteParseOnInit(
Day14(data14),
Day14(test14),
resultTestOne,
resultOne,
resultTestTwo,
resultTwo,
{ Day14(data14) },
{ Day14(test14) },
)

@Nested
inner class Init {
@Test
fun `14,-,example,1`() {
report(AOCTest({ "123".toInt() }, Unit, 123, 5, "14".toInt(), Part.TWO, false, "example"))
}

@Test
fun `14,-,example,2`() {
report(test.initTest.copy())
}

@Test
fun `14,-,test,init`() {
report(test.initTest)
}

@Test
fun `14,-,live,init`() {
report(test.initLive)
}
}

@Nested
inner class `Part 1` {
@Test
fun `14,1,test`() {
report(test.testPart1)
}

@Test
fun `14,1,live,1`() {
report(test.livePart1)
}
}

@Nested
inner class `Part 2` {
@Test
fun `14,2,test`() {
report(test.testPart2)
}

@Test
fun `14,2,live,1`() {
report(test.livePart2)
}
}
}
12 changes: 12 additions & 0 deletions src/test/resources/2024/input_14_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
p=0,4 v=3,-3
p=6,3 v=-1,-3
p=10,3 v=-1,2
p=2,0 v=2,-1
p=0,0 v=1,3
p=3,0 v=-2,-2
p=7,6 v=-1,-3
p=3,0 v=-1,-2
p=9,3 v=2,3
p=7,3 v=-1,2
p=2,4 v=2,-3
p=9,5 v=-3,-3

0 comments on commit dd689c9

Please sign in to comment.