aboutsummaryrefslogtreecommitdiff
path: root/day09/part2
blob: d92e7cd6c0fc085090116f5618be9f91e4f6fdbc (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
#!/usr/bin/env ruby

input = gets.chomp.chars

ptr = 0
garbage = false
escape = false
lvl = 0
chars = 0

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

  if garbage then
    if ch == '>' then
      garbage = false
    else
      chars += 1
    end
    next
  end

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

puts chars