Skip to content

Commit

Permalink
day 14, part 1 (refactor)
Browse files Browse the repository at this point in the history
More names for things, I guess.
  • Loading branch information
robbkidd committed Dec 24, 2024
1 parent abcb023 commit 45a0583
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions 2024/ruby/day24.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ def part1
while to_be_determined.keys.any? {|wire| wire.start_with?('z') } do
puts to_be_determined.keys.inspect if ENV['DEBUG']
to_be_determined
.select {|wire, gate| gate[:inputs].all? { known_wires.key?(_1) } }
.each do |wire, gate|
known_wires[wire] = gate[:proc].call
to_be_determined.delete(wire)
.select {|_wire, gate| gate[:inputs].all? { known_wires.key?(_1) } }
.each do |computable_wire, gate|
known_wires[computable_wire] = gate[:proc].call
to_be_determined.delete(computable_wire)
end
end

known_wires
.select {|wire, signal| wire.start_with?('z') }
.sort_by {|wire, signal| wire }
.select {|wire, _signal| wire.start_with?('z') }
.sort_by {|z_wire, _signal| z_wire }
.reverse
.map {|wire, signal| signal.to_s }
.map {|_z_wire_significantly_ordered, signal| signal.to_s }
.join
.to_i(2)
end
Expand Down

0 comments on commit 45a0583

Please sign in to comment.