General programming

Moderators: None (Apply to moderate this forum)
Number of threads: 1642
Number of posts: 2791

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Can anyone help me with Prolog ? Posted by babak_deghat on 23 Dec 2012 at 4:47 AM
every time i run the following code :

:- 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,’*’).


strawberry prolog just says :
Compiling the file:
C:\Users\Babak\Desktop\111111.pro
0 errors, 0 warnings.
No.


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



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.