Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require_relative "../common.rb"
- module AoC
- class D25 < AocDayBase
- def solve_p1
- locks, keys = [], []
- File.read(input_file).split("\n\n").each do |schematic|
- lines = schematic.split("\n").map(&:chars)
- heights = lines[1...-1].transpose.map { |col| col.count("#") }
- if lines[0][0] == "#"
- locks << heights
- else
- keys << heights
- end
- end
- locks.sum { |lock| keys.count { |key| fits?(lock, key) } }
- end
- def fits?(lock, key)
- lock.zip(key).all? { |a, b| a + b <= 5 }
- end
- def solve_p2
- "Merry Christmas! Congrats on 10 years, Eric!"
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement