From 423d2bcb74df7290d2d7e8d3d4aaea278cd1e98b Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Mon, 2 Dec 2019 12:58:09 +0000 Subject: Day 02, though it's not going to sclae whell when we add more instructions! --- day02/part2 | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 day02/part2 (limited to 'day02/part2') diff --git a/day02/part2 b/day02/part2 new file mode 100755 index 0000000..aadb860 --- /dev/null +++ b/day02/part2 @@ -0,0 +1,43 @@ +#!/usr/bin/env ruby + +Input = $stdin.readlines[0].strip.split(",").map(&:to_i) + +noun = 0 +verb = 0 + +loop do + $input = Input.dup + $input[1] = noun + $input[2] = verb + + $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 + + loop do + continue = handle_code + break unless continue + $pc += 4 + end + + break if $input[0] == 19690720 + + verb += 1 + if verb == 100 + verb = 0 + noun += 1 + end +end + +puts (100 * noun) + verb -- cgit v1.2.3