Day 17 part 1

This commit is contained in:
Sven Weidauer 2024-12-25 12:03:20 +01:00
parent 5c47d18647
commit 598e8bd639

View file

@ -6,8 +6,14 @@ Register C: 0
Program: 2,4,1,3,7,5,1,5,0,3,4,1,5,5,3,0 Program: 2,4,1,3,7,5,1,5,0,3,4,1,5,5,3,0
*/ */
class Computer(var a: Int = 0, var b: Int = 0, var c: Int = 0, var ip: Int = 0, val memory: List<Int>) { class Computer(
val output = mutableListOf<Int>() var a: Int = 0,
var b: Int = 0,
var c: Int = 0,
private var ip: Int = 0,
val memory: List<Int>
) {
private val output = mutableListOf<Int>()
fun run(): List<Int> { fun run(): List<Int> {
ip = 0 ip = 0
@ -21,6 +27,7 @@ class Computer(var a: Int = 0, var b: Int = 0, var c: Int = 0, var ip: Int = 0,
3 -> if (a != 0) { 3 -> if (a != 0) {
ip = literalOperand() - 2 ip = literalOperand() - 2
} }
4 -> b = b xor c 4 -> b = b xor c
5 -> output.add(comboOperand() and 7) 5 -> output.add(comboOperand() and 7)
6 -> b = a / (1 shl comboOperand()) 6 -> b = a / (1 shl comboOperand())