Project Euler Problem 6
module Enumerable def sum inject(0) {|a, n| a + n } end end def f(enum) sum1 = enum.map {|n| n ** 2 }.sum sum2 = enum.sum ** 2 sum2 - sum1 end p f(1 .. 10) p f(1 .. 100)
module Enumerable def sum inject(0) {|a, n| a + n } end end def f(enum) sum1 = enum.map {|n| n ** 2 }.sum sum2 = enum.sum ** 2 sum2 - sum1 end p f(1 .. 10) p f(1 .. 100)