aoc2023/day_6/impl_2.rb

24 lines
511 B
Ruby
Raw Normal View History

2023-12-10 21:28:20 +01:00
#prepare the input which is a string containing new lines
def parse(input)
data = []
input.each_line do |line|
data << line.split(":").last.gsub(" ","").to_i
puts data
end
data
end
# result should a single string or integer
def calculate(data)
win_count = 0
time,distance = data
win_count = 0
(1..time).each do |duration|
speed = duration
time_left = time - duration
travel_distance = speed * time_left
win_count += 1 if travel_distance > distance
end
win_count
end