Skip to content

Instantly share code, notes, and snippets.

@madebydna
Forked from stuartellis/se-fib-solution
Created August 19, 2010 19:48
Show Gist options
  • Save madebydna/538732 to your computer and use it in GitHub Desktop.
Save madebydna/538732 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby -wKU
puts `ps -o rss= -p #{$$}`.to_i
current_fib = 1
fib_numbers = []
for i in 1..4000000 do
if i == current_fib * 2
fib_numbers << i
current_fib = i
end
end
=begin
fib_numbers.each do |n|
puts n
end
=end
puts `ps -o rss= -p #{$$}`.to_i
#!/usr/bin/env ruby -wKU
puts `ps -o rss= -p #{$$}`.to_i
def fibonacci
a, b = 0, 1
sum = 0
while a < 4000000
printf("%d\n", a)
sum += a if a.even?
a,b = b,a+b
end
puts "-------------"
puts sum
end
fibonacci
puts `ps -o rss= -p #{$$}`.to_i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment