blob: aadb8601e09f575844e19adb795e45ea4aff9c49 (
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#!/usr/bin/env ruby
Input = $stdin.readlines[0].strip.split(",").map(&:to_i)
noun = 0
verb = 0
loop do
$input = Input.dup
$input[1] = noun
$input[2] = verb
$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
loop do
continue = handle_code
break unless continue
$pc += 4
end
break if $input[0] == 19690720
verb += 1
if verb == 100
verb = 0
noun += 1
end
end
puts (100 * noun) + verb
|