blob: ebadaf0c57d7fbfd4f0603dfdbe8762e4fd21b66 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
earliest, notes = File.readlines('input.txt')
earliest = earliest.to_i
ids = notes.split(',').filter_map do |id|
if id != 'x'
id.to_i
end
end
best_wait = ids.max + 1
best_id = 0
ids.each do |id|
wait = id - (earliest % id)
if wait < best_wait
best_wait = wait
best_id = id
end
end
puts best_wait * best_id
|