In [1]:
example = [
    "b inc 5 if a > 1"
    "a inc 1 if b < 5"
    "c dec -10 if a >= 1"
    "c inc -20 if c == 10"
]


Out[1]:
4-element Array{String,1}:
 "b inc 5 if a > 1"    
 "a inc 1 if b < 5"    
 "c dec -10 if a >= 1" 
 "c inc -20 if c == 10"

In [19]:
using DataStructures

registers = DefaultDict(0)

function execute(program)     
    empty!(registers)
    m = 0
    for line in program
        r1, op1, v1, r2, op2, v2 = match(r"([a-z]+) (inc|dec) ([-]?[0-9]+) if ([a-z]+) ([><=!]+) ([-]?[0-9]+)", line).captures
        eval(parse("if registers[\""*r2*"\"] "*op2*" "*v2*"; registers[\""*r1*"\"] "*(op1 == "inc" ? "+=" : "-=")*" "*v1*" end"))
        if length(registers)>0
            m = max(m, maximum(values(registers)))
        end
    end
    m
end


Out[19]:
execute (generic function with 1 method)

In [21]:
println("  Maximum alltimes ", execute(example))
println("Maximum at the end ", maximum(values(registers)))


  Maximum alltimes 10
Maximum at the end 1

In [23]:
open("inputs/day8.txt") do fd
    println("  Maximum alltimes ", execute(readlines(fd)))
    println("Maximum at the end ", maximum(values(registers)))
end


  Maximum alltimes 5199
Maximum at the end 4416

In [ ]: