June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -1,12 +1,16 @@
pprint(matrix) = for i = 1:size(matrix,1) println(join(matrix[i,:])) end
spaces(m,n) = [" " for i=1:m, j=1:n]
function sierpinski(n, token = "*")
x = [token for i=1:1, j=1:1]
for i = 1:n
t = spaces(size(x)...)
x = [[x x x] ; [x t x] ; [x x x]]
end
x
function sierpinski(n::Integer, token::AbstractString="*")
x = fill(token, 1, 1)
for _ in 1:n
t = fill(" ", size(x))
x = [x x x; x t x; x x x]
end
return x
end
function printsierpinski(m::Matrix)
for r in 1:size(m, 1)
println(join(m[r, :]))
end
end
sierpinski(2, "#") |> printsierpinski

View file

@ -0,0 +1,27 @@
sub carpet
{
(['#'], -> @c {
[
|@c.map({$_ x 3}),
|@c.map({ $_ ~ $_.trans('#'=>' ') ~ $_}),
|@c.map({$_ x 3})
]
} ... *).map: { .join("\n") };
}
say carpet[3];
# Same as above, structured as an array bound to a sequence, with a separate sub for clarity.
sub weave ( @c ) {
[
|@c.map({ $_ x 3 }),
|@c.map({ $_ ~ .trans( '#' => ' ' ) ~ $_ }),
|@c.map({ $_ x 3 })
]
}
my @carpet = ( ['#'], &weave ... * ).map: { .join: "\n" };
say @carpet[3];
# Output of both versions matches task example.