[2023][ruby][6.x]

main
Alpha Chen 12 months ago
parent 1931b227df
commit b8cd0faa3e
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -0,0 +1,15 @@
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 }
Loading…
Cancel
Save