Click to See Complete Forum and Search --> : The Challenge


Noia
December 12th, 2002, 09:13 PM
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 :D

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

Noia
December 18th, 2002, 07:39 PM
Follow up:
Well, that wasn't exactly a Massive hit........I'v had one reply.....

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 :D)

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

mathgirl32
December 18th, 2002, 07:48 PM
....except 9 isn't a prime number. ;-) Just an oversite, I'm sure.

Noia
December 18th, 2002, 07:51 PM
Woops..I just realized........lol.....your right my bad.....tanx :)

mathgirl32
December 18th, 2002, 07:53 PM
:D heeheehee.... math is SO cool!

neel
December 18th, 2002, 08:45 PM
Didn't see this thread the first time... hrm going to keep this in mind if I'm bored today

Noia
December 18th, 2002, 08:46 PM
Thanks for removing your post ;)
If your going to participate...good luck...

- Noia

MsMittens
December 18th, 2002, 08:48 PM
The timeline is fine. ;)

Good luck to all those participating. ;)

Negative
December 30th, 2002, 05:20 PM
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 (http://www.webclass.ru/tut.php?tut=137)...


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:


<?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 !

Noia
December 30th, 2002, 06:12 PM
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

Noia
January 3rd, 2003, 07:26 PM
The final Evaluation of the programs will be done as soon as I get my New comp (in about 3-4 days), every one who want's to take part must have handed in their programs by then. I will try to accomedat any late enterys, and any final entery will be checked instead of their current entery.

Good luck.....

Guus
January 4th, 2003, 01:58 AM
Hehe, this is the best you're-doing-my-homework-and-you-dont-even-realise-it cover-up I've seen to date :)

Noia
January 4th, 2003, 02:15 AM
er??
I already handed mine in at school, and I won...and if you want proof I can send you the source :P
BTW...congrats on 900 posts...

- Noia

Guus
January 4th, 2003, 03:10 AM
Just kidding Noia, just kidding :)

Human$hield
January 4th, 2003, 04:18 AM
I wrote a program exactly like this but in C++ my freshman year in college. This thread is cool though, I like the idea of you guys throwing out some challenges for us. I think I'll hold off until we get one a bit more in depth:) I always love to work with a group of bright minds on this kind of stuff! Great fun!

Noia
January 4th, 2003, 12:36 PM
lol......damn ,theres some one who's beating my time....by half!! lol...oh well, I'm still lacking a bit on the enterys so pleas hurry up people....

Guus: lol, I know :D

HumanShield: If youd like too, you could make a challenge in C, I know there are alot of ppl who would like that, also other languages would be cool, but I chose QBasic to try and get some newbies into the game of programing.....hehe, didn't work out very well, still....

- Noia

- Noia