I ran into a strange looking problem the other day. It involves the use of a special recursive function called the necklace problem. Heard it's supposed to be a famous math problem. Anyways. The thing is, I have to input two numbers, the first one to fill in the tens value place, and the second number to fill in the ones value place. To get the next number, I have to add the two previous numbers and only use the number in the ones place value, but it has to stop if you see the same two numbers in the beginning. So only the numbers of the ones place value are used. I am very close to getting it, but the condition to stop my loop doesn't seem right.
I seem to be very close to getting it right. What's the correct boolean condition to stop it? Suggestions/ideas/solutions all welcomed if possible
It works quite well, but it sorta destroyed the whole idea of a recursion. I tried to define the next number in terms of the previous two numbers that were being calculated. I never expected this to work your way like that.
a) swap number1 and number2: b) counter is incremented after the calculation, which leads to array[counter]==0 for every iteration while testing c) you need a || instead of && - do while one of both conditions is false (or both).
[ May 31, 2006: Message edited by: Stefan Wagner ]
[ May 31, 2006: Message edited by: Stefan Wagner ] [ June 01, 2006: Message edited by: Stefan Wagner ]