m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/08/a.rb
blob: 60122eb34ecbdb4686f9fc09257c440a6fa0628e (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
code = []

File.readlines('input.txt').each do |line|
  instruction, number = line.split
  code.push [instruction, number.to_i]
end

visited = {}
current_line = 0
acc = 0

while !visited[current_line]
  visited[current_line] = true
  case code[current_line][0]
  when 'nop'
    current_line += 1
  when 'acc'
    acc += code[current_line][1]
    current_line += 1
  when 'jmp'
    current_line += code[current_line][1]
  end
end

puts acc