Pascal Triangles in Ruby with Enumerator
Stumbled across Enumerator and somebody had an example of Pascal Triangles …
def pascal
Enumerator.new do |e|
e << coll = [1]
loop do
e << coll = ([0] + coll).zip(coll + [0]).map(&:sum)
end
end
end
triangles = pascal
puts triangles.take(10)
⬅️ Read previous Read next ➡️