Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Stern-Brocot-sequence/Ruby/stern-brocot-sequence.rb
Normal file
20
Task/Stern-Brocot-sequence/Ruby/stern-brocot-sequence.rb
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
def sb
|
||||
return enum_for :sb unless block_given?
|
||||
a=[1,1]
|
||||
0.step do |i|
|
||||
yield a[i]
|
||||
a << a[i]+a[i+1] << a[i+1]
|
||||
end
|
||||
end
|
||||
|
||||
puts "First 15: #{sb.first(15)}"
|
||||
|
||||
[*1..10,100].each do |n|
|
||||
puts "#{n} first appears at #{sb.find_index(n)+1}."
|
||||
end
|
||||
|
||||
if sb.take(1000).each_cons(2).all? { |a,b| a.gcd(b) == 1 }
|
||||
puts "All GCD's are 1"
|
||||
else
|
||||
puts "Whoops, not all GCD's are 1!"
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue