Computer Science Canada CCC J5 2005 Bananas Help |
Author: | nike52 [ Thu Mar 13, 2008 11:41 am ] |
Post subject: | CCC J5 2005 Bananas Help |
Hey. I'm doing J5 2005, indirect recursion, really a tough cookie. I've solved the problem but I'm having trouble trying to understand another person's solution from the http://access.mmhs.ca/ccc/index.htm website. Here's the PDF, if you haven't seen it. http://www.cemc.uwaterloo.ca/ccc/2005/junior/bananas.pdf Here's the full code. http://access.mmhs.ca/ccc/2005/2005j5bananas.txt The part that I don't understand from the person's code is this part Quote: var found : boolean := false
for i : 2 .. length (s) - 1 found := found or (aWord (s (1 .. i - 1)) and s (i) = "N" and monkeyWord (s (i + 1 .. *))) end for result found First, so far from what I think I understand, found equals false or true, true, if those 3 conditions are true. If those 3 conditions are true once, then found equals true for the rest of the for loop. What I don't understand is the for loop. What's it there for? I tried running without it, but the solution doesn't work and I can't understand how it works. Could someone explain to me that part of the code? Why it's there, why is it doing what's it doing, why is there a for loop? I've banged my head alot on it. So far what I think it's unnecessary. Obviously I'm wrong though. I think running the first 3 conditions is satisfactory enough to find out if the word is a monkey language word. E.g. ANBBASS A is the aword, satisfies the 1st condition N satisfies the second and BBASS satisfies the 3rd *EDIT* I GET IT NOW |