aboutsummaryrefslogtreecommitdiff
path: root/day02/part1
blob: 460b3b5169b557a7b24dee0986bb1f2094f76ff7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env ruby

$input = $stdin.readlines[0].strip.split(",").map(&:to_i)
$pc = 0

def handle_code
  case $input[$pc]
  when 1
    $input[$input[$pc+3]] = $input[$input[$pc+1]] + $input[$input[$pc+2]]
    return true
  when 2
    $input[$input[$pc+3]] = $input[$input[$pc+1]] * $input[$input[$pc+2]]
    return true
  when 99
    return false
  end
end

$input[1] = 12
$input[2] = 2

loop do
  continue = handle_code
  break unless continue
  $pc += 4
end

puts $input[0]