Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Programming Contests > PHP Programming Contests

PHP Programming Contests Everything to do with the PHP Programming Contests.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2004-04-13, 12:44 PM
stuart's Avatar
Administrator
 
Join Date: Jan 2003
Location: Scotland
Posts: 472
stuart will become famous soon enoughstuart will become famous soon enough
Send a message via MSN to stuart
Default

As always, any questions relating to contest 8 please post here !!

Stuart
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2004-04-13, 06:24 PM
jbardin
Guest
 
Posts: n/a
Default

Are parenthesis allowed...

e.g.

1 + 2 + 3 * 4 = 15

1 + (2 + 3) * 4 = 21

This is important because if parens are not allowed then the solution to the contest is ubersimple, number of permutations is low n^x

foreach ($permutations as $permutation) {
if (eval($permutation) == $answer)) {
echo 'Solved'; break;
}
}

when parens get involved the number of permutations rises several orders of magnitude greater for each number in the input set. ni^x + ni^xn-1 ... or something like that...

the point is the contest is just a fight as to who can loop the fastest, and transfer the least amount of memory.

IIRC codewalkers.com tried a similar contest

http://codewalkers.com/contests/2003-11-03/
Reply With Quote
  #3 (permalink)  
Old 2004-04-14, 09:46 AM
stuart's Avatar
Administrator
 
Join Date: Jan 2003
Location: Scotland
Posts: 472
stuart will become famous soon enoughstuart will become famous soon enough
Send a message via MSN to stuart
Default

I was waiting for someone to ask that!!! ... I was going to add it to the contest page but totally forgot

Yes, parenthesis may be used in the puzzle so your script must account for this.

Also forgot to mention that the shortest solution will win over time!!! if more that one script finds the same shortest solution then the fastest will win!

Cheers,
Stuart
Reply With Quote
  #4 (permalink)  
Old 2004-04-14, 06:17 PM
Junior Member
 
Join Date: May 2003
Location: Boulder, CO
Posts: 14
Mr. Sketch
Default

What happens to extra decimal places after a divide or multiply? Round or trunc, and should it be done after each operation or wait until the end to do the final rounding/truncing:

ex:
17,7,2.42 or would it be 2.43 since the result of the divide is 2.4285714285714285714285714285714
Reply With Quote
  #5 (permalink)  
Old 2004-04-15, 04:45 PM
stuart's Avatar
Administrator
 
Join Date: Jan 2003
Location: Scotland
Posts: 472
stuart will become famous soon enoughstuart will become famous soon enough
Send a message via MSN to stuart
Default

Welcome back Mr. Sketch!!

Very good question indeed

I think a 'round' after each calculation is the only way.

For example if the number = 136.09456353622 you should round it, and end up with 136.09.

An other example would be 136.09510808928 should round to 136.1


Cheers
Reply With Quote
  #6 (permalink)  
Old 2004-04-17, 09:26 AM
Guest
Guest
 
Posts: n/a
Default

1. Is it always possible to find an exact solution for the numbers given to the script?
2. How is length measured? Is it a length of the 'result string' or the number of operators/operands used?
Reply With Quote
  #7 (permalink)  
Old 2004-04-17, 11:25 AM
stuart's Avatar
Administrator
 
Join Date: Jan 2003
Location: Scotland
Posts: 472
stuart will become famous soon enoughstuart will become famous soon enough
Send a message via MSN to stuart
Default

Yes, All lists will have an exact solution provided you use the rules specified in the posts above.

Length is measured by operators used!!
Reply With Quote
  #8 (permalink)  
Old 2004-04-18, 05:08 AM
Guest_Eric
Guest
 
Posts: n/a
Default

So, the list you provide can have up to 50 numbers in it and the last one will be the value the script is suppose to reach? This one is over my head I think...
Reply With Quote
  #9 (permalink)  
Old 2004-04-18, 09:58 PM
Junior Member
 
Join Date: Apr 2004
Posts: 2
argonauta
Default

hi there

I was reading, and one conditions is that you MUST use each number at least once, and at most twice, right?

however, what if you give me 5 numbers, but the smallest solution would be using only 4 of them?

i mean, you give me:

a,b,c,d,e=>f

the best solution being:
a+b+c+d=f
but if i have to use all numbers then the solution would be presented as:
a+b+c+d+(e-e)=f

Which only adds one more operator to the solution, nothing else. Well, when the list gets bigger, you could try to find a better way to remove all non-used numbers via substraction, but this, by all means, would be already kinda useless???

anyway, i wanted to make sure: ALL and ALL numbers must be used, or we must use as few numbers as possible??????
Reply With Quote
  #10 (permalink)  
Old 2004-04-19, 09:19 AM
stuart's Avatar
Administrator
 
Join Date: Jan 2003
Location: Scotland
Posts: 472
stuart will become famous soon enoughstuart will become famous soon enough
Send a message via MSN to stuart
Default

Hi,

Yes, all numbers must be included at least once, but can be used twice!! the object of the game is to find the shortest solution using the rules above (and any other rules stated). In your example your second one would be valid. But you are correct, it may well be possible to find the solution without using all numbers in the list.... but that is cheating
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.0 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.0 (a popular PHP IDE) and NuCoder 1.4 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:05 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.