David Wees came up with this challenge. Determine what algorithm this code emulates. You will find the answer more informative if you create a table to see the pattern of moves the code makes. The table can then be used to introduce the algorithm formally to your students. Or better yet, get them to build their own tables from the code. Try a range of integers to test the code. What patterns exist?

I will post my answer in a couple of days.

### Like this:

Like Loading...

*Related*

Pingback: The Algorithm in the Code: Building an Inquiry Tool « Digital Substitute

Neat algorithm – GCF is what I get – I think I’m applying it correctly, but…

Hi jg,

Correct, the code returns the GCF, when natural numbers are considered. I’d be interested in knowing what method you used to work this out. My solution, which I hope you read, is in my next post.

Also, what is the name of the algorithm that generates GCF? (It never ends, does it?)

Shawn

I ran through the process in my head a few times, then did it manually a couple of times, had a suspicion, and ran a few pairs through Excel. I then made a handwaving argument about remainders.

No respectable math problem is solved without some magical handwaving!

I hope you enjoyed this math challenge. I have more, plus math labs, that you can play with.