Files
aoc2022/day2/day2b.jl
Bryce Allen e4c7345d33 day2
2022-12-02 10:29:54 -05:00

34 lines
595 B
Julia

#!/usr/bin/env julia
infile = size(ARGS, 1) > 0 ? ARGS[1] : "day2input.txt"
println("infile = ", infile)
a_move_value = Dict("A"=>1, "B"=>2, "C"=>3)
function score(opponent, self)
oval = a_move_value[opponent]
if self == "X"
# need to lose
sval = 1 + mod(oval - 2, 3)
return sval
elseif self == "Y"
# need to tie
sval = oval
return 3 + sval
else
# need to win
sval = 1 + mod(oval, 3)
return 6 + sval
end
end
io = open(infile, "r")
total = 0
for line in eachline(io)
global total
o, s = split(line)
total += score(o, s)
end
println(total)