Skip to content

Instantly share code, notes, and snippets.

@michael-reeves
Created June 1, 2015 14:54
Show Gist options
  • Save michael-reeves/b7dc44e3d323d1162185 to your computer and use it in GitHub Desktop.
Save michael-reeves/b7dc44e3d323d1162185 to your computer and use it in GitHub Desktop.
prime fibonaccis
require 'prime'
class Prime
def self.fib(n)
if n == 0
return 0
end
(2..n).reduce([0,1]) do |total, n|
total << total[-1] + total[-2]
end
end
def self.primes(n)
Prime.first n
end
end
Prime.fib(30).each do |n|
if Prime.prime?(n)
puts "#{n} (prime)"
else
puts n
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment