[SWIPL] 8 Queens problem for a 3D chessboard
黃耀賢 (Yau-Hsien Huang)
g9414002.pccu.edu.tw@REDACTED
Wed May 5 05:04:18 CEST 2010
Sorry, Erlang guys. I post this article in a wrong mailing list.
I'm sorry.
2010/5/5 黃耀賢 (Yau-Hsien Huang) <g9414002.pccu.edu.tw@REDACTED>
> Step 0. Correct the original program.
>
> Step 1. Use board/1 and queens/1 to produce 3 candidate answer
> sets, each one for one dimension.
>
> Step 2. Take every one answer from 3 candidate answer sets, and
> check if all chesses existing in the first answer set match
> corresponding ones in the second answer set, while ones in the
> later answer set match corresponding ones in the third answer set.
>
> This is a quick answer. Sorry for sort of inaccurate.
>
> On Wed, May 5, 2010 at 3:17 AM, xlacrimx <xlacrimx@REDACTED> wrote:
>
>>
>> I have the code for an 8 by 8 chessboard for the 8 Queens problem. How
>> could
>> I modify it to make it 8 by 8 by 8? Here's the code:
>>
>> queens([]).
>> queens(Row/Col|Rest]):-queens(Rest), member(Col,[1,2,3,4,5,6,7,8]),
>> safe(Row/Col,Rest).
>>
>>
>> safe(Anything,[]).
>> safe(Row/Col,[Row1/Col1|Rest]):-Col =\= Col1, Col1 - Col =\= Row1 - Row,
>> Col1 - Col =\= Row - Row1, safe(Row/Col,
>> Rest).
>>
>> member(X,[X|Tail]).
>> member(X,[Head|Tail]):-member(X|Tail).
>>
>> board([1/C1, 2/C2, 3/C3, 4/C4, 5/C5, 6/C6, 7/C7, 8/C8]).
>> --
>> View this message in context:
>> http://old.nabble.com/8-Queens-problem-for-a-3D-chessboard-tp28451926p28451926.html
>> Sent from the SWI Prolog mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> SWI-Prolog mailing list
>> SWI-Prolog@REDACTED
>> https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>>
>
>
More information about the erlang-questions
mailing list