aboutsummaryrefslogtreecommitdiff
path: root/day08/part1
diff options
context:
space:
mode:
authorNat Lasseter <Nat Lasseter nathan@bytemark.co.uk>2017-12-08 17:18:19 +0000
committerNat Lasseter <Nat Lasseter nathan@bytemark.co.uk>2017-12-08 17:18:19 +0000
commit4a22c4e119c6cad69bdf7687d509f69e391f33c0 (patch)
tree2576e85959ad7c95ea34c49e101ea06f14508181 /day08/part1
parent546c50a3d17551aeee259c122b02bfd68673277a (diff)
Day 08
Diffstat (limited to 'day08/part1')
-rwxr-xr-xday08/part133
1 files changed, 33 insertions, 0 deletions
diff --git a/day08/part1 b/day08/part1
new file mode 100755
index 0000000..167e761
--- /dev/null
+++ b/day08/part1
@@ -0,0 +1,33 @@
+#!/usr/bin/env ruby
+
+input = $stdin.readlines.map(&:chomp)
+h = {}
+
+input.each do |line|
+ cmd, cond = line.split(' if ')
+
+ cmda = cmd.split
+ reg = cmda[0]
+ h[reg] = 0 if h[reg].nil?
+ chg = (cmda[1] == 'inc' ? cmda[2].to_i : -cmda[2].to_i)
+
+ conda = cond.split
+ h[conda[0]] = 0 if h[conda[0]].nil?
+ go = case conda[1]
+ when '<'
+ h[conda[0]] < conda[2].to_i
+ when '<='
+ h[conda[0]] <= conda[2].to_i
+ when '=='
+ h[conda[0]] == conda[2].to_i
+ when '>='
+ h[conda[0]] >= conda[2].to_i
+ when '>'
+ h[conda[0]] > conda[2].to_i
+ when '!='
+ h[conda[0]] != conda[2].to_i
+ end
+ h[reg] += chg if go
+end
+
+puts h.to_a.map(&:last).max