Forum Moderators: coopster

Message Too Old, No Replies

Restart A Function

         

DCHWeb

1:39 pm on Apr 20, 2005 (gmt 0)

10+ Year Member



I have a function that merely iterates through an array of arrays, appending an integer to one of the values in the 2nd level array. I would like the function to be restarted if the integer that is ready to be placed in the value already exists there. Theoretically, calling the function again would recurse and would cause major problems, while stopping the function first would prevent it from being called again.

If you need a bit of background, I am coding a script for a Family and Consumer Sciences teacher at a local middle school. The script generates a schedule for each student in the class, telling them what module to go to in what order. It has the following restrictions: Two students cannot be partnered more than once, and a student cannot be in a given module more than once.

Any help would be appreciated.

gettopreacherman

3:09 pm on Apr 20, 2005 (gmt 0)

10+ Year Member



from just sitting back and thinkin...I would use something like a Loop for the number of results, then within that loop call your function...within your function you simply append or don't append the number...

DCHWeb

8:52 pm on Apr 20, 2005 (gmt 0)

10+ Year Member



A number has to be appended, and it must be different than all previous numbers. I cannot change one number, as that would throw off the order, i must change them all.

It would produce something like this

Already in value:
0,
0,
1,
1,
2,
2,
.
.
.

What should happen
0,9,
0,4,
1,2,
1,6,
2,1,
2,4,
.
.
.

I think i may be going about this the wrong way, so I am open to any suggestions about how I should change or rewrite this.

jd01

3:48 am on Apr 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can get the numbers this way:

I drew this out on paper, so let me try to explain how I got it to work faily easily.

Pretend you have three circles each with the number of modules and students, the inside one stays still, the middle one rotates +1 at a time, and the outside one rotates +2 at a time.

The outside circle will rotate on odd numbers, and complete a rotation in 1/2 the time of the middle group, putting the outside group back at point 1, but with only half of the modules done, the middle group will be at the half way point, with half of the modules done also.

You could then put the outside group on the even numbers they missed, and keep the middle rotating at +1. They should all finish at the same time, but not repeat because of the difference in the speed of the rotation.

Hope this makes sense & helps.

Justin

Added: I don't have time to do the math, right now, but I'm sure you can find an equasion to do the trick =)