-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2023 - Day06 - part 2 brute force (again)
- Loading branch information
Showing
2 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |