Skip to content

Commit

Permalink
2024 Day 05 Parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
fmmr committed Dec 5, 2024
1 parent adf62b7 commit 193cf5d
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/main/kotlin/no/rodland/advent_2024/Day05.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package no.rodland.advent_2024

import no.rodland.advent.Day

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

class Day05(val input: List<String>) : Day<Long, Long, Pair<List<Pair<Int, Int>>, List<List<Int>>>> {

private val parsed = input.parse()
private val rules = parsed.first
private val pages = parsed.second

override fun partOne(): Long {
return 2
}

override fun partTwo(): Long {
return 2
}

override fun List<String>.parse(): Pair<List<Pair<Int, Int>>, List<List<Int>>> {
val (rulesStr, pagesStr) = this.joinToString("\n").split("\n\n").map { it.split("\n") }

val pages = pagesStr.map { line ->
line.split(",").map { it.toInt() }
}
val rules = rulesStr.map { line ->
val (first, second) = line.split("|").map { it.toInt() }
first to second
}
return rules to pages
}

override val day = "05".toInt()
}
82 changes: 82 additions & 0 deletions src/test/kotlin/no/rodland/advent_2024/Day05Test.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 Day05Test {
private val data05 = "2024/input_05.txt".readFile()
private val test05 = "2024/input_05_test.txt".readFile()

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

val test = defaultTestSuiteParseOnInit(
Day05(data05),
Day05(test05),
resultTestOne,
resultOne,
resultTestTwo,
resultTwo,
{ Day05(data05) },
{ Day05(test05) },
)

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

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

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

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

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

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

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

@Test
fun `05,2,live,1`() {
report(test.livePart2)
}
}
}
28 changes: 28 additions & 0 deletions src/test/resources/2024/input_05_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
47|53
97|13
97|61
97|47
75|29
61|13
75|53
29|13
97|29
53|29
61|53
97|53
61|29
47|13
75|47
97|75
47|61
75|61
47|29
75|13
53|13

75,47,61,53,29
97,61,53,29,13
75,29,13
75,97,47,61,53
61,13,29
97,13,75,29,47

0 comments on commit 193cf5d

Please sign in to comment.