Skip to content

Commit

Permalink
Shorten global loops
Browse files Browse the repository at this point in the history
  • Loading branch information
bewuethr committed Dec 9, 2023
1 parent c763763 commit 261a62f
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions 2023/day05/day05b
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,10 @@ end

mappings = mappings_str.map { |str| Mapping.new(str) }

mins = []
global_min = seeds.map do |seed_range|
mappings.reduce([seed_range]) do |ranges, mapping|
mapping.convert(ranges)
end.map(&:first).min
end.min

seeds.each do |seed_range|
ranges = [seed_range]

mappings.each do |mapping|
ranges = mapping.convert(ranges)
end

mins << ranges.map(&:first).min
end

puts mins.min
puts global_min

0 comments on commit 261a62f

Please sign in to comment.