Skip to content

Instantly share code, notes, and snippets.

@swhitt
Created December 6, 2023 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swhitt/8b74be95824d43df030887a46e23454d to your computer and use it in GitHub Desktop.
Save swhitt/8b74be95824d43df030887a46e23454d to your computer and use it in GitHub Desktop.
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