Share
Explore BrainMass

Create a Program that Models a Worm's Behavior

Create a program that models the worm's behavior in the following scenario:

A worm is moving toward an apple. Each time it moves the worm cuts the distance between itself and the apple by its own body length until the worm is close enough to enter the apple. The worm can enter the apple when it is within a body length of the apple.

Attachments

Solution Preview

Please look into the attached word doc. Although, no objective is given the statement reveals that the final goal of the worm is the enter the apple. Furthermore, there is nothing stopping it from doing so (predators, impediments, stamina, etc). So, it is always true that the worm enters the apple. The question then is when? The following program attempts to answer the ...

Solution Summary

Please look into the attached word doc. Although, no objective is given the statement reveals that the final goal of the worm is the enter the apple. Furthermore, there is nothing stopping it from doing so (predators, impediments, stamina, etc). So, it is always true that the worm enters the apple. The question then is when? The following program attempts to answer the question by finding the integral number of moves needed to get the worm close to the apple within its body length.
The program has been extensively commented and can be implemented in any programming language easily. Hope it helps.

$2.19