-1

I have a Prolog project to create about the "Puzzle 8". I'm new with this language. I have many doubts so I came here to resolve at least one. Here is my code:

puzzle([1, 2, 3, 4, 5, 6, 7, 8, 0]).

affiche_puzzle :-
    puzzle(Puzzle),
    printe(Puzzle).

printe([]).
printe([H1,H2,H3|Puzzle]) :-
    format('~w ~w ~w~n', [H1, H2, H3]),
    printe(Puzzle).

My doubt is why when I use the printe([H1,H2,H3|Puzzle]) the result is this and not the numbers of the list:

_G4716 _G4719 _G4722
Puzzle = [] ;

_G4843 _G4846 _G4849
Puzzle = [_G4843, _G4846, _G4849]...

I would be grateful if you help me!

false
  • 10,264
  • 13
  • 101
  • 209
Cesar
  • 25
  • 4
  • Your code should work as is without changes if you type in (query) `affiche_puzzle`. What did you type in as a query? – lurker May 10 '15 at 01:51

1 Answers1

2

you must call each predicates with suitable arguments:

?- affiche_puzzle.
1 2 3
4 5 6
7 8 0
true.

?- printe([a,b,c,d,e,f,g,h,i]).
a b c
d e f
g h i
true.

houssam
  • 1,823
  • 15
  • 27