river-crossing-puzzle

Solve Cannibals/Missionaries using breadth-first search (BFS) in Prolog?

隐身守侯 提交于 2019-12-23 13:35:10
问题 I am working on solving the classic Missionaries(M) and Cannibals(C) problem, the start state is 3 M and 3 C on the left bank and the goal state is 3M, 3C on the right bank. I have complete the basic function in my program and I need to implemet the search-strategy such as BFS and DFS. Basically my code is learn from the Internet. So far I can successfuly run the program with DFS method, but I try to run with BFS it always return false. This is my very first SWI-Prolog program, I can not find

Can't find the error in my Haskell code

匆匆过客 提交于 2019-12-21 19:48:44
问题 I tried to translate a (working !) solution of the cabbage-goat-wolf puzzle from Scala to Haskell, but the code throws and error when calling head in findSolutions because the solution list is empty, so the problem seems to be somewhere in loop. findMoves seems to work fine. import Data.Maybe(fromMaybe) data Item = Farmer | Cabbage | Goat | Wolf deriving (Eq, Show) type Position = ([Item], [Item]) validPos :: Position -> Bool validPos p = valid (fst p) && valid (snd p) where valid list = elem

Getting started with basic transportation problems like Wolf, Cabbage, Goat with either C# or F# [closed]

混江龙づ霸主 提交于 2019-12-13 09:12:44
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . OK. this might be a very basic question to please don't flame me but I have been googling I want to learn how to write solutions to

Generating possible combinations in Prolog

徘徊边缘 提交于 2019-12-12 17:13:20
问题 I am trying to solve the 'missionaries and cannibals' problem using Prolog, in which you have an input number of missionaries and cannibals on one side of an island, and they have to all cross to the other side in a boat that has a specified maximum capacity, with the constraint of: On either side of the island, and in the boat, cannibals cannot outnumber missionaries. There has to be at least one person in the boat. I have attempted to achieve this with the following code: % M = number of

Fox-Goat-Cabbage Transportation

纵然是瞬间 提交于 2019-12-07 18:30:03
问题 My question is about an old transportation problem -- carrying three items across a river with a boat only capable of tranferring one item at a time. A constraint is certain items cannot be left together, such as the cabbage with the goat, wolf with the goat etc. This problem should be solveable using Integer programming, or another optimization approach. The cost function is all items being on the other side of the river, and the trips required to get there could be the output from Simplex (

Can't find the error in my Haskell code

泪湿孤枕 提交于 2019-12-04 09:21:15
I tried to translate a (working !) solution of the cabbage-goat-wolf puzzle from Scala to Haskell, but the code throws and error when calling head in findSolutions because the solution list is empty, so the problem seems to be somewhere in loop. findMoves seems to work fine. import Data.Maybe(fromMaybe) data Item = Farmer | Cabbage | Goat | Wolf deriving (Eq, Show) type Position = ([Item], [Item]) validPos :: Position -> Bool validPos p = valid (fst p) && valid (snd p) where valid list = elem Farmer list || notElem Goat list || (notElem Cabbage list && notElem Wolf list) findMoves :: Position