Alice Community Spirals and the Fibonacci Function

 Spirals and the Fibonacci Function
 lanceA Guest   Status: Posts: n/a Spirals and the Fibonacci Function - 11-10-2006, 07:45 PM I'm trying to develop a fibonacci method to solve the following: A guy is at the bottom of a mountain, the mountain is to the North, he is facing South. He says, "Now that I am at the bottom of the mountain, I need to turn around." After he turns he says, "Then I walk in a spiral of six quarter turns to the left. If I do this I will be at the opening for the magic tunnel at the bottom of the mountain." This has to be solved using recursion. The method to be invoked must employee fibonacci computation methods. Otherwise his movement will be similar to 3rd grade herky-jerky movements. Has anyone successfully used recursion in solving Fibonacci computations in ALICE and would you be willing to share your code? Computing the fibonacci numbers will cause the MAN to walk in a true spiral, not a circle or square or rectangle, etc. Thanks in advance P.S. The answer is NOT: Loop 6 times Do together man.move. forward .1 meters man.turn.left 1/4 revolution Last edited by lanceA; 11-10-2006 at 08:02 PM. Reason: To add further clarification
 One solution.
DrJim
Guest

Status:
Posts: n/a
One solution. - 11-11-2006, 11:14 AM

See attached code for the recursive sequence generation. Some notes:

1. Technically, this doesn't violate the cheating policy since problem 7-7a, p. 209 in the Herbert text asks for pseudo-code and this is the real thing. Still - comments anyone? (I'm not being a smart ass here - I really tried and couldn't figure out a way to explain this without posting the code.)

2. The algorithm is from a 20+ year old reference http://www.atarimagazines.com/creati...ay_to_skin.php that used Basic (ohh ) and a dreaded "GOTO" (ahh, gasp ). To get the recursive version, I just replaced the GOTO with the "obviously superior" (OK, I can be a smart ass ) recursive method call. The reference also gives a formula for calculating individual numbers in a Fibonacci sequence, although I haven't tried it.

3. To generate the spiral once you have the sequence, see http://library.thinkquest.org/27890/theSeries6a.html . Note that a spiral generated this way will have discontinuous second derivatives and will be a bit "herky-jerky."
Attached Files
 Fibonacci.a2w (173.5 KB, 1330 views)

Last edited by DrJim; 11-11-2006 at 11:17 AM.

 lanceA Guest   Status: Posts: n/a 11-11-2006, 06:41 PM Thanks for the suggestion. I notice your method requires 2 input params.....I prefer the students do it with one. I'm trying to teach them efficient coding techniques I think I've worked it out with a for-loop, using 4 lines of code in Alice. But I will give them credit if they use your method because it does work. Thanks again, Last edited by lanceA; 11-11-2006 at 07:14 PM. Reason: further clarification of the issue
 Efficiency?
 DrJim Guest   Status: Posts: n/a Efficiency? - 11-13-2006, 09:38 AM I wrote that code specifically to demonstrate a purely recursive approach and therefore avoided any iterative construct such as a loop. Other that to say I think it's a great topic for class discussion, I won't comment directly on relative efficiencies, since that's also part c of the problem in the Herbert text. I will note, however, that the few times I've actually used the sequence (it's a good benchmark because of it's slightly "herky-jerky" behavior) I've used either a table lookup or an iterative approach to generate it. Last edited by DrJim; 11-13-2006 at 09:44 AM. Reason: (corrected a "Freudian" slip - had said regressive for recursive.
 Shadow Sovereign Guest   Status: Posts: n/a 11-14-2006, 07:33 PM Not more Fibonnaci.... ....I think my head is gonna explode.

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements     Community News and Announcements Alice 3     How Do I?     Works In Progress     Share Your World     Share Custom Classes     Bugs and Trouble Shooting     Suggestion Box Alice 2     How do I...?     Works-In-Progress     Share Worlds     Share Objects     Bugs and Troubleshooting     Suggestion Box Educators     Teaching with Alice     Teaching Using Alice 3     Teaching Using Alice 2     CS Principles and Alice     AP CSA and Intro to Java and Alice     Workshops General Discussion     Questions and Comments     The Lounge