Last active
December 5, 2023 18:56
-
-
Save henrik/5466b2f3ccffc114af1547169a1fa996 to your computer and use it in GitHub Desktop.
Advent of Code day 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data = DATA.read | |
seeds = data[/seeds: (.+)/, 1].split.map(&:to_i) | |
maps = data.scan(/map:\n(.+?)(?:\n\n|\z)/m).map { |(x)| x.lines.map { _1.split.map(&:to_i) } } | |
locations = seeds.map { |seed| | |
maps.reduce(seed) { |input, map| | |
d, s, _r = map.find { |_d, s, r| (s..(s + r)).cover?(input) } | |
d ? d + (input - s) : input | |
} | |
} | |
puts locations.min | |
__END__ | |
Data goes here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment