Created
December 6, 2023 16:37
-
-
Save swhitt/8b74be95824d43df030887a46e23454d to your computer and use it in GitHub Desktop.
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
def part1 | |
times, distances = input_lines.map { |line| line.scan(/\d+/).map(&:to_i) } | |
calculate_wins(times.zip(distances)) | |
end | |
def part2 | |
calculate_wins([input_lines.map { |line| line.delete("^0-9").to_i }]) | |
end | |
def calculate_wins(races) | |
races.map { |time, distance| (1...time).count { |hold| (time - hold) * hold > distance } }.reduce(:*) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment