diff --git a/2023/ruby/day_06.rb b/2023/ruby/day_06.rb new file mode 100644 index 0000000..1dd3728 --- /dev/null +++ b/2023/ruby/day_06.rb @@ -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 }