diff --git a/src/main/kotlin/no/rodland/advent_2024/Day13.kt b/src/main/kotlin/no/rodland/advent_2024/Day13.kt index b4466d6..0395495 100644 --- a/src/main/kotlin/no/rodland/advent_2024/Day13.kt +++ b/src/main/kotlin/no/rodland/advent_2024/Day13.kt @@ -19,8 +19,22 @@ class Day13(val input: List) : Day> { } data class Machine(val a: P, val b: P, val p: P) { - val cb = (p.y * a.x - p.x * a.y) / (a.x * b.y - a.y * b.x) - val ca = (p.x - cb * b.x) / a.x + // Button A: X+94, Y+34 + // Button B: X+22, Y+67 + // Prize: X=8400, Y=5400 + + // 1: a.x*ca + b.x*cb = p.x + // 2: a.y*ca + b.y*cb = p.y + + // 1: ca = (p.x - b.x*cb) / a.x + // 2+1: a.y*((p.x - b.x*cb) / a.x) + b.y*cb = p.y + // b.y*cb - a.y/a.x * b.x*cb = p.y - a.y/a.x * p.x + // cb * (b.y - a.y/a.x * b.x) = p.y - a.y/a.x * p.x + // cb = (p.y - a.y/a.x * p.x) / (b.y - a.y/a.x * b.x) + // cb = (a.x * p.y - a.y * p.x) / (a.x * b.y - a.y * b.x) + + val cb = (a.x * p.y - a.y * p.x) / (a.x * b.y - a.y * b.x) + val ca = (p.x - b.x * cb) / a.x val ok = (cb * b.x + ca * a.x == p.x) && (cb * b.y + ca * a.y == p.y) }