-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhalf_pyramid.jl
64 lines (52 loc) · 882 Bytes
/
half_pyramid.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# half_pyramid.jl
# wookay.noh at gmail.com
import Base: ==
type Star
data::Array
end
function show(io::IO, s::Star)
row, col = size(s.data)
for m in 1:row
for n in 1:col
print(io, s.data[m,n])
end
m < row && println(io)
end
end
==(a::Star, b::Star) = ==(a.data, b.data)
function star(a::Array)
Star(map(x->x==1?"*":" ", a))
end
using Base.Test
@test Star(["*" " "]) == star([1 0])
@test Star(["*" " "; " " "*"]) == star([1 0; 0 1])
buf = IOBuffer()
tri = Array(tril(ones(Int,5,5)))
show(buf, star(tri))
println(buf)
@test """\
*
**
***
****
*****
""" == takebuf_string(buf)
show(buf, star(rotl90(tri)))
println(buf)
@test """\
*
**
***
****
*****
""" == takebuf_string(buf)
show(buf, star(rotr90(tri)))
println(buf)
@test """\
*****
****
***
**
*
""" == takebuf_string(buf)
close(buf)