Advertisement
botimoo

2024 D25

Dec 25th, 2024 (edited)
1,210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.67 KB | Source Code | 0 0
  1. require_relative "../common.rb"
  2.  
  3. module AoC
  4.   class D25 < AocDayBase
  5.     def solve_p1
  6.       locks, keys = [], []
  7.  
  8.       File.read(input_file).split("\n\n").each do |schematic|
  9.         lines = schematic.split("\n").map(&:chars)
  10.         heights = lines[1...-1].transpose.map { |col| col.count("#") }
  11.  
  12.         if lines[0][0] == "#"
  13.           locks << heights
  14.         else
  15.           keys << heights
  16.         end
  17.       end
  18.  
  19.       locks.sum { |lock| keys.count { |key| fits?(lock, key) } }
  20.     end
  21.  
  22.     def fits?(lock, key)
  23.       lock.zip(key).all? { |a, b| a + b <= 5 }
  24.     end
  25.  
  26.     def solve_p2
  27.       "Merry Christmas! Congrats on 10 years, Eric!"
  28.     end
  29.   end
  30. end
  31.  
Tags: aoc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement