aboutsummaryrefslogtreecommitdiff
path: root/day09/part1
blob: 1bb643a81ea7f1de2ab827075b2eed5207157bf2 (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
44
#!/usr/bin/env ruby

input = gets.chomp.chars

ptr = 0
garbage = false
escape = false
lvl = 0
score = 0

input.each do |ch|
  if escape then
    escape = false
    next
  end
  
  if ch == '!' then
    escape = true
    next
  end

  if garbage then
    garbage = false if ch == '>'
    next
  end

  if ch == '<' then
    garbage = true
    next
  end

  if ch == '{' then
    lvl += 1
    score += lvl
    next
  end

  if ch == '}' then
    lvl -= 1
    next
  end
end

puts score