1. ## The Challenge

Well.....I Challenge you (The users) to write a program in Qbasic to find the larges prime in a million (1000000).
Think of it as chance to do some research online, and learn some programing and such at the same time

WHAT IS A PRIME?:
A prime number is a number only devisable by itself and 1, good examples of this is 3,5,7 and 9.

THE RULES:
* You Must count upwards (1 to 1000000)
* You Must start at a number between 1 and 5
* You must show the time taken in your program.

WHAT IS QBASIC?:
Qbasic is a fairly easy to learn, and if a good programing language to start off with.
I'll give you some hint's now, and maby some further one's later onward's.
One of the main ideas behind this is to learn how to make a program effective and fast, and have fun (Well, call me sad but I thought it was fun)
Qbasic is Free ware, it can be sought out by a simple Google, if too many ppl start looking for it, I might serve it here, but I'd rather not...

DELIVERY:
Once you feel that your program is good enough to enter, you can PM it to me in Text form as a *.BAS file, NO COMPILED ENTERIES WILL BE MARKED.

THE PRIZE:
Um, well, it would have been a mars bar, but you'll have to put up with some respect and AP's, and any thing else I or any one else can think up in the mean time.

The winner will be anounced in the next Newsletter so make sure you read it
(MsMittens: See me if ther's any questions)

Any question's.....Just PM me, and I'll see wot I can do....
Good Luck.

- Noia

Hint's:
Arrays (DIM)
Nested loops
Theory of Primes

I'v got some more hint's, but first of all I would like so say that this is supposed to teach people to do research for themself, to get invilved with their friends and teachers and other sources of Information, the idea is to learn, and when this challenge was set to me, it was probably one of the things that I'v learnt the most from, I found several ways of doing it, and some worked better than others...

If you have started or plan to start, please tell me, all Final Programs need to be in before the next News letter, some time aroung Min Jan.
All the program's will be tested on my computer, up to three times, the times will be recorded and the mean will be issued, and the winner and runner up will be posted in the News letter (I hope )

Hint's:
Theory of Prime: If a number is a prime, you only need to test it up to the square root of n where n is the max-range you'r looking for....
Also, There is only one even prime, "2", and it is far from the larges prime in a million, so why check the even numbers?

Well.....If you have any question's, send me your program, and I'll see if I can't help to make it faster.....once some more programs start comming in, I'll start posting time's, which will be updated every time a new issue of a program is handed in....

Keep a look out for a dead line which will be about 1-2 days before the News letter (MrsMittens: is it enough time?)

Keep trying.....
- Noia

3. ....except 9 isn't a prime number. ;-) Just an oversite, I'm sure.

5. heeheehee.... math is SO cool!

6. Didn't see this thread the first time... hrm going to keep this in mind if I'm bored today

7. Thanks for removing your post
If your going to participate...good luck...

- Noia

8. The timeline is fine.

Good luck to all those participating.

9. ## PHP?

I started with PHP a couple of days ago, and I thought I'd give it a shot...

THE RULES:
* You Must count upwards (1 to 1000000)
* You Must start at a number between 1 and 5
* You must show the time taken in your program.
Okies, got all that covered. I didn't know how to make it show the time, but Redgore pointed me to this link...

If a number is a prime, you only need to test it up to the square root of n where n is the max-range you'r looking for....
Okies...

I ran the script, but got a "Fatal error: Maximum execution time of 30 seconds exceeded" error...
Therefore, I changed max_execution_time = 30 ; Maximum execution time of each script, in seconds in php.ini to max_execution_time = 5000, just to make sure

Here's my code:

Code:
```<?php
//Get current time - Time code from http://www.webclass.ru/tut.php?tut=137
\$mtime = microtime();
//Split seconds and microseconds
\$mtime = explode(" ",\$mtime);
//Create one value for start time
\$mtime = \$mtime[1] + \$mtime[0];
//Write start time into a variable
\$tstart = \$mtime;

//Actual Code
\$limit = 1000000;
\$test = 2;
while(TRUE)
{
\$testdiv = 2;
if (\$test > \$limit)
break;
while (TRUE)
{
if (\$testdiv > sqrt(\$test))
{
print "\$test ";
break;
}
// test if \$test can be divided by \$testdiv
if (\$test % \$testdiv == 0)
break;
\$testdiv = \$testdiv + 1;
}
\$test = \$test + 1;
}
// Second part of timer-code
//Get current time as we did at start
\$mtime = microtime();
\$mtime = explode(" ",\$mtime);
\$mtime = \$mtime[1] + \$mtime[0];
//Store end time in a variable
\$tend = \$mtime;
//Calculate the difference
\$totaltime = (\$tend - \$tstart);
//Output result
printf ("Page was generated in %f seconds !", \$totaltime);
?>```
Here are the last lines of the output:

999667 999671 999683 999721 999727 999749 999763 999769 999773 999809 999853 999863 999883 999907 999917 999931 999953 999959 999961 999979 999983 Page was generated in 381.632641 seconds !

10. hehe....well, you got the right answer.....but 381 sec's is a bit long....try to make it so that it only prints a variable at the end, and keep over writing the variable once you find a new prime...saves time.......nice prog though ....keep it up

- Noia

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•