1
0
Fork 0

part 1 working and prep part 2

This commit is contained in:
Andrew Tomaka 2024-12-17 01:25:41 -05:00
parent 19147d460c
commit 4633a84ae1
Signed by: atomaka
GPG key ID: 61209BF70A5B18BE

View file

@ -27,10 +27,11 @@ OPERANDS = [
->() { :noop },
]
stdout = []
def execute(registers, program)
stdout = []
i = 0
while i < program.size
i = 0
while i < program.size
opcode = program[i]
literal_operand = program[i+1]
combo_operand = OPERANDS[literal_operand].call
@ -65,15 +66,24 @@ while i < program.size
denominator = 2 ** combo_operand
registers[:C] = numerator / denominator
end
end
[registers, program, stdout.join(",")]
end
p registers
original_registers = registers.dup
_, _, part_1 = execute(registers, program)
p part_1
puts stdout.join(",")
registers = original_registers.dup
_, _, part_2 = execute(registers, program)
p program.join(",")
p part_2
p part_2 == program.join(",") ? "Correct!" : "Not correct!"
__END__
Register A: 729
Register A: 2024
Register B: 0
Register C: 0
Program: 0,1,5,4,3,0
Program: 0,3,5,4,3,0