Skip to content

Commit

Permalink
2023 - Day 15 - part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
fmmr committed Dec 15, 2023
1 parent f03047b commit 61eb2db
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/main/kotlin/no/rodland/advent_2023/Day15.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package no.rodland.advent_2023

import no.rodland.advent.Day

// template generated: 15/12/2023
// Fredrik Rødland 2023

class Day15(val input: List<String>) : Day<Int, Long, List<CharArray>> {

private val parsed = input.parse()

override fun partOne(): Int {
return parsed.sumOf { it.hash() }
}

private fun CharArray.hash() = fold(0) { acc, c -> ((c.code + acc) * 17).mod(256) }

override fun partTwo(): Long {
return 2
}

override fun List<String>.parse(): List<CharArray> {
return first().split(",").map { it.toCharArray() }
}

override val day = "15".toInt()
}

82 changes: 82 additions & 0 deletions src/test/kotlin/no/rodland/advent_2023/Day15Test.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package no.rodland.advent_2023

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 Day15Test {
private val data15 = "2023/input_15.txt".readFile()
private val test15 = "2023/input_15_test.txt".readFile()

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

val test = defaultTestSuiteParseOnInit(
Day15(data15),
Day15(test15),
resultTestOne,
resultOne,
resultTestTwo,
resultTwo,
{ Day15(data15) },
{ Day15(test15) },
)

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

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

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

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

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

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

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

@Test
fun `15,2,live,1`() {
report(test.livePart2)
}
}
}
Loading

0 comments on commit 61eb2db

Please sign in to comment.