Print some debug stuff
This commit is contained in:
parent
4633a84ae1
commit
3a8e1ba1a9
1 changed files with 13 additions and 2 deletions
15
17/main.rb
15
17/main.rb
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require "debug"
|
||||
DEBUG = true
|
||||
|
||||
input = (ARGV.first.nil? ? DATA : ARGF)
|
||||
.readlines(chomp: true)
|
||||
|
@ -28,7 +29,7 @@ OPERANDS = [
|
|||
]
|
||||
|
||||
def execute(registers, program)
|
||||
stdout = []
|
||||
stdout, commands = Array.new, Array.new
|
||||
|
||||
i = 0
|
||||
while i < program.size
|
||||
|
@ -43,31 +44,41 @@ def execute(registers, program)
|
|||
numerator = registers[:A]
|
||||
denominator = 2 ** combo_operand
|
||||
registers[:A] = numerator / denominator
|
||||
commands << [:adv, numerator, denominator]
|
||||
when 1
|
||||
registers[:B] = registers[:B] ^ literal_operand
|
||||
commands << [:bxl, literal_operand]
|
||||
when 2
|
||||
registers[:B] = combo_operand % 8
|
||||
commands << [:bst, combo_operand % 8]
|
||||
when 3
|
||||
if registers[:A] == 0
|
||||
:noop
|
||||
commands << [:noop]
|
||||
else
|
||||
i = literal_operand
|
||||
commands << [:jnz, literal_operand]
|
||||
end
|
||||
when 4
|
||||
registers[:B] = registers[:B] ^ registers[:C]
|
||||
commands << [:bxc, registers[:B], registers[:C]]
|
||||
when 5
|
||||
stdout << combo_operand % 8
|
||||
commands << [:out, combo_operand % 8]
|
||||
when 6
|
||||
numerator = registers[:A]
|
||||
denominator = 2 ** combo_operand
|
||||
registers[:B] = numerator / denominator
|
||||
commands << [:bdv, numerator, denominator]
|
||||
when 7
|
||||
numerator = registers[:A]
|
||||
denominator = 2 ** combo_operand
|
||||
registers[:C] = numerator / denominator
|
||||
commands << [:cdv, numerator, denominator]
|
||||
end
|
||||
end
|
||||
|
||||
p commands if DEBUG
|
||||
|
||||
[registers, program, stdout.join(",")]
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue