You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
406 B
16 lines
406 B
10 months ago
|
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
|
||
|
distances = (1...time).map {|hold| (time - hold) * hold }
|
||
|
p distances.count { _1 > record }
|