General Question

inunsure's avatar

Is there anyone good at programming who would like to help me create this puzzle solver?

Asked by inunsure (423points) April 25th, 2012

It’s a program to work out all river crossing puzzles
http://en.wikipedia.org/wiki/River_crossing_puzzle

Now I’ve worked out a way to solve all these problems but I dont know much about programming to make an app to run the steps to solve such a puzzle

Observing members: 0 Composing members: 0

16 Answers

yankeetooter's avatar

I have to ask…is this a homework problem?

inunsure's avatar

No what school has homework like this

funkdaddy's avatar

What did you have in mind?

Do you want something to show common examples with solutions or something where the user can enter variables? Is it a game the user has to solve or a tool? Is it animated?

If you want to do it yourself, I like javascript for this sort of quick proof of concept. It’s relatively easy to learn and just takes a text editor and a web browser to get started.

There are some excellent resources online, the W3Schools is a great place to start.

There are other good options, but I like how easy it is to find documentation on javascript for someone just starting out.

dabbler's avatar

@funkdaddy‘s ideas are a great start. In particular Javascript is a simple enough programming language to get started, and you have everything you need to make it work (your browser).

Beyond that it’s a logic exercise first. You’ll want to think about how to define the specific abilities and limitations of each actor in your scenario, and the facilities and limitations of the environment (river?) and how to define them in every way that matters.
Then decompose your solution method into every step, and consider where there can be loopbacks / iterations while working out any particular problem.

Next step is to translate all that into your chosen coding language, and try it !
Have fun.

roundsquare's avatar

If you haven’t seen graph theory before you may find it useful.

Also, lots of schools have homework like this. For example, any computer science class might have homework like this.

phaedryx's avatar

I’d actually warn against W3Schools. Some of their examples are bad or weird. I’d recommend something like MDN instead.

funkdaddy's avatar

@phaedryx – out of curiosity, what’s weird about the if else example? I think the Mozilla guides are great for programmers looking to learn something new, or as reference, but W3Schools is better for someone with no previous background to get some useful and inspiration tools to actually build a first project.

phaedryx's avatar

w3schools does a mix of allman and whitesmith brace style in their examples when everyone else in the javascript world uses “one true brace” style (Crockford says anything but 1TB is “awful”, see his section on semicolon insertion here). That’s why I say it is weird. Javascript has a lot of idiosyncrasies that w3schools fails to mention, that I think should be pointed out.

phaedryx's avatar

So, I coded this up in Ruby last night: https://gist.github.com/97f68ccde901ede0d0bc
(added comments this morning)

A bit rough, but hopefully gets the idea across for the recursive solution. The approach I took was to model the riverbanks and boat and rules for moving things between them.

inunsure's avatar

@phaedryx
^_^ I’m so lost. How do you use it what does it do?

phaedryx's avatar

Using it:
save it to a file (say river.rb)
run it with a ruby interpreter: ruby river.rb

What it does:
outputs the solution to the river-crossing puzzle (I tried to include enough comments that you could follow it, actual output is at the bottom of the file)

phaedryx's avatar

Hmm, perhaps a higher-level explanation:

First I considered everything involved: a boat, the side of the river everything is on, the other side of the river when they are trying to get to, a man, a fox, a goose, and beans.

I decided I could treat the man, fox, goose, and beans as items I wanted to move around. I could treat the riverbanks and boat as containers of items. I would move items from one container to another—riverbank, into the boat, across the river, and out of the boat onto the other river bank. I just needed to program the rules for what could be left on a bank, what could go into a boat, and moving items between the containers. Whenever I moved items from one container to another I would output the result.

Example some logic: when passengers get on the boat, they are removed from the riverbank and added to the boat:
current_bank = current_bank – passengers
boat = boat + passengers

Example checking one of the rules, if a set of passengers is allowed on the boat
(boat + passengers).okay?

LostInParadise's avatar

I think that what @inunsure is looking for is a general purpose program to cover river crossing problems in general. It seems to me that the tricky part is to come up with a way for entering the rules. For a few examples, the first few problems here The list is by no means exhaustive.

inunsure's avatar

I’ve already worked out a way to solve all the river crossing problems, its in one of my other threads

phaedryx's avatar

Huh, got off on a tangent and forgot what the original question was about. Oops, that was a waste of time.

LostInParadise's avatar

What would be required then would be the following:
Specify a list of types of crosser, giving each a name.
Tell how many there are of each type of crosser.
Enter a list of illegal combinations on a river bank of the various types of crossers, making use of wildcards if appropriate.
Specify requirements for and illegal combinations of people who can be in the boat, again making use of wildcards. This allows the program to determine legal transitions from one state to the next.

The computer program would then have sufficient information to go from a state of having nobody on the far bank to having everyone there.

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther