This commit is contained in:
2023-12-06 00:37:09 -05:00
parent bda745865f
commit 2bb1b8c901
2 changed files with 18 additions and 0 deletions

12
2023/day6/p1.rb Normal file
View File

@@ -0,0 +1,12 @@
# frozen_string_literal: true
res = 1
f = File.open('./2023/day6/data')
times = f.readline.scan(/\d+/).map(&:to_i)
distances = f.readline.scan(/\d+/).map(&:to_i)
times.each_with_index do |time, i|
res *= (0..time).reduce(0) { |acc, j| distances[i] < (time - j) * j ? acc + 1 : acc }
end
puts res

6
2023/day6/p2.rb Normal file
View File

@@ -0,0 +1,6 @@
# frozen_string_literal: true
f = File.open('./2023/day6/data')
time = f.readline.split(':')[1].gsub(' ', '').to_i
distance = f.readline.split(':')[1].gsub(' ', '').to_i
puts (0..time).reduce(0) { |acc, j| distance < (time - j) * j ? acc + 1 : acc }