1
2
3
4
5
6
7
8
9
10
11
12
13
14
times, records = ARGF.readlines(chomp: true).map { _1.scan(/\d+/).map(&:to_i) }

# part one
p times.zip(records)
  .map {|time, record|
    distances = (1...time).map {|hold| (time - hold) * hold }
    distances.count { _1 > record }
  }
  .inject(:*)

# part two
time = times.join.to_i
record = records.join.to_i
p (1...time).count {|hold| (time - hold) * hold  > record}