;!Function game24($,$b,$c,$d) $game24=f(""+$+$b+$c+$d,"")EndFunctionFunction f($,$b) Dim $e,$x,$y,$z,$a If($) For $x=1 to Len($) $e=f(Left($,$x-1)+SubStr($,$x+1),$b+SubStr($,$x,1)) If $e $f=$e EndIf Next Else $e=Split("+ - * /") For Each $x In $e For Each $y In $e For Each $z In $e $=Left($b,1)+".0"+$x+"("+SubStr($b,2,1)+".0"+$y+"("+SubStr($b,3,1)+".0"+$z+Right($b,1)+"))" $z=Execute("$$a="+$) If "24"=$a $f=$ EndIf Next Next Next EndIfEndFunction

_________________________
There are two types of vessels, submarines and targets.

AJH, it's worth a great deal. Your post shows the effort you put forth to solve the problem. You found an issue with nested arrays. Other people may not have been aware this issue existed. Your score is secondary. You are one a few that took the time and completed the task. Good work.

{edit}AJH, You can reduce your score score by four by compacting your execute string: '$$y=ABS(24.-('+$e+'))<0.01'. Remember spaces within quotes are counted for the next KixGolf outing.

I am a bit late since my home machine still isn't up to snuff. I actually lowered my score to 653. I might have tried to go lower but I couldn't seem to generate any method that worked consistently. I especially had trouble with Jooel's suggestion of testing the script with a large number of random selection. This code passes Jens test & seems to works properly for a large number of random selections but if I change the order of the permutations (i.e. use '+ - / *' instead of '+ - * /') it still fails.

PS: Did you all verify that your code actually generates all the combinations & did you compare your results with Madruga's analysis? Richard's code is a thing of beauty but it doesn't generate all the possible combinations. Richard assumes the nested brackts "a (b(c d))" can be morphed into all possible solutions but it cannot be morphed into several of the unique solutions found by Madruga.

I think validating our results is a serious challange in this competition.

My first post, checked (ab)(cd), (abc)d, and a(bcd) which I think covers the required combinations as long as the numbers and operator all rotate through all combinations.

If Jens did not include the random input check then I think that if the other checks pass the script is good. But since the random numbers are part of the test, all possible combination of 1-9 would need to be checked. Since we currently have no good method of independently varifying a given set of random numbers at test time we can not be sure if the test scripts correctly found no solution or simply did not find the solution do to short comings of the code.

I applaud Jens for the time he spends setting this up and do not believe that absolute perfection is a requirement for this level of competition. The discussions so far have been quite interesting.

I just ran Richards code through all combinations by having four FOR loops looping from 0-9. Howver, at around the numbera 8,1,0,0 the script exitied with an 'Out of menory' message. I also noticed that the script consumed an ever increasing amount of memory while looping.

I was running it under KiXtart 4.12 beta 1 and it looks like there's some kind of memory leak.

[ 23. September 2002, 15:39: Message edited by: sealeopard ]

_________________________
There are two types of vessels, submarines and targets.

I saw your comment in the beta forum & I wonder about another issue - the "Join" function. It appears that Join strips all zeros & the decimal from numbers if that is at all possible. Thus if you declare a variable to be double precision but put an integer value into the variable then Join will convert it to an integer during the join. Currently, to force retention of floating point or double types you must work in pure strings. All the solutions posted seem to work in a pure string type right up to the evaluate. There are no mixture of types.

The question is if this is an appropriate strategy for the Join function. Maybe if the variable type is floating point or double then Join should append a decimal & a zero to the number to retain the original type.

For me sorting out all the problems was a major headache because I didn't realize at first that there was at least 3 problems & not 1. They were the problems of zero divide, the Join & rounding. I think this project really put Kixtart to the test in the domaine of real math. I know that this is the first time that I have looked at real math so closely in kixtart.

I knew that, in order to have a winner, I'd have to let go of the obvious "tons" of nested FORs; and I knew there had to be some way to rotate the whole shebang, but I failed to see what you did...

Also, the parentheses swap was a nice trick!

BTW: If I'm not mistaken, you can change the 1E-9 for a bigger 0.1 (or can we use just .1 in KiXtart?) and it takes 1 (or 2) bytes out. It "should" be accurate enough, as the results that get closest to 24 and are not good answers are 23.8(8) and 24.1(6), if memory serves me...

On second though, Howard, are you sure your code is ok? I mean, you work with only 16 permutations of the possible 24!! Try runing under my improved test script (streamlined the output, and fixed some bugs). Also, and since one of the solutions that your code fails to find is one that has nothing to do with the permutations, there's bound to be some major error in there other than the missing permutations... Try your code with the 5555 set and check it out...