RosettaCodeData/Task/Sierpinski-carpet/Ruby/sierpinski-carpet.rb
2015-11-18 06:14:39 +00:00

11 lines
274 B
Ruby

def sierpinski_carpet(n)
carpet = ["#"]
n.times do
carpet = carpet.collect {|x| x + x + x} +
carpet.collect {|x| x + x.tr("#"," ") + x} +
carpet.collect {|x| x + x + x}
end
carpet
end
4.times{|i| puts "\nN=#{i}", sierpinski_carpet(i)}