30 lines
499 B
Ruby
30 lines
499 B
Ruby
|
#!/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
|