Skip to content

Commit

Permalink
2023 - Day06 - part 2 brute force (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmmr committed Dec 6, 2023
1 parent 465b552 commit 5e42dba
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/main/kotlin/no/rodland/advent_2023/Day06.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package no.rodland.advent_2023

import no.rodland.advent.Day
import product

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

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

override fun List<String>.parse(): List<Pair<Int, Int>> {
TODO("Not yet implemented")
}

override fun partOne(): Long {
return input.map { line ->
(0..line.first).count { push(it.toLong(), line.first.toLong()) > line.second }.toLong()
}.product()
}

override fun partTwo(): Long {
val test = input.first() == (7 to 9)
return if (test) {
val line = 71530L to 940200L
(0..line.first).count { push(it, line.first) > line.second }.toLong()

} else {
val line = 48938466L to 261119210191063L
(0..line.first).count { push(it, line.first) > line.second }.toLong()

}
}

private fun push(pushButton: Long, maxLength: Long): Long {
return pushButton * (maxLength - pushButton)
}

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

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

import no.rodland.advent.DisableSlow
import no.rodland.advent.defaultTestSuiteParseOnInit
import no.rodland.advent.report
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test

@Suppress("ClassName")
@DisableSlow
internal class Day06Test {
private val data06 = listOf(
48 to 261,
93 to 1192,
84 to 1019,
66 to 1063,
)
private val test06 = listOf(
7 to 9,
15 to 40,
30 to 200,
)

private val resultTestOne = 288L
private val resultTestTwo = 71503L
private val resultOne = 1312850L
private val resultTwo = 36749103L

val test = defaultTestSuiteParseOnInit(
Day06(data06),
Day06(test06),
resultTestOne,
resultOne,
resultTestTwo,
resultTwo,
{ Day06(data06) },
{ Day06(test06) },
numTestPart2 = 1
)

@Nested
inner class Init {
@Test
fun `06,-,test,init`() {
report(test.initTest)
}

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

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

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

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

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

0 comments on commit 5e42dba

Please sign in to comment.