The 2008 Winter Scripting Games

Advanced Event 6: Prime Time

Important: The deadline for this event has passed. Solutions are available in VBScript, Windows PowerShell, and Perl.

In Prime Time, competitors must write a script that calculates – and displays – all the prime numbers between 1 and 200, inclusive.

Not a native speaker of English? These event instructions are also available in the following languages: Chinese (Simplified); Chinese (Traditional); French; German; Japanese; Portuguese Brazilian; Russian; and Spanish. For more information, and to access these localized instructions, see the Scripting Games International page.

*
On This Page
About This EventAbout This Event
Event ScenarioEvent Scenario

About This Event

Division

Advanced

Deadline

Tuesday, February 26, 2008 (8:00 AM PST)

Points Awarded

5

Top of pageTop of page

Event Scenario

A prime number is a number that can only be evenly divided by 1 and by itself. For example, 7 is a prime number. Why? Because the only two numbers that can be evenly divided into 7 are 1 and 7. By contrast, 12 is not a prime number. Why not? Because, in addition to the numbers 1 and 12, other values (2, 3, 4, and 6) can also be evenly divided into 12.

Now that we know what prime numbers are, it’s time to write a script that can calculate prime numbers. To receive credit for Event 6, you must write a script that calculates – and lists – all the prime numbers between 1 and 200, inclusive. For example:

2
3
5
7

Etc. The best news of all? That’s all you have to do to successfully complete this event. (Hey, even advanced scripters need an easy event every now and then, right?)

Note that we starting with two assumptions here: that the number 1 is not a prime number, but the number 2 is a prime number.

Hint. OK, it’s possible that some of you might have forgotten how to calculate prime numbers. Fortunately, there are algorithms available over the Internet that can help you accomplish this task. For example, search for the Sieve of Eratosthenes and see if that helps.


Top of pageTop of page