babakdeghat
Technical User
- Dec 23, 2012
- 7
every time i run the following code :
[italic]
:- use_module(contestlib, [writeN/2]).
cross(N) :-
hor_line(N),
N1 is N - 1,
B1 is N1 // 2,
Middle is N1 + B1,
down(N,’*’,0,N1),
down(N,’.’,N1,B1),
blanks(1), blanks(Middle), stars(1), nl,
up(N,’.’,Middle,B1),
up(N,’*’,N1,N1),
hor_line(N).
hor_line(N) :- stars(N), blanks(N), stars(N), nl.
down(_,_,_,0) :- !.
down(N,Delimiter,Outer,Lines) :-
write_line(Delimiter,Outer,N),
Outer1 is Outer + 1,
Lines1 is Lines - 1,
down(N,Delimiter,Outer1,Lines1).
up(_,_,_,0) :- !.
up(N,Delimiter,Outer,Lines) :-
Outer1 is Outer - 1,
write_line(Delimiter,Outer1,N),
Lines1 is Lines - 1,
up(N,Delimiter,Outer1,Lines1).
write_line(Delimiter,OuterSpace,N) :-
write(Delimiter),
blanks(OuterSpace),
stars(1),
InnerSpace is 3*N - 4 - 2*OuterSpace,
blanks(InnerSpace),
stars(1),
blanks(OuterSpace),
write(Delimiter),
nl.
blanks(N) :- writeN(N,’.’).
stars(N) :- writeN(N,’*’).[/italic]
strawberry prolog just says :
[italic]Compiling the file:
C:\Users\Babak\Desktop\111111.pro
0 errors, 0 warnings.
No.[/italic]
the aim of this code :
Write a predicate cross/1, for which cross(N) draws a cross figurer.
* * * * *
* * * * *
* *
* *
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
* *
* *
* * * * *
* * * * *
3 × N
N N N
(a) N = 5
* * *
* * *
* *
* *
*
*
*
*
*
*
*
*
*
*
*
*
*
* *
* *
* * *
* * *
(b) N = 3
here is a picture of what it should look like :
[italic]
:- use_module(contestlib, [writeN/2]).
cross(N) :-
hor_line(N),
N1 is N - 1,
B1 is N1 // 2,
Middle is N1 + B1,
down(N,’*’,0,N1),
down(N,’.’,N1,B1),
blanks(1), blanks(Middle), stars(1), nl,
up(N,’.’,Middle,B1),
up(N,’*’,N1,N1),
hor_line(N).
hor_line(N) :- stars(N), blanks(N), stars(N), nl.
down(_,_,_,0) :- !.
down(N,Delimiter,Outer,Lines) :-
write_line(Delimiter,Outer,N),
Outer1 is Outer + 1,
Lines1 is Lines - 1,
down(N,Delimiter,Outer1,Lines1).
up(_,_,_,0) :- !.
up(N,Delimiter,Outer,Lines) :-
Outer1 is Outer - 1,
write_line(Delimiter,Outer1,N),
Lines1 is Lines - 1,
up(N,Delimiter,Outer1,Lines1).
write_line(Delimiter,OuterSpace,N) :-
write(Delimiter),
blanks(OuterSpace),
stars(1),
InnerSpace is 3*N - 4 - 2*OuterSpace,
blanks(InnerSpace),
stars(1),
blanks(OuterSpace),
write(Delimiter),
nl.
blanks(N) :- writeN(N,’.’).
stars(N) :- writeN(N,’*’).[/italic]
strawberry prolog just says :
[italic]Compiling the file:
C:\Users\Babak\Desktop\111111.pro
0 errors, 0 warnings.
No.[/italic]
the aim of this code :
Write a predicate cross/1, for which cross(N) draws a cross figurer.
* * * * *
* * * * *
* *
* *
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
* *
* *
* * * * *
* * * * *
3 × N
N N N
(a) N = 5
* * *
* * *
* *
* *
*
*
*
*
*
*
*
*
*
*
*
*
*
* *
* *
* * *
* * *
(b) N = 3
here is a picture of what it should look like :