This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-11-29 01:08:19

Transformed71506
New Scratcher
Registered: 2010-09-27
Posts: 8

Greatest Common Factor Script

Hello

Beginner Scratch user here.

I am trying to write a script calculating the GCF using the Euclidean Algorithm.

I want to use the mod block in my script.

For example:  I want to find the GCF between 24 and 10.

The script would calculate 24 mod 10 which is 4.

Then calculate 10 mod 4 which is 2

Then calculate 4 mod 2 which is 0 so my GCF would be 2.

I have set up variables divisor, dividend, remainder and answer in my script but having trouble getting it to work.  I would like the GCF to be displayed an the answer.

I have uploaded my beginning project on my page under Transformed71506.

Any help would greatly be appreciated!  Thanks!

Offline

 

#2 2010-11-29 07:34:41

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Greatest Common Factor Script

What you could d is enter each item on a list (i.e. delete all of the list, then add each new number you are dividing by).  Set up the script to repeat until the last item of the list is zero, then have it set a variable to the second to last number, which will be your GCF.  Does this work for you?

EDIT:  One other thing, I saw on your project you were trying to use the "answer" block, but you can't set that to just anything, it's there for raw input when the "ask" block is used.

Last edited by AtomicBawm3 (2010-11-29 07:36:25)


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#3 2010-11-29 08:03:40

12three
Scratcher
Registered: 2008-06-12
Posts: 1000+

Re: Greatest Common Factor Script

Try this:
I made it in a few minutes.
http://scratch.mit.edu/projects/12three/1448919

Offline

 

#4 2010-11-30 00:18:47

Transformed71506
New Scratcher
Registered: 2010-09-27
Posts: 8

Re: Greatest Common Factor Script

Thanks AtomicBawm3 and12three for your help!

It works great and I see my mistakes!

Offline

 

#5 2010-11-30 12:13:49

12three
Scratcher
Registered: 2008-06-12
Posts: 1000+

Re: Greatest Common Factor Script

Transformed71506 wrote:

Thanks AtomicBawm3 and12three for your help!

It works great and I see my mistakes!

Yep.  wink

Offline

 

Board footer