-
Notifications
You must be signed in to change notification settings - Fork 1
/
tartan.pl
80 lines (69 loc) · 1.02 KB
/
tartan.pl
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
tartan(0,_,_).
tartan(1,0,_):-
write('*'),
write('\n').
tartan(1,1,_):-
write(' * '),
write('\n').
tartan(1,R,AC):-
writeChar(' ',R),
addColumn(AC),
write('*'),
addColumn(AC),
write('\n').
even(N):-
0 is mod(N,2).
odd(N):-
1 is mod(N,2).
writeChar(_,N):-
N =<0.
writeChar(C,N):-
N > 0,
write(C),
N1 is N-1,
writeChar(C, N1).
writeEvenLine(N):-
N0 is 2*N,
N1 is N0-1,
writeChar('*',N1).
writeOddLine(N):-
N1 is (2*N)-3,
write('*'),
writeChar(' ',N1),
write('*').
addColumn(R):-
R = 0.
addColumn(_):-
write('*').
tartan(N,R,AC):-
even(N),
writeChar(' ',R),
addColumn(AC),
writeEvenLine(N),
addColumn(AC),
write('\n'),
N1 is N-1,
R1 is R+1,
tartan(N1,R1,AC),
writeChar(' ',R),
addColumn(AC),
writeEvenLine(N),
addColumn(AC),
write('\n').
tartan(N,R,AC):-
odd(N),
writeChar(' ',R),
addColumn(AC),
writeOddLine(N),
addColumn(AC),
write('\n'),
N1 is N-1,
R1 is R+1,
tartan(N1,R1,1),
writeChar(' ',R),
addColumn(AC),
writeOddLine(N),
addColumn(AC),
write('\n').
tartan(N):-
tartan(N,0,0).