diff options
author | Nat Lasseter <user@4574.co.uk> | 2019-12-02 12:58:09 +0000 |
---|---|---|
committer | Nat Lasseter <user@4574.co.uk> | 2019-12-02 12:58:09 +0000 |
commit | 423d2bcb74df7290d2d7e8d3d4aaea278cd1e98b (patch) | |
tree | b459d4fb4f3bc622c661d512f9825702c7aaf2f1 /day02/part1 | |
parent | b1692f98b614e731cd42fc770dff77e2f3c136ff (diff) |
Day 02, though it's not going to sclae whell when we add more instructions!
Diffstat (limited to 'day02/part1')
-rwxr-xr-x | day02/part1 | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/day02/part1 b/day02/part1 new file mode 100755 index 0000000..460b3b5 --- /dev/null +++ b/day02/part1 @@ -0,0 +1,28 @@ +#!/usr/bin/env ruby + +$input = $stdin.readlines[0].strip.split(",").map(&:to_i) +$pc = 0 + +def handle_code + case $input[$pc] + when 1 + $input[$input[$pc+3]] = $input[$input[$pc+1]] + $input[$input[$pc+2]] + return true + when 2 + $input[$input[$pc+3]] = $input[$input[$pc+1]] * $input[$input[$pc+2]] + return true + when 99 + return false + end +end + +$input[1] = 12 +$input[2] = 2 + +loop do + continue = handle_code + break unless continue + $pc += 4 +end + +puts $input[0] |