You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
advent-of-code/2017/ruby/day_09.rb

26 lines
379 B

require "strscan"
input = ARGF.read.strip
input = input.gsub(/!./, "")
p input.scan(/<[^>]*>/).map {|g| g.size - 2 }.sum
input = input.gsub(/<[^>]*>/, "")
.gsub(?,, "")
ss = StringScanner.new(input)
score = 0
group = 0
until ss.eos?
case
when ss.scan(/\{/)
group += 1
when ss.scan(/\}/)
score += group
group -= 1
else
raise "omg!"
end
end
p score