M
Matthew Moss
Challenge:
Here ya go. Non-negative parameter to the function is recursion depth,
so should be 0 for the "null 1x1 carpet", 1 for the 3x3, 2 for the
9x9, etc. This is golfed, and probably a bit more than 80 chars
(gonna wrap in email, I bet).
def carpet(n)
def k(s,x,y) (s<=3D3||k(s/3,x/3,y/3))&&!(x%3=3D=3D1&&y%3=3D=3D1)
end;s=3D3**n;s.times{|y|s.times{|x| print k(s,x,y)?"#":" "};puts}
end
Followup: Make my solution shorter. (There's got to be something nicer
than using `times` twice and `print` once.
=A0 Print out a Serpinski carpet.
Here ya go. Non-negative parameter to the function is recursion depth,
so should be 0 for the "null 1x1 carpet", 1 for the 3x3, 2 for the
9x9, etc. This is golfed, and probably a bit more than 80 chars
(gonna wrap in email, I bet).
def carpet(n)
def k(s,x,y) (s<=3D3||k(s/3,x/3,y/3))&&!(x%3=3D=3D1&&y%3=3D=3D1)
end;s=3D3**n;s.times{|y|s.times{|x| print k(s,x,y)?"#":" "};puts}
end
Followup: Make my solution shorter. (There's got to be something nicer
than using `times` twice and `print` once.