Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
Spirals and the Fibonacci Function
Old
lanceA
Guest
 
Status:
Posts: n/a
Default Spirals and the Fibonacci Function - 11-10-2006, 08: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 09:02 PM. Reason: To add further clarification
   
Reply With Quote
One solution.
Old
DrJim
Guest
 
Status:
Posts: n/a
Arrow One solution. - 11-11-2006, 12:14 PM

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
File Type: a2w Fibonacci.a2w (173.5 KB, 1324 views)

Last edited by DrJim; 11-11-2006 at 12:17 PM.
   
Reply With Quote
Old
lanceA
Guest
 
Status:
Posts: n/a
Default 11-11-2006, 07: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 08:14 PM. Reason: further clarification of the issue
   
Reply With Quote
Efficiency?
Old
DrJim
Guest
 
Status:
Posts: n/a
Thumbs up Efficiency? - 11-13-2006, 10: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 10:44 AM. Reason: (corrected a "Freudian" slip - had said regressive for recursive.
   
Reply With Quote
Old
Shadow Sovereign
Guest
 
Status:
Posts: n/a
Talking 11-14-2006, 08:33 PM

Not more Fibonnaci....


....I think my head is gonna explode.
   
Reply With Quote
Reply

Thread Tools
Display Modes

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 Jump



Copyright ©2017, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.