Book Image

Scratch Cookbook

By : Brandon Milonovich
Book Image

Scratch Cookbook

By: Brandon Milonovich

Overview of this book

Scratch 2.0 is an easy to use programming language that allows you to animate stories and create interactive games. Scratch also gives you the capability of using programming to calculate complicated calculations for you. Scratch Cookbook will lead you through easy-to-follow recipes that give you everything you need to become a more advanced programmer. Scratch Cookbook will take you through the essential features of Scratch. You'll then work through simple recipes to gain an understanding of the more advanced features of Scratch. You will learn how to create animations using Scratch. Sensory board integration (getting input from the outside environment) will also be covered, along with using Scratch to solve complicated and tedious calculations for you. You'll also learn how to work through the exciting process of project remixing where you build on the work of others. Scratch Cookbook will give you everything you need to get started with building your own programs in Scratch that involve sounds, animations, and user interaction.
Table of Contents (17 chapters)
Scratch Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Sieve of Eratosthenes


This recipe is all about generating prime numbers. It is a known algorithm that can generate these numbers for us. An algorithm is a specific procedure (or set of instructions) that leads us to a result. If you'd like detailed information about how the algorithm works, you should take a moment to visit http://mathworld.wolfram.com/SieveofEratosthenes.html.

In a nutshell, the sieve works by determining if a number is prime by doing the following. You write down all of the numbers from 2 until your end point (let's say that we want to find all of the primes until the number 100 ; you'd write every number from 2 to 100). Next, go through each number from smallest to greatest and cross it out if it is divisible by 2. Then look at the smallest number in the list (in our case, 3). Beginning with the next number higher than 3, cross out each number divisible by 3. Continue this process until you've gotten to , where n is the number you were going up to. All of the numbers that...