New member here, I've spent the last 3 months trying to solve this problem on my own and have come up with a kind of workable solution, however its not as efficient as I want it to be.
I am trying to create a program that is capable of taking a choice based logic problem (We'll use the old grain/chicken/fox one to start) and going through and making smart choices that make sense, randomly, until it obtains the solution, BUT it remembers its choices and won't repeat a series of failed choices.
Luckily, for this question there are only 3 possible choices per move, move the chicken, the fox, or the grain, to the other side.
Not only that but after a move I can cut out 1/3 of the moves, the same one, as why would we bother moving the chicken to the left side then bring it right back to the right again?
At the moment I've been representing the problem inside my program as a nested matrix, 3x3x3x3x3, in other words a tree diagram splitting up into 3s 5 times.
The program first starts at the first layer of the matrix, which I named PrimeMatrix, and chooses randomly one of three moves.
It then tests if that move is a 1 in the matrix, which starts out as [1,1,1], then makes the move. If it is still within the boundaries of the move, it turns the 1 into another layer of [1,1,1] so now, say the first move, turns the matrix from [1,1,1] into [[1,1,1],1,1].
If it fails it replaces it with a 0, so if the first move doesnt follow the rules the matrix becomes [0,1,1] then it goes back and tries again.
Eventually after getting enough layers deep and checking if the chicken grain and fox are all on the right side, the program ends and relays back what moves gave success.
It's a lot more complicated than that but thats the gist of it. It works, but under one condition which just won't do for me.
I have to know the minimum steps for success.
The reason for this is I don't know how to infinitely add layers to the matrix. I have to have, with my skill, 5 blocks of code, one per layer, per choice.
IE
Label 1
initial set up of variables
Do first move
if rules are broken goto 1
else
set matrix layer's choice to another layer
do second move
etc etc
I don't know how to program in any language to infinitely add layers to a matrix, does anyone know how?
I mostly use VB, though matrix wise I decided to use actionscript because it's a lot more friendly when it comes to lists within lists, thing is I want to know how to do this better for a big exam for potential scholarships, and need to know how to display this in psuedo code or flow charts.
Watch the exam this year not even have any bonus questions on it about learning algorithms >.<
Learning + Memory Algorithm to Solve Simple Problems
Started by PuppetMaster, May 23 2010 11:41 AM
5 replies to this topic
#1
Posted 23 May 2010 - 11:41 AM
|
|
|
#2
Posted 23 May 2010 - 01:57 PM
I'd use a list of arrays, rather than an a large 2d array. Using recursion, you return failure (-1) if you hit a loop, or failure. You return the list and minimum number of steps on success.
#3
Posted 23 May 2010 - 02:39 PM
That is what I use, each "layer" of the array is the next step.
For the chicken fox grain question the min steps I already know is 5, 3 choices per step, therefore the array is 5 dimensionel, 3x3x3x3x3
Which works brilliantly if I know how many steps are required because then I just make code for each step manually.
I want to make a program that will just keep trying steps infinitely and make the array infinite in dimensions until it hits an error.
I have no idea how to do this though in flash or VB, let alone psuedoscript or as a flowchart =/
For the chicken fox grain question the min steps I already know is 5, 3 choices per step, therefore the array is 5 dimensionel, 3x3x3x3x3
Which works brilliantly if I know how many steps are required because then I just make code for each step manually.
I want to make a program that will just keep trying steps infinitely and make the array infinite in dimensions until it hits an error.
I have no idea how to do this though in flash or VB, let alone psuedoscript or as a flowchart =/
#4
Posted 23 May 2010 - 03:47 PM
VB should have some sore of List container, stack, etc.
#5
Posted 24 May 2010 - 09:28 PM
In terms of language, see python. Python has a data structure called "Lists". These would solve your problem.
Also, learning python is not tough, will take a week at max and you will have some command over it.
How to add new layers?
Say you have :
A= [1,1,1]
next,
B = [] // Now B = []
B.append(A) // Now B = [[1,1,1]]
B.append(1) // Now B = [[1,1,1],1]
basically the structure that you wrote, in the manner you visualized it, is easily creatable and manipulatable in Python.
Cheers!
Also, learning python is not tough, will take a week at max and you will have some command over it.
How to add new layers?
Say you have :
A= [1,1,1]
next,
B = [] // Now B = []
B.append(A) // Now B = [[1,1,1]]
B.append(1) // Now B = [[1,1,1],1]
basically the structure that you wrote, in the manner you visualized it, is easily creatable and manipulatable in Python.
Cheers!
#6
Posted 25 May 2010 - 05:13 AM
Thats called a matrix, please see my third paragraph where I outline exactly that, except instead of all the jostling around with creating a secondary list and placing that within one, I simply tell actionscript to straight up make one inside it.
Once again, I'll reiterate. I need a way to infinitely add layers. It seems the append function does add 1 var to the list at the end, if that is what append does (add whatever you input)
In which case half of my problem is accomplishable, I can create the list infinitely by repeatedly appending [1,1,1] to it increasing its dimensions.
However I would need a way to reference the point as well, tell the program to look at the point, and test if it is a 1 or a 0 or another array.
How does python reference a point in an array, is it just B[1] to see the first point, and B[2] to see the second, etc? And then is it B[1][2] to see the sdecond point of the first array?
var PrimeMatrx:Array = [1,1,1] PrimeMatrix[1] = [1,1,1] //PrimeMatrix is now [[1,1,1],1,1,]
Once again, I'll reiterate. I need a way to infinitely add layers. It seems the append function does add 1 var to the list at the end, if that is what append does (add whatever you input)
In which case half of my problem is accomplishable, I can create the list infinitely by repeatedly appending [1,1,1] to it increasing its dimensions.
However I would need a way to reference the point as well, tell the program to look at the point, and test if it is a 1 or a 0 or another array.
How does python reference a point in an array, is it just B[1] to see the first point, and B[2] to see the second, etc? And then is it B[1][2] to see the sdecond point of the first array?


Sign In
Create Account

Back to top









