Created
May 15, 2012 02:14
-
-
Save masui/2698568 to your computer and use it in GitHub Desktop.
fibprime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# | |
# フィボナッチ数列を出力 | |
# | |
fib = [1,1] | |
loop do | |
puts fib[0] | |
fib.push fib.shift + fib[0] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# | |
# 2, 3, 5, 13, 89, 233, 1597, 28657, 514229, 433494437, 2971215073, ... | |
# | |
IO.popen("./fib1.rb","r"){ |ffib| | |
IO.popen("./prime1.rb","r"){ |fprime| | |
fib = ffib.gets.to_i | |
prime = fprime.gets.to_i | |
while true do | |
if fib == prime then | |
puts fib | |
fib = ffib.gets.to_i | |
prime = fprime.gets.to_i | |
elsif fib > prime then | |
prime = fprime.gets.to_i | |
else | |
fib = ffib.gets.to_i | |
end | |
end | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# | |
# 素数をひたすら出力 | |
# | |
primes = [2] | |
puts 2 | |
cand = 3 | |
while true do | |
lim = Math.sqrt(cand).floor | |
primes.each { |prime| | |
if prime > lim then | |
puts cand | |
primes << cand | |
break | |
end | |
if cand % prime == 0 then | |
break | |
end | |
} | |
cand += 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment