Skip to content

Instantly share code, notes, and snippets.

@wazery
Created March 7, 2014 05:46
Show Gist options
  • Save wazery/9405888 to your computer and use it in GitHub Desktop.
Save wazery/9405888 to your computer and use it in GitHub Desktop.
#! /usr/bin/ruby
def euler_2(n)
f = 0
l= 1
numbers = []
i = 0
while i <= n
i = f + l
numbers << i if i % 2 == 0
f = l
l = i
end
puts "The sum is: #{numbers.inject(:+)}"
end
n = ARGV[0].to_i
euler_2 n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment