aboutsummaryrefslogtreecommitdiff
path: root/day23/part2
diff options
context:
space:
mode:
Diffstat (limited to 'day23/part2')
-rwxr-xr-xday23/part239
1 files changed, 9 insertions, 30 deletions
diff --git a/day23/part2 b/day23/part2
index b00d666..634d447 100755
--- a/day23/part2
+++ b/day23/part2
@@ -1,34 +1,13 @@
-#!/usr/bin/env ruby
+#!/bin/bash
-def valof(reg_file, reg_or_int)
- if reg_or_int >= 'a' && reg_or_int <= 'z' then
- return reg_file[reg_or_int] || 0
- end
- return reg_or_int.to_i
-end
+if [[ $(basename $(pwd)) != 'day23' ]] ; then
+ cd day23
+fi
-input = $stdin.readlines.map(&:chomp)
+file=$(mktemp --tmpdir=. --suffix=.c)
-reg = {'a' => 1}
-pc = 0
+trap "rm $file a.out" EXIT
-loop do
- break if pc < 0 || pc >= input.length
- istr = input[pc].split
- case istr[0]
- when 'set'
- reg[istr[1]] = valof(reg, istr[2])
- when 'sub'
- reg[istr[1]] = valof(reg, istr[1]) - valof(reg, istr[2])
- when 'mul'
- reg[istr[1]] = valof(reg, istr[1]) * valof(reg, istr[2])
- when 'jnz'
- if valof(reg, istr[1]) != 0 then
- pc += valof(reg, istr[2])
- pc -= 1
- end
- end
- pc += 1
-end
-
-puts reg['h']
+./part2gen > $file
+gcc -O3 $file
+./a.out