|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Hi,
anyone can figure this problem. It is a 3x3 number puzzle. We start with for example, +------+------+------+ | 1 | 2 | x | +------+------+------+ | 4 | 5 | 3 | +------+------+------+ | 7 | 8 | 6 | +------+------+------+ uses 'x' to indicate where the empty position currently is in one state. we want to end up with the below shape at the final state: +------+------+------+ | 1 | 2 | 3 | +------+------+------+ | 4 | 5 | 6 | +------+------+------+ | 7 | 8 | x | +------+------+------+ we are given this code and only need the code for move: solution(Row1,Row2,Row3,History) :- move(Row1,Row2,Row3,NewRow1,NewRow2,NewRow3), \+ member(state(NewRow1,NewRow2,NewRow3),History), solution(NewRow1,NewRow2,NewRow3,[state(Row1,Row2,Row3)|History]). The first three arguments are representations of each of the three rows in the puzzle. The fourth argument 'History' is a list of previous states that we have traveled through. Anyways, calling ?- solution([1,2,x],[4,5,3],[7,8,6],[]). should solve the puzzle. This should be easy for any prolog programmer, I just don't know prolog so any takers, please reply or e-mail me at URL Thank you |
![]() |
| Viewing: Dev Shed Forums > Other > Project Help Wanted > prolog easy program.. Easy $$ |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|