PHP Programming Contests - April - May 2004 - No. 8

Please note this contest ended 2nd May 2004 at 23.59.

Contest 8 (Number Cruncher)
Number Cruncher

Yes, an algo contest again.... I hear you say ;).
Most (if not all) of the UK entrants will know a television gameshow called 'Countdown' where they have a few games, one of which is the numbers game (if anyone knows the real name, let me know). The game is very straight forward. You are given a list of numbers and an answer and are asked to give the quckest formula using all the numbers in the list to get the answer. The operators used are plus(+), minus(-), multiply(*) and divide(/). Well i'm going to add a few tweeks to that for this contest ;)

More details about the contest
I will provide a list of numbers (between 5 and 50 in the list), the numbers will appear in this format '123.45', ranging from '0' to '9999.99' - two decimal places maximum. The answer you need to find will appear at the end of the list (last item), a example is below:


The above example will be stored in a text file named 'numbers.txt' each idividual number is seperated by a ',' comma.

The Rules
Please read these rules carefully!!
1. The list of seperate numbers can range from 5 to 50 not including the answer. 2. Each number in the list will be seperated by a ',' comma, no comma will exist at the start or end of the list. 3. Legal mathematical operators allowed are: Plus(+), Minun(-), Multiply(*) and Divide(/). 4. Each number in the list must be used once, BUT can be used upto a maximum of twice. So each number can be used twice. 5. Legal operators can be used any number of times and not all are required. 6. Maximum execution time per run is 55 seconds. (Based on php 4.3.2 running on modern system) 10 extra seconds will be given for the testings and results, but you should base your run on a max of 55.

Again as above the input will be provided as a text file named 'numbers.txt' which will follow the format below:
The list will have anywhere between 5 and 50 seperate numbers not including the answer.

Your script will return the list of numbers and operators used to solve the formula in the correct order. Followed by and '=' sign and the answer found. For example:
23 + 100.1 + 78.01 + 1 + 90.5 = 292.61
If however your script cannot find the correct answer, then it should return the closest answer it can!!

* UPDATE * Parenthisis may be used in the puzzle!!(see the forum). The shortest solution will win over speed, however if more than one script produces the same solution the fastest script will win.

Judging and Winning
The winning scripts will be the fastest and most accurate!!
All scripts will be tested numerous times using various lists as described above.

Closing Date:
All entries in by Sunday 2nd May 2004 at 23.59 (GMT)

Send your entry (including scripts) to please include a text file 'contact.txt' with your forum username, Full Name and Email Address. Submissions should be zipped. Please also post a message in the contest forum stating you just submitted and entry!!

Rules and Restrictions:
Must run on Linux
Must run with PHP4.3.4 (register globals off)
No third party PHP extensions ( other than ones supplied with php 4.3.4 on
All code must be writen by you !!


Please post any questions in the Contest Forums!!... best of luck

Contest 8 Winner

Winner: Taylor Johnson - View Full Results.

© Copyright 2003-2014 The ultimate PHP Editor and PHP IDE site.