Project Euler 6(Ruby 0.000064s)
require "benchmark" def Euler6() total1 = 0 total2 = 0 100.times do |i| total1 += (i + 1) ** 2 total2 += i + 1 end total2 = total2 ** 2 p total2 - total1 end puts Benchmark::CAPTION puts Benchmark.measure{ Euler6() }
require "benchmark" def Euler6() total1 = 0 total2 = 0 100.times do |i| total1 += (i + 1) ** 2 total2 += i + 1 end total2 = total2 ** 2 p total2 - total1 end puts Benchmark::CAPTION puts Benchmark.measure{ Euler6() }