Skip to content

Commit e09e617

Browse files
committed
2024/day 13 - part 2
1 parent 48927c4 commit e09e617

File tree

1 file changed

+0
-26
lines changed
  • src/main/kotlin/me/underlow/advent2024

1 file changed

+0
-26
lines changed

src/main/kotlin/me/underlow/advent2024/Day13.kt

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,9 @@ package me.underlow.advent2024
22

33
import me.underlow.advent2022.checkResult
44
import me.underlow.advent2022.readInput
5-
import kotlin.math.max
65

76
object ClawContraption {
87
data class ClawMachine(val xA: Int, val yA: Int, val xB: Int, val yB: Int, val xPrice: Long, val yPrice: Long) {
9-
fun calc(): Long {
10-
val presses = mutableListOf<Pair<Long, Long>>()
11-
12-
13-
val maxAPresses = max(xPrice / xA, yPrice / yA)
14-
val maxBPresses = max(xPrice / xB, yPrice / yB)
15-
for (a in 0 until maxAPresses) {
16-
for (b in 0 until maxBPresses) {
17-
if (a * xA + b * xB == xPrice && a * yA + b * yB == yPrice) {
18-
presses += a to b
19-
}
20-
}
21-
}
22-
23-
if (presses.isEmpty())
24-
return 0
25-
26-
return presses.map { aButton * it.first + bButton * it.second }.min()
27-
}
288

299
fun calc2(): Long {
3010
val a1 = xA
@@ -37,10 +17,6 @@ object ClawContraption {
3717
val y = (c2 * a1 - c1 * a2) / (b2 * a1 - b1 * a2)
3818
val x = (c1 - b1 * y) / a1
3919

40-
41-
// val y = (yPrice * xA - xPrice * xB) / (yB * xA - xB * yA)
42-
// val x = (xPrice - xB * y) / xA
43-
4420
if (x * xA + y * xB == xPrice && y * yB + x * yA == yPrice) {
4521
return x * aButton + y
4622
}
@@ -56,7 +32,6 @@ object ClawContraption {
5632
fun part1(list: List<String>): Long {
5733
val clawMachines = parseInput(list)
5834

59-
// brute force
6035
val calc = clawMachines.map { it.calc2() }
6136

6237
return calc.sum()
@@ -67,7 +42,6 @@ object ClawContraption {
6742
it.copy(xPrice = it.xPrice + 10000000000000, yPrice = it.yPrice + 10000000000000)
6843
}
6944

70-
// brute force
7145
val calc = clawMachines.map { it.calc2() }
7246

7347
return calc.sum()

0 commit comments

Comments
 (0)