Skip to content

Instantly share code, notes, and snippets.

@eric1234
Created October 8, 2009 02:38
Show Gist options
  • Select an option

  • Save eric1234/204665 to your computer and use it in GitHub Desktop.

Select an option

Save eric1234/204665 to your computer and use it in GitHub Desktop.
Problem 6 on Project Euler
class Numeric
def squared
self * self
end
end
module Enumerable
def sum &blk
blk = proc {|x| x} unless block_given?
inject(0) {|sum, element| sum + (blk[element] || 0)}
end
end
puts (1..100).sum.squared - (1..100).sum {|i| i.squared}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment