Skip to content

Commit

Permalink
Solve day 25
Browse files Browse the repository at this point in the history
  • Loading branch information
erikkessler1 committed Dec 25, 2024
1 parent 325eec9 commit 6eedd62
Show file tree
Hide file tree
Showing 3 changed files with 4,110 additions and 0 deletions.
50 changes: 50 additions & 0 deletions day-25/code_chronicle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true

class CodeChronicle
include NewlineInput

def unique_locks
locks = []
keys = []

current_item = Array.new(5) { Array.new(7) }
y = 0
lines.each do |line|
if line.empty?
if current_item.all? { _1.first == 1 }
locks << current_item
else
keys << current_item
end

current_item = Array.new(5) { Array.new(7) }
y = 0
next
end

line.each_char.with_index do |char, x|
current_item[x][y] = char == "#" ? 1 : 0
end

y += 1
end

if current_item.all? { _1.first == 1 }
locks << current_item
else
keys << current_item
end

locks = locks.map { _1.map(&:sum) }
keys = keys.map { _1.map(&:sum) }

result = 0
keys.each do |key|
locks.each do |lock|
result += 1 if key.zip(lock).map(&:sum).all? { _1 <= 7 }
end
end

result
end
end
Loading

0 comments on commit 6eedd62

Please sign in to comment.