RosettaCodeData/Task/Sylvesters-sequence/Crystal/sylvesters-sequence.cr

19 lines
324 B
Crystal
Raw Permalink Normal View History

2026-04-30 12:34:36 -04:00
require "big"
def sylvester
accum = 1.to_big_i
curr = 1.to_big_i
Iterator.of {
accum *= curr
curr = accum + 1
}
end
puts "First 10 elements:"
sylvester.first(10).each do |s|
puts s
end
print "\nSum of the reciprocals of the first 10 elements: "
puts sylvester.first(10).sum {|s| BigRational.new(1, s) }