Skip to content

Commit

Permalink
2024 Day 03 Part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
fmmr committed Dec 3, 2024
1 parent 572db16 commit d26212b
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/main/kotlin/no/rodland/advent_2024/Day03.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package no.rodland.advent_2024

import no.rodland.advent.Day

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

class Day03(val input: List<String>) : Day<Long, Long, List<Pair<Int, Int>>> {
private val multRegEx = "mul\\((\\d{1,3}),(\\d{1,3})\\)".toRegex()

private val parsed = input.parse()

override fun partOne(): Long {
return parsed.sumOf { (a, b) -> a * b }.toLong()
}

override fun partTwo(): Long {
return 2
}

override fun List<String>.parse(): List<Pair<Int, Int>> {
return flatMap { line ->
multRegEx.findAll(line).toList().map { mr ->
mr.groupValues[1].toInt() to mr.groupValues[2].toInt()
}
}
}

override val day = "03".toInt()
}
5 changes: 4 additions & 1 deletion src/main/script/download_aoc_input.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ git add "src/test/resources/${YEAR}/input_${DAY}_test.txt"
git commit -a -m "${YEAR} - Day ${DAY} - input/init"
cd - || exit

tail -10 "$PUZZLE_FILE"
tail -10 "$PUZZLE_FILE"
echo
echo "TEST-FILE: $PUZZLE_FILE_TEST"
echo "FILE: $PUZZLE_FILE"
82 changes: 82 additions & 0 deletions src/test/kotlin/no/rodland/advent_2024/Day03Test.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 Day03Test {
private val data03 = "2024/input_03.txt".readFile()
private val test03 = "2024/input_03_test.txt".readFile()

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

val test = defaultTestSuiteParseOnInit(
Day03(data03),
Day03(test03),
resultTestOne,
resultOne,
resultTestTwo,
resultTwo,
{ Day03(data03) },
{ Day03(test03) },
)

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

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

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

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

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

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

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

@Test
fun `03,2,live,1`() {
report(test.livePart2)
}
}
}
1 change: 1 addition & 0 deletions src/test/resources/2024/input_03_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))

0 comments on commit d26212b

Please sign in to comment.