2015/08/script.rb

30 lines
499 B
Ruby
Raw Permalink Normal View History

2021-11-23 13:29:22 +01:00
#!/usr/bin/env ruby
require_relative '../common'
class Day08 < Day
def part1
count_code_characters - count_real_characters
end
def part2
new_input = input.map do |row|
"\"#{row.gsub(/(["\\])/, '\\\\\1')}\""
end
new_input.map(&:size).sum - count_code_characters
end
private
def count_code_characters
input.map(&:size).sum
end
def count_real_characters
input.map { |row| row.gsub(/\\\\|\\"|\\x[0-9a-f]{2}/, '_').size - 2 }.sum
end
end
Day08.run