diff options
author | Nat Lasseter <Nat Lasseter nathan@bytemark.co.uk> | 2017-12-23 12:53:06 +0000 |
---|---|---|
committer | Nat Lasseter <Nat Lasseter nathan@bytemark.co.uk> | 2017-12-23 12:53:06 +0000 |
commit | 0dd497895a93bec09c911154ffefab85a9559375 (patch) | |
tree | 6d6b96d94fb753b8c883371457567eaa55189b51 /day23/part2 | |
parent | 4f32293785d818f5c31394ef0f85cb729797e053 (diff) |
C attempt. Probably slightly faster. No free optimisations.day23
Diffstat (limited to 'day23/part2')
-rwxr-xr-x | day23/part2 | 39 |
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 |