aboutsummaryrefslogtreecommitdiff
path: root/day09
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2019-12-11 21:53:12 +0000
committerNat Lasseter <user@4574.co.uk>2019-12-11 21:53:12 +0000
commit693130cae9bdb145af79ee2eb256b661003b6e45 (patch)
treefc4a450b012545c0f5599c667426d44451fbf71d /day09
parent3bea5ec1373b842e6ad9f7cff050615e1f5ebde8 (diff)
Wrote Intcode (dis-)assembler
Diffstat (limited to 'day09')
-rwxr-xr-xday09/das73
1 files changed, 0 insertions, 73 deletions
diff --git a/day09/das b/day09/das
deleted file mode 100755
index 9b1eecf..0000000
--- a/day09/das
+++ /dev/null
@@ -1,73 +0,0 @@
-#!/usr/bin/env ruby
-
-class Program
- def initialize(program)
- @mem = program
- @pc = 0
- end
-
- def dis_next
- opcode = @mem[@pc] % 100
-
- p3, p2, p1 = ("%03d" % (@mem[@pc] / 100)).chars
-
- print "#{@pc}: "
- case opcode
- when 1
- puts "add #{Program.sigil(p1)}#{@mem[@pc+1]} #{Program.sigil(p2)}#{@mem[@pc+2]} #{Program.sigil(p3)}#{@mem[@pc+3]}"
- @pc += 4
- when 2
- puts "mul #{Program.sigil(p1)}#{@mem[@pc+1]} #{Program.sigil(p2)}#{@mem[@pc+2]} #{Program.sigil(p3)}#{@mem[@pc+3]}"
- @pc += 4
- when 3
- puts "in #{Program.sigil(p1)}#{@mem[@pc+1]}"
- @pc += 2
- when 4
- puts "out #{Program.sigil(p1)}#{@mem[@pc+1]}"
- @pc += 2
- when 5
- puts "jnz #{Program.sigil(p1)}#{@mem[@pc+1]} #{Program.sigil(p2)}#{@mem[@pc+2]}"
- @pc += 3
- when 6
- puts "jez #{Program.sigil(p1)}#{@mem[@pc+1]} #{Program.sigil(p2)}#{@mem[@pc+2]}"
- @pc += 3
- when 7
- puts "tlt #{Program.sigil(p1)}#{@mem[@pc+1]} #{Program.sigil(p2)}#{@mem[@pc+2]} #{Program.sigil(p3)}#{@mem[@pc+3]}"
- @pc += 4
- when 8
- puts "teq #{Program.sigil(p1)}#{@mem[@pc+1]} #{Program.sigil(p2)}#{@mem[@pc+2]} #{Program.sigil(p3)}#{@mem[@pc+3]}"
- @pc += 4
- when 9
- puts "arb #{Program.sigil(p1)}#{@mem[@pc+1]}"
- @pc += 2
- when 99
- puts "hlt"
- @pc += 1
- else
- puts "dat #{@mem[@pc]}"
- @pc += 1
- end
- end
-
- def dis_all
- until @pc >= @mem.length do
- dis_next
- end
- end
-
- private
-
- def self.sigil(p)
- case p
- when "0"
- "@"
- when "2"
- "&"
- end
- end
-end
-
-input = $stdin.readlines[0].strip.split(",").map(&:to_i)
-
-p = Program.new(input)
-p.dis_all