Sealeopard
(KiX Master)
2002-09-15 12:19 AM
KiXtart Golf V: Game24

KiXtart Golf V: 24 Game

The general KiXtart Golf rules are at the end of the post. Following are the goal and rules for the current KiXtart Golf challange.

Goal
Use four integer numbers from an integer range of 0-9 and the following basic math operations +, -, *, /, (, and ) in such a way that the resulting formula equals 24.

Rules
    [*]All four integers must be used
    [*]Each integer may only be used once
    [*]Only the basic math operators +, -, *, / and parentheses ( and ) are allowed
    [*]The formula must conform to standard math rules, thus for example 3 / 2 = 1.5 or 1 / 3 = 0.3 period (0.333333....).

    [*]The formula must conform to the math rules of precedence (for example * before +)

    [*]Some combinations can result in multiple solutions, only one is to be returned

    [*]Some combinations may not result in a valid solution, then an empty string is to be returned

Examples:
( 1 + 2 + 3 ) * 4 = 24
1 * 2 * 3 * 4 = 24

The prototye for the function is as follows:
code:
$outputstring=Game24($digit1,$digit2,$digit3,$digit4)

Example
Given the input:
code:
$out = Game24(1,2,3,4)

one possible output string for $out might be
code:
$out = '(1+2+3)*4'

or
code:
$out = '1*2*3*4'

Test Code
code:
BREAK ON

DIM $rc, $out, $result, $i1, $i2, $i3, $i4

$rc=SETOPTION('Explicit','ON')
$rc=SETOPTION('NoVarsInString','ON')
$rc=SRND(@MSECS)


? 'Game24 KiXtart Golf running under KiXtart v'@KIX
? ''

$i1=1
$i2=2
$i3=3
$i4=4
? 'Numbers = '+$i1+', '+$i2+', '+$i3+', '+$i4
$out=Game24($i1,$i2,$i3,$i4)
if trim($out)=''
? 'Incorrect answer, there is a solution to this combination'
? ''+$out+' <> 24'
else
? 'Please doublecheck your solution to guarantee a correct result'
? ''+$out+' = 24'
endif
? ''

$i1=2
$i2=2
$i3=6
$i4=8
? 'Numbers = '+$i1+', '+$i2+', '+$i3+', '+$i4
$out=Game24($i1,$i2,$i3,$i4)
if trim($out)=''
? 'Incorrect answer, there is a solution to this combination'
? ''+$out+' <> 24'
else
? 'Please doublecheck your solution to guarantee a correct result'
? ''+$out+' = 24'
endif
? ''

$i1=4
$i2=4
$i3=6
$i4=6
? 'Numbers = '+$i1+', '+$i2+', '+$i3+', '+$i4
$out=Game24($i1,$i2,$i3,$i4)
if trim($out)=''
? 'Correct answer answer, there is no solution to this combination'
else
? 'Incorrect answer, there is no solution to this combination'
endif
? ''

$i1=3
$i2=3
$i3=8
$i4=8
? 'Numbers = '+$i1+', '+$i2+', '+$i3+', '+$i4
$out=Game24($i1,$i2,$i3,$i4)
if trim($out)=''
? 'Incorrect answer, there is a solution to this combination'
? ''+$out+' <> 24'
else
? 'Please doublecheck your solution to guarantee a correct result'
? ''+$out+' = 24'
endif
? ''

$i1=RND(9)
$i2=RND(9)
$i3=RND(9)
$i4=RND(9)
? 'Numbers = '+$i1+', '+$i2+', '+$i3+', '+$i4
$out=Game24($i1,$i2,$i3,$i4)
if trim($out)=''
? 'No solution found'
? ''+$out+' <> 24'
else
? 'Please doublecheck your solution to guarantee a correct result'
? ''+$out+' = 24'
endif
? ''


$i1=3
$i2=4
$i3=7
$i4=7
$out=Game24($i1,$i2,$i3,$i4)
? 'Numbers = '+$i1+', '+$i2+', '+$i3+', '+$i4
if trim($out)=''
? 'Incorrect answer, there is a solution to this combination'
? ''+$out+' <> 24'
else
? 'Please doublecheck your solution to guarantee a correct result'
? ''+$out+' = 24'
endif
? ''

$i1=1
$i2=2
$i3=8
$i4=9
$out=Game24($i1,$i2,$i3,$i4)
? 'Numbers = '+$i1+', '+$i2+', '+$i3+', '+$i4
if trim($out)=''
? 'Incorrect answer, there is a solution to this combination'
? ''+$out+' <> 24'
else
? 'Please doublecheck your solution to guarantee a correct result'
? ''+$out+' = 24'
endif
? ''

function game24($a,$b,$c,$d)
endfunction

================================================================
KiXtart GOLF - How To Play
================================================================


Most importantly, anybody can play, no age restrictions, no penalties, no handicap!

The object in "real" golf is to hit the ball in the hole in the fewest strokes. The object in KiXtart Golf is to get from input (tee) to target (hole) in the fewest keystrokes.

Example: How many positive elements are in array $a?

Array $a could be of structure $a=[1, 2 ,-3, 4, -5, -7, 8, 9]

One approach:
code:
for $b=0 to ubound($a)
if $a[$b]>0
$c=$c+1
endif
next

for a score of 45.

Another solution is:
code]DO
$b=$b+1
if $a[$b]>0
$c=$c+1
endif
UNTIL $b>(UBOUND($a)+1)[/code]

for a score of 53.

Better approach: Code sample 1

================================================================
KiXtart GOLF - The Rules
================================================================


1) The goal of KiXtart Golf is to score the lowest strokes.

2) Strokes are all characters in a piece of code except whitespace characters, unless the whitespace character is necessary for the line of code to work. Therefore, carriage returns and line feeds do not count or spaces in between the '=' sign when assigning variables, e.g. '$a = $b' scores 5.

3) Code can be constructed any way you like, as long as it is syntactically correct with KiXtart.

4) The final solution MUST pass all test scripts that accompagny the KiXtart golf challenge.

5) The use of '$' as a variable is allowed.

6) In case of questions about a particular way to count the KiXtart Golf Challenge organizer has the last call.

7) During the private coding phase, no code is allowed to be posted. Violations result in disqualification of said player.

8) During the public coding phase, code should be posted, reused, and borrowed from other players.

9) The following script can be used to count the KiXtart Golf score: http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=2;t=003608

================================================================
KiXtart GOLF - The Duration of the Competition
================================================================


1) Private coding phase: From date/time of posting the tournament challenge to the following Saturday, 3pm EST (BBS+6 time)

2) Public coding phase: From Saturday, 3pm EST (BBS+6 time) to the following Wednesday, 3pm EST (BBS+6 time)

3) Final results: The following Monday, 11am EST (BBS+6 time)

[ 16. September 2002, 23:07: Message edited by: sealeopard ]


MightyR1
(MM club member)
2002-09-15 12:24 AM
Re: KiXtart Golf V: Game24

Whoops there it is....

Gonna start th(dr)inking [Big Grin] [Big Grin]


Sealeopard
(KiX Master)
2002-09-15 12:32 AM
Re: KiXtart Golf V: Game24

Just a little history to this:

I was at a good friends party celebrating his Ph.D. defence (after nearly six years of working on it) when a mutual friend of ours started talking about the '24 Game'. He's a math teacher and using it in his classroom.

Naturally, with the help of a couple of 'Mike's Hard Lemonade', some of us started solving the numbers he threw at us. We stumbled for about 20 minutes through possible solutions for '3 3 7 7' before he told us. I guess, the increasing amount of empty bottles made him believe we'd never find a solution to that one, even though there are multiple.


LonkeroAdministrator
(KiX Master Guru)
2002-09-15 12:52 AM
Re: KiXtart Golf V: Game24

that really seems tricky.

not an easy job for me this... no no...

getting coffee ready...


LonkeroAdministrator
(KiX Master Guru)
2002-09-16 12:36 AM
Re: KiXtart Golf V: Game24

ok, got it in head...
trying to write it in sketchboard gives me headache...

shoul eat up a lot of memory...


LonkeroAdministrator
(KiX Master Guru)
2002-09-15 01:02 PM
Re: KiXtart Golf V: Game24

jens, the 3377 got me badly.
last night scrolled it around about an hour...

anyway, as trying to solve it, let me ask some:
1) we can't use the same number more than once
2) we are to use integers, not floating point counting?


**DONOTDELETE**
(Lurker)
2002-09-15 01:07 PM
Re: KiXtart Golf V: Game24

Given the origins of the game, do you think it is fair for an answer
to be able to use Kixtarts 'Integer maths' truncation?
i.e. are the following results valid or not ?
a) '(9/2)*6-3'
b) '(9*5+4)/2'
I think we should state that the result should adhere to
'real world' (ie floating point) maths.


MightyR1
(MM club member)
2002-09-15 02:19 PM
Re: KiXtart Golf V: Game24

Oh boy...a really tough one this is...

I'm able to find solutions manually. Now finding a way to make KiX think like me...


LonkeroAdministrator
(KiX Master Guru)
2002-09-15 02:27 PM
Re: KiXtart Golf V: Game24

I skipped that option already cause wouldn't that make random number mixes?

meaning also that solution might never come up...


MightyR1
(MM club member)
2002-09-15 02:32 PM
Re: KiXtart Golf V: Game24

Hmmm, then maybe the other way around...

--> Getting myself to think like KiX [Big Grin]


Howard Bullock
(KiX Supporter)
2002-09-15 03:04 PM
Re: KiXtart Golf V: Game24

My 12 year old son plays this game in Math class. Hopefully I'll get some time today to attack this.

LonkeroAdministrator
(KiX Master Guru)
2002-09-15 03:44 PM
Re: KiXtart Golf V: Game24

hoby, you are pretty old if your son is almost the same age as I! [Big Grin]

Howard Bullock
(KiX Supporter)
2002-09-15 03:46 PM
Re: KiXtart Golf V: Game24

You better not get caught under-age drinking...or is that only a U.S. thing?

[ 15. September 2002, 15:50: Message edited by: Howard Bullock ]


LonkeroAdministrator
(KiX Master Guru)
2002-09-15 03:52 PM
Re: KiXtart Golf V: Game24

hoby, who will know if you drink at home?

and also, if you have papers which say you are 32?


Sealeopard
(KiX Master)
2002-09-15 04:05 PM
Re: KiXtart Golf V: Game24

Guys:

Just to clear up a potential point of confusion:
a) '(9/2)*6-3'
==> (9/2)*6-3 = (4.5)*6-3 = 24 is a correct answer for the combination (2,3,6,9)
b) '(9*5+4)/2'
==> (9*5+4)/2 = (45+4)/2 = (49)/2 = 24.5 is an invalid answer for the combination (2,4,5,9)

You must use 'real world' math, not the incorrect integer math module build into KiXtart.

I have updated the rules to reflect this issue.

I have also removed the EXECUTE statement that checks for correct answers since it will fail if the '/' is used and the operation results in fractions. This was an oversight in my coding since I forgot about the messed-up integer math in KiXtart.


Sealeopard
(KiX Master)
2002-09-15 04:12 PM
Re: KiXtart Golf V: Game24

Another thing. The combination (3,3,7,7) is definitely one of the harder ones to solve and the consumption of alcoholic beverages might not be able to assist successfully in finding that solution.

LonkeroAdministrator
(KiX Master Guru)
2002-09-15 06:02 PM
Re: KiXtart Golf V: Game24

just wanted to count the possibilities...
I may have counted wrong, but got result of 5040 different compinations...

 


Sealeopard
(KiX Master)
2002-09-15 06:29 PM
Re: KiXtart Golf V: Game24

That's possible [Smile]

I do know that some number combinations can be solved in 80+ ways. However, I just require one single valid combination.

For example (1,2,3,4) has a total of 98 solutions but (3+1)*(4+2) could be considered a mutation of (4+2)*(3+1). Or reformatted:
code:
(1+3)*(2+4)=24
(3+1)*(2+4)=24
(3+1)*(4+2)=24

I've been playing around with it yesterday during my class and I believe it all boils down to four generic formulas. However, you're welcome to code all 5040 unique permutations [Big Grin]


LonkeroAdministrator
(KiX Master Guru)
2002-09-15 06:34 PM
Re: KiXtart Golf V: Game24

I'm trying to, but do you understand how many loops I need there...

I already have on the paper, 17 internal loops...

you know:

for each $ in $var
for each $var in $
....
next
next

and it's getting pretty awfull!

{edit}
for the ones who do not know their path yet, I can say, this is not correct one!

I'm making too complex and now I trash everything and start from the cratch...

[ 15. September 2002, 19:07: Message edited by: Lonkero ]


Jack Lothian
(MM club member)
2002-09-15 07:17 PM
Re: KiXtart Golf V: Game24

I think that I get 18,432 permutations.

There are 4 possible places for operators ie.

Operator*number*operator*number*operator*number*operator*number

The first operator can only take on the value + or - but the other 4 can take on all 4 values. So we have 128 operator permutations.

The parenthesis generate another 6 permutations. Although this number could go higher if one considers (1+2+3+4) to be different from 1+2+3+4 or if (1)+(2)+(3)+(4) is considered to be different from 1+2+3+4.

Finally, then one can rotate the 4 numbers in the 4 positions which gives another 24 permutations.

Thus 128*6*24=18,432

I don't obviously see a way to get a solution that doesn't use brut force. I also not sure limiting the number of solutions that are desired influences the size of the code. The code must potentially search all permutations to ensure that no solutions exist. In fact, requiring only 1 soultion might increase the size of the code.

Just some thoughts.

PS. Maybe the general forum might be a better place for this competition.

[ 15. September 2002, 19:22: Message edited by: Jack Lothian ]


Sealeopard
(KiX Master)
2002-09-15 07:40 PM
Re: KiXtart Golf V: Game24

I think that the first operator is actually not necessary since it will not produce distinct solutions that cannot be achieved by other permutations.

LonkeroAdministrator
(KiX Master Guru)
2002-09-15 07:42 PM
Re: KiXtart Golf V: Game24

mmm...

I left out the first potential operator (which actually, as I thought of it, could be -)

then, situation with ()()()() is there for nothing, so didn't count that either...

the one part I don't get on the operator thing...
I got under 100 of them...

and paranthesis counted for 5 effective...


Jack Lothian
(MM club member)
2002-09-15 08:02 PM
Re: KiXtart Golf V: Game24

Jens,

True, but in general, repeat solutions can not be so easily eliminated. So, if someone can put forward a logical position for dropping a permutation or class of permutation in the analysis, this is permitted in the contest? Validation of the resultants could be difficult.

Jooel,

Parenthesis permutations:

(n n n ) n
n (n n n)
(n n) n n
n (n n) n
n n (n n)
(n n) (n n)

I got 128 operator permutations by:

2*4*4*4

but Jens' point reduces this to 4*4*4=64

thus my revised number is: 9,216.

Of course there will be many solutions that are effectively repeat solutions in these permutations. Maybe we could might try to identify methods that eliminate repeats?

Note, Jens, Commonsense says you are correct but can you put forward a proof of this point covering all permutations. The presence of divisions which are not transative and parenthesis makes this a more difficult proof than I orginally thought.

[ 15. September 2002, 20:20: Message edited by: Jack Lothian ]


Sealeopard
(KiX Master)
2002-09-15 08:11 PM
Re: KiXtart Golf V: Game24

I don't thnik you need to be concerned about repeat solutions, since I just want to have one valid solution returned. And whether that is (1+2+3)*4 or 1*2*3*4 or ((3+2)+1)*4 doesn't really matter.

LonkeroAdministrator
(KiX Master Guru)
2002-09-15 08:17 PM
Re: KiXtart Golf V: Game24

ah, forgot one in the paranthesis part...

what comes to increase the size when only one output, I think it actually decreases the size by 2-10 strokes


Jack Lothian
(MM club member)
2002-09-15 08:28 PM
Re: KiXtart Golf V: Game24

Jens,

But maybe there are cases where only solution or worse none exist. To validate these cases the algorithm must contain loops that eliminate all possibilities.

Unless one has a proof that eliminates a permutation as always being a repeat you must code for all permutations. Stopping after finding your first solution requires an IF statement. Maybe someone could make a smaller algorithm that finds all solutions but doesn't contain the if statement.


LonkeroAdministrator
(KiX Master Guru)
2002-09-15 08:53 PM
Re: KiXtart Golf V: Game24

jack, why you should stop there?

just scan trough them all...
easy, I already have the finding part in simple loop.

I actually made a bad quess and I have to check it out.
it may run for days, but will work.
if I remember correctly, there is no time limit as long as it works, right? [Razz]


Sealeopard
(KiX Master)
2002-09-15 09:06 PM
Re: KiXtart Golf V: Game24

Nope, there's no time limit. However, I've found a website containing a Game24 solver written entirely in JavaScript. It spits out the solution nearly instantaneously, thus I would not expect KiXtart to run for days [Wink]

I'm leaving now, gonna play some Squash!


LonkeroAdministrator
(KiX Master Guru)
2002-09-15 09:18 PM
Re: KiXtart Golf V: Game24

jens, it's just about different goals...

if you think there is nice source... 1000 strokes and such.
what if I can make it 200?
with just 500000 times longer run time...


Jack Lothian
(MM club member)
2002-09-15 09:35 PM
Re: KiXtart Golf V: Game24

Jens.

I presume this is the site.

24Game

It is actually tougher because it allows the 4 numbers to take on the values 1 though 13 & not 0 through 9. Also, for those interested he provides his source code. The solution is mainly in "solution.java" & "solution.class". Interesting!

This kind of strategy will find fast answers most of the time at the sacrifice of complex code.

Several of you have mentioned that your children are using the game at school. This site contains both an internet & standalone version.

PS. After looking over the above java code, I realized I forgot 1 type Parenthesis - i.e none what so ever so there are 15,232 permutations.

[ 16. September 2002, 01:34: Message edited by: Jack Lothian ]


Howard Bullock
(KiX Supporter)
2002-09-16 12:10 AM
Re: KiXtart Golf V: Game24

Game24 KiXtart Golf running under KiXtart v4.11

Numbers = 1, 2, 3, 4
Please doublecheck your solution to guarantee a correct result
24 = 24

Numbers = 2, 2, 6, 8
Please doublecheck your solution to guarantee a correct result
24 = 24

Numbers = 4, 4, 6, 6
Correct answer answer, there is no solution to this combination

Numbers = 3, 3, 8, 8
Correct answer answer, there is no solution to this combination

Numbers = 0, 3, 2, 0
No solution found
<> 24

Numbers = 3, 4, 7, 7
Please doublecheck your solution to guarantee a correct result
24 = 24

Numbers = 1, 2, 8, 9
Please doublecheck your solution to guarantee a correct result
24 = 24

Time: 1683 ticks
KixGolf score = 634

[ 16. September 2002, 00:37: Message edited by: Howard Bullock ]


Sealeopard
(KiX Master)
2002-09-16 02:05 AM
Re: KiXtart Golf V: Game24

Nice job, Howard!

You would get the First Scorer Award but for the fact that you did not return the formula. The rules state that $out should contain the formula or an empty string.

I guess, while we all were chatting away, you've been in stealth mode and coded [Big Grin]

[ 16. September 2002, 02:08: Message edited by: sealeopard ]


Howard Bullock
(KiX Supporter)
2002-09-16 03:51 AM
Re: KiXtart Golf V: Game24

Sorry, returned the wrong variable.

Game24 KiXtart Golf running under KiXtart v4.11

Numbers = 1, 2, 3, 4
Please doublecheck your solution to guarantee a correct result
(1.0*2.0)*(3.0*4.0) = 24

Numbers = 2, 2, 6, 8
Please doublecheck your solution to guarantee a correct result
2.0*(2.0+6.0)+8.0 = 24

Numbers = 4, 4, 6, 6
Correct answer answer, there is no solution to this combination

Numbers = 3, 3, 8, 8
Correct answer answer, there is no solution to this combination

Numbers = 0, 3, 3, 8
Please doublecheck your solution to guarantee a correct result
(0.0/3.0)+(3.0*8.0) = 24

Numbers = 3, 4, 7, 7
Please doublecheck your solution to guarantee a correct result
3.0+(4.0*7.0)-7.0 = 24

Numbers = 1, 2, 8, 9
Please doublecheck your solution to guarantee a correct result
(9.0-1.0)+(2.0*8.0) = 24

Time: 1152 ticks

KixGolf score = 632

{edit} KixGolf score = 518
{edit} KixGolf score = 488
{edit} KixGolf score = 470
{edit} KixGolf score = 469

[ 16. September 2002, 05:54: Message edited by: Howard Bullock ]


Sealeopard
(KiX Master)
2002-09-16 04:12 AM
Re: KiXtart Golf V: Game24

[Smile] [Smile] Nice [Smile] [Smile]

Howard will receive the First Scorer Award.


LonkeroAdministrator
(KiX Master Guru)
2002-09-17 12:40 AM
Re: KiXtart Golf V: Game24

he migth even win the first period...

and we are still lacking the company of brian...
neither is fernando here.


Howard Bullock
(KiX Supporter)
2002-09-17 12:43 AM
Re: KiXtart Golf V: Game24

I certainly don't want to be the ONLY participant.

[ 16. September 2002, 12:44: Message edited by: Howard Bullock ]


Fernando Madruga
(Starting to like KiXtart)
2002-09-16 03:42 PM
Re: KiXtart Golf V: Game24

I've been busy! [Smile]

Just found out today.
Have some cinema to catch up later, but I'll try and give this a spin afterwards...

Later,
  Madruga

P.S.: I have a couple questions:
1) Any particular reason why we're using the "old" kixgolf3 ?
2) Shouldn't the test code include the proper :! before and after the function declaration?

[ 16. September 2002, 16:24: Message edited by: Fernando Madruga ]


Sealeopard
(KiX Master)
2002-09-16 04:48 PM
Re: KiXtart Golf V: Game24

Fernando: If you have improvements to the KiXtart scoring script, then the posting of code might be better served in the scoring script thread since I will always reference that thread for the official scoring script.

[ 16. September 2002, 16:49: Message edited by: sealeopard ]


Fernando Madruga
(Starting to like KiXtart)
2002-09-16 05:25 PM
Re: KiXtart Golf V: Game24

Updated test.kix for Game24.

Too many changes to list, but I think this one has a clear output, and it's a lot easier to add new test conditions...

Please *DO* test it and post any required fixes: haven't tested it enough...

code:
BREAK ON

Global $Target

$Target = 24

$rc=SETOPTION('Explicit','ON')
$rc=SETOPTION('NoVarsInString','ON')
$rc=SRND(@MSECS)


? 'Game24 KiXtart Golf running under KiXtart v'@KIX
? ''

test24(1,2,3,4,1)
test24(2,2,6,8,1)
test24(4,4,6,6,2)
test24(3,3,8,8,2)
test24(RND(9),RND(9),RND(9),RND(9),3)
test24(3,4,7,7,1)
test24(1,2,8,9,1)
? ""

; Inputs: $i1..$i4 => 4 numbers to pass to game24
; $behaviour = 1 -> Expected result
; $behaviour = 2 -> Expected to fail
; $behaviour = 3 -> Don't know (random)
function test24($i1,$i2,$i3,$i4,$behaviour)
DIM $rc, $out, $result, $error, $str
$str = 'In => '+$i1+', '+$i2+', '+$i3+', '+$i4+'; Out => '
$out=Game24($i1,$i2,$i3,$i4)
$error=trim(Execute("$$result=("+$out+")"))
if $result = $Target
$str = $str + $out + " = " + $result
else
$str = $str + $out + " = " + $result
endif
if ( ($behaviour=1) and ($result=$Target) ) or ( ($behaviour=2) and ($result='') )
$str = $str + " => Correct!!"
else
if ( $behaviour = 3 )
$str = $str + " => Not sure..."
else
$str = $str + " => WRONG!!"
endif
endif
? $str
endfunction

Dim $shellcommand
$shellcommand='kix32 Kixgolf3.kix $f='+@scriptname
? $shellcommand
Shell $shellcommand

;!
function game24($a,$b,$c,$d)
$game24="9*3-2-1";$a+$b+$c+$d
endfunction
;!
;!

P.S. As sugested, I'll post the updated KixGolf script in the proper place.

[ 16. September 2002, 17:51: Message edited by: Fernando Madruga ]


Richard H.Administrator
(KiX Supporter)
2002-09-16 05:40 PM
Re: KiXtart Golf V: Game24

KixGolf v3.0.3 score = 446, running under KiXtart v4.11 RC 1

Howard Bullock
(KiX Supporter)
2002-09-16 06:07 PM
Re: KiXtart Golf V: Game24

aha! The game is afoot. Now to trim some more...

Richard, do you have the proper out?

[ 16. September 2002, 18:08: Message edited by: Howard Bullock ]


Howard Bullock
(KiX Supporter)
2002-09-16 07:43 PM
Re: KiXtart Golf V: Game24

KixGolf v3.0.3 score = 413, running under KiXtart v4.10
KixGolf v3.0.3 score = 401, running under KiXtart v4.10
KixGolf v3.0.3 score = 377, running under KiXtart v4.10
KixGolf v3.0.3 score = 367, running under KiXtart v4.10

[ 16. September 2002, 21:36: Message edited by: Howard Bullock ]


Jack Lothian
(MM club member)
2002-09-16 10:42 PM
Re: KiXtart Golf V: Game24

I think the validation script has a bug. I got a solution for

3,3,8,8

Game24= 8 / ( 3 - 8 / 3 )

My score is 990 - I think I have a long way to go.

[ 16. September 2002, 23:01: Message edited by: Jack Lothian ]


Sealeopard
(KiX Master)
2002-09-16 11:06 PM
Re: KiXtart Golf V: Game24

Jack:

You're right. I'll correct the test script.


Howard Bullock
(KiX Supporter)
2002-09-16 11:08 PM
Re: KiXtart Golf V: Game24

Jens, That invalidates my "first to post". I still have not found that combination. [Frown]

[ 16. September 2002, 23:08: Message edited by: Howard Bullock ]


Sealeopard
(KiX Master)
2002-09-16 11:11 PM
Re: KiXtart Golf V: Game24

I think, Jack is the first one to find this particular solution. I've checked it using one of those online Game 24 things and that one didn't find a solution either.

Never trust a computer [Wink]

This will also mean that Richard Howarth is currently recipiend of the First Scorer Award provided that his script passes the updated and corrected test script.

[ 16. September 2002, 23:13: Message edited by: sealeopard ]


Jack Lothian
(MM club member)
2002-09-16 11:22 PM
Re: KiXtart Golf V: Game24

I also get another inconsistency with Madruga's test script. His script gives:

In => 3, 3, 7, 7; Out => ( 3 + 3 / 7 ) * 7 = 21 => WRONG!!

Which is clearly incorrect.

You know, I have been playing with the math in Kixtart for almost 2 days non stop & I don't believe "execute", "val", "decimalnumber", "join", or "cdbl" generate consistent answers when you feed them various mixes of floating point numbers & integers. All seem to have some type of internal house cleaning rountines that convert all floating points that are integer values to integer values. Sometimes the results are downright bizarre & unpredicatable.

It is frustrating as hell & I had to fudge the math to make the routine work consistently.

Also, isn't adding zeros to output numbers inconsistent with the game's overall approach of dealing only with integers? My solution doesn't add zeros.

[ 16. September 2002, 23:25: Message edited by: Jack Lothian ]


Howard Bullock
(KiX Supporter)
2002-09-16 11:52 PM
Re: KiXtart Golf V: Game24

Although it appears that

$s = execute("$$v = 8.0/(3.0-8.0/3.0)") equals 24 try this:
code:
$s = execute("$$v = 8.0/(3.0-8.0/3.0)") 
? $v
if $v=24
? "hey this equals 24"
else
? "wait a minute - this does not equal 24"
endif

My code found this combination but did not see it as the correct answer.

[ 16. September 2002, 23:57: Message edited by: Howard Bullock ]


MightyR1
(MM club member)
2002-09-17 12:08 AM
Re: KiXtart Golf V: Game24

Hmm, it seems KiX has problems comparing Doubles with Longs....

Give this a try:
code:
Break on

$s = Execute("$$v = 8.0/(3.0-8.0/3.0)")
If $v=24
? "hey this equals 24"
Else
? "wait a minute - this does not equal 24"
EndIf
? ?
? " V - " $v " - " VarTypeName($v)
$v = Val($v)
? " Val V - " $v " - " VarTypeName($v)
$x = 24
? " X - " $x " - " VarTypeName($x)
$x = Val($x)
? " Val X - " $x " - " VarTypeName($x)


Get $x

Exit (0)



Jack Lothian
(MM club member)
2002-09-17 12:10 AM
Re: KiXtart Golf V: Game24

Howard, Patrick,

This is exactly the type of problem that I have been having & there seemed to be no reason for the failures. The calculations are very unstable. I try to get around this by using 2 fudge factors - 1 that I use to enforce floating point but which perturbs the accuracy. I compensate by a second fudge factor that catches values in a very narrow interval. After hours of testing it was the only consistent method that I could find. I can increase the accuracy indefinitely but at the cost of 2 characters per decimal place.

I think all of the above mentioned functions are wonky & totally unreliable with floating point. They are not even predictable.

Patrick,

You might be right Patrick but I get the sense the problem is deeper & more serious than that. For instances, there are about 5 functions for effectively executing a constructed string. If you feed them exactly the same string they give different results on occasions.

Howard,

Add 0.000001 to all your numbers & then check for a narrow range say + or - 0.0001 about 24. I bet it will work. Absolutely everything must be floating point though. Even the 24 must be written as 24.0.

This is kind of like practicing voodoo in my opinion but it does give consistent results.

Jens,

I think your challange may have pushed kixtart beyond its capabilities.

[ 17. September 2002, 00:21: Message edited by: Jack Lothian ]


Howard Bullock
(KiX Supporter)
2002-09-17 12:20 AM
Re: KiXtart Golf V: Game24

Not sure why this works:

code:
$s = Execute("$$v = 8.0/(3.0-8.0/3.0)")
If cint($v)=24
? "hey this equals 24"
Else
? "wait a minute - this does not equal 24"
EndIf

and this does not:
code:
$s = Execute("$$v = 8.0/(3.0-8.0/3.0)")
If $v=cdbl(24)
? "hey this equals 24"
Else
? "wait a minute - this does not equal 24"
EndIf

I guess changing to an INT just plain easier to do..

[ 17. September 2002, 00:36: Message edited by: Howard Bullock ]


Jack Lothian
(MM club member)
2002-09-17 12:36 AM
Re: KiXtart Golf V: Game24

Howard,

My experience is that with out the fudge factors you get trade offs. You can increase the prediction of correct responses but only at the cost of lossing reliability at predicting non-solutions. Many times in the last 48 hours, I thought I had found the answer only to discover the new solution didn't work with other solutions.

To be truthful, I am not sure my algorithm is 100% accurate but it worked on the several dozen examples that I had on hand. I though of exporting all the permutations to excel so I could test the forumala in an environment that is reliable but I haven't had time to test that idea yet.


LonkeroAdministrator
(KiX Master Guru)
2002-09-17 12:44 AM
Re: KiXtart Golf V: Game24

yep, ran this little test script to find the leak:
code:
$s = Execute("$$v = 8.0/(3.0-8.0/3.0)")
$=cdbl(24)
if $<$v
$diff=$v-$ "24 is smaller by:"
else
$diff=$-$v "24 is bigger by:"
endif
$diff=$diff*1000000
$diff=$diff*1000000
$diff
" / 1000 000 000 000"

get $

and it did not suprise me at all.

{edit}
I quess I might add the output of it too:
24 is bigger by:0,0106581410364015 / 1000 000 000 000

[ 17. September 2002, 00:46: Message edited by: Lonkero ]


Jack Lothian
(MM club member)
2002-09-17 01:22 AM
Re: KiXtart Golf V: Game24

Lonkero,

I think we are running into 2 problems. Fist as you say there is a leak but also Ruud's string parsing functions for math strings probably has other holes. His routines seem to convert floating point into integer in very caprious ways. Both Join & Execute strip all unnecessary zeros from your code so it is very hard to force either function to do floating point math. My experiments seem to indicate that execute & join are actually more bullet proof than formatdecimal or cdbl. These results that come out of these functions are really weird. These holes in these parsing routines even effect more mundane functions like the if statement.

The combination of these various problems seems to create a version of the Heisenburg uncertainy principle in kix. Very accurate matches can only be identified in a probabilistic sense.


Sealeopard
(KiX Master)
2002-09-17 01:31 AM
Re: KiXtart Golf V: Game24

Damn, I think I know what it is. Has anybody every heard of EPS?

EPS = Floating point relative accuracy. EPS is a permanent variable whose value is initially the distance from 1.0 to the next largest floating point number.

Basically, in order to display any give number in a discreet numbering system, it has to be converted into that numering system. And based on the number of bits used in that system you end up with a specific number which is the smallest number that can be displayed.

For example, assuming an integer numbering system, EPS equals 1 since the next higher number from 1 is 2. Any number in beweeen 1 and 2 that is to be converted to the integer system will thus end up being either 1 or 2. Which one it is, is being governed by conventions, e.g. IEEE definitions.

Another example, in Matlab, a mathematical scripting language, EPS=2.2204e-016 for floating point math. This means any number smaller than EPS cannot be displayed, it will either be rounded down to 0 or up to EPS. It also means that certain numbers cannot be displayed without some (small) loss. Thus, if I calculate 0.0001*3 - 0.0003 in discreet floating point math I will get a result of 5.4210e-020 and not '0'.

I hope everybody is still with me on this?

Anyway, I don't think there's anything we can do about this since it's a limitation of the underlying number conversion system.


Howard Bullock
(KiX Supporter)
2002-09-17 01:38 AM
Re: KiXtart Golf V: Game24

Now that this behavior has been defined, should we defined that the calculated value of the input be close to 24 within some specified range?

Sealeopard
(KiX Master)
2002-09-17 01:53 AM
Re: KiXtart Golf V: Game24

If you put a CINT around the resulting value, then that should go back to an integer 24.

Also, I just ran this little script and it works fine.
code:
Break on

$a='(cdbl(3)+cdbl(3)/cdbl(7))*cdbl(7)'

$rc=execute('$$b='+$a)

? 'Result = '+$b

? 'Result = '+($b=24)

? 'Result = '+vartypename($b)

with output
code:
Result = 24
Result = 1
Result = Double



Howard Bullock
(KiX Supporter)
2002-09-17 02:02 AM
Re: KiXtart Golf V: Game24

This fails:
code:
$a='cdbl(8)/(cdbl(3)-cdbl(8)/cdbl(3))'
$rc=execute('$$b='+$a)
? 'Result = '+$b
? 'Result = '+($b=24)
? 'Result = '+vartypename($b)

This works (in this case):
code:
? 'Result = '+(cint($b)=24)  



[ 17. September 2002, 02:04: Message edited by: Howard Bullock ]


Howard Bullock
(KiX Supporter)
2002-09-17 02:07 AM
Re: KiXtart Golf V: Game24

This is obviously wrong but with CINT is passes:
code:
$a='(cdbl(3)/cdbl(8))+cdbl(8)*cdbl(3)'

$rc=execute('$$b='+$a)
? 'Result = '+$b
? 'Result = '+(cint($b)=24)
? 'Result = '+vartypename($b)



[ 17. September 2002, 02:08: Message edited by: Howard Bullock ]


Fernando Madruga
(Starting to like KiXtart)
2002-09-17 02:07 AM
Re: KiXtart Golf V: Game24

Jack, I don't quite get it when you say:
quote:

I also get another inconsistency with Madruga's test script. His script gives:

In => 3, 3, 7, 7; Out => ( 3 + 3 / 7 ) * 7 = 21 => WRONG!!

Which is clearly incorrect.

Why is that incorrect? If I use integer math, then 3 / 7 = 0, + 3 = 3, * 7 = 21... Have I forgotten something from school?
Surelly that is not the intended result!
You may be induced in error by the "WRONG!" part: it does not mean that the expression is wrong, it only means that that expression does not evaluate to the expected result of 24...

P.S.: I'm still trying to figure out a decent algorithm... When I do, I'll sure as hell post the results here... [Smile]

[ 17. September 2002, 02:08: Message edited by: Fernando Madruga ]


Jack Lothian
(MM club member)
2002-09-17 02:18 AM
Re: KiXtart Golf V: Game24

True but one of jens primary goals was to use real number math not just integer number math. It was in this context, I felt was it was incorrect.

Jack Lothian
(MM club member)
2002-09-17 02:23 AM
Re: KiXtart Golf V: Game24

Interestingly, I stripped 100 characters out of my code mainly through eliminations of cdbl's & at about character 98, my script started to fail again. Got put them all back in I guess.

Fernando Madruga
(Starting to like KiXtart)
2002-09-17 02:43 AM
Re: KiXtart Golf V: Game24

Oops...

I missed that "real math" thing... [Smile]

Anyway, here's the revised script.

code:
BREAK ON

Global $Target

$Target = 24
$ErrorMargin = 0.0001

$rc=SETOPTION('Explicit','ON')
$rc=SETOPTION('NoVarsInString','ON')
$rc=SRND(@MSECS)


? 'Game24 KiXtart Golf running under KiXtart v'@KIX
? ''

test24(1,2,3,4,1)
test24(2,2,6,8,1)
test24(4,4,6,6,2)
test24(3,3,8,8,2)
test24(RND(9),RND(9),RND(9),RND(9),3)
test24(3,4,7,7,1)
test24(1,2,8,9,1)
test24(3,3,7,7,1)
? ""

; Inputs: $i1..$i4 => 4 numbers to pass to game24
; $behaviour = 1 -> Expected result
; $behaviour = 2 -> Expected to fail
; $behaviour = 3 -> Don't know (random)
function test24($i1,$i2,$i3,$i4,$behaviour)
DIM $rc, $out, $result, $error, $str, $i
$str = 'In => '+$i1+', '+$i2+', '+$i3+', '+$i4+'; Out => '
$out=Game24($i1,$i2,$i3,$i4)
$i = 1
while $i <= Len($out)
if ( SubStr($out,$i,1) >= '0' ) and ( SubStr($out,$i,1) <= '9' )
$out = Left($out,$i) + '.0' + SubStr($out,$i+1)
$i = $i + 2;
endif;
$i = $i + 1;
loop
$error=Execute("$$result=("+$out+")")
$result=Trim($result)
$str = $str + $out + " = " + $result
if ( $behaviour = 3 )
$str = $str + " => Not sure..."
else
if ( ($behaviour=1) and ($result>=$Target-$ErrorMargin) and ($result<=$Target+$ErrorMargin) ) or ( ($behaviour=2) and ($result='') )
$str = $str + " => Correct!!"
else
$str = $str + " => WRONG!!"
endif
endif
? $str
endfunction

Dim $shellcommand
$shellcommand='kix32 Kixgolf3.kix $f='+@scriptname
? $shellcommand
Shell $shellcommand

; Operators: 64 combinations
; +++ ++- ++* ++/ +-+ +-- +-* +-/ +*+ +*- +** +*/ +/+ +/- +/* +//
; -++ -+- -+* -+/ --+ --- --* --/ -*+ -*- -** -*/ -/+ -/- -/* -//
; *++ *+- *+* *+/ *-+ *-- *-* *-/ **+ **- *** **/ */+ */- */* *//
; /++ /+- /+* /+/ /-+ /-- /-* /-/ /*+ /*- /** /*/ //+ //- //* ///

; Digits: 24 permutations
; abcd abdc acbd acdb adbc adcb
; bacd badc bcad bcda bdac bdca
; cabd cadb cbad cbda cdab cdba
; dabc dacb dbac dbca dcab dcba

; Parentheses: 7 combinations
; (ab)(cd)
; (ab)cd
; (abc)d
; a(bc)d
; a(bcd)
; ab(cd)
; abcd

;!
function game24($a,$b,$c,$d)

endfunction

;!
;!

Being such a big problem, I'd sugest to this group to come up with a 100% working solution for finding the answer and adding a function named checkresult or something else to the test program that would take the {edit}expression{/edit} and return true if the result is the expected one. One should be allowed to use that function in one's code, so as to save a lot of cdlbs/ints/adding error margins/whatevers to the code. I think we all could benefit from that... Not only in the interest of making one's code shorter, but mainly in making it a lot more readable and focusing on the problem at hand, instead of in ways to best deal with what seems to be some incongruencies in the language itself...

Just my two cents...

{edit} removed poll {/edit}

[ 17. September 2002, 20:39: Message edited by: Fernando Madruga ]


Jack Lothian
(MM club member)
2002-09-17 03:10 AM
Re: KiXtart Golf V: Game24

If there are 11 combinations of brackets my script is wrong since I only had 7. It is easy to fix but it would add another 100 characters to my script.

Initially, I thought the extras were just simple rotations of the orginal 7 but I could be wrong. The java script on the web only deals with 7 basic permutations as well. I am too tired right now to worry it out though.

As to your question, all contributions are welcome but this is just a fun thing & I don't think we need to over do it.


Howard Bullock
(KiX Supporter)
2002-09-17 03:21 AM
Re: KiXtart Golf V: Game24

The criteria that matters is does it pass the tests that Jens lays out. This is not suppose to be a perfect algorithm or data engine.

[ 17. September 2002, 03:22: Message edited by: Howard Bullock ]


MightyR1
(MM club member)
2002-09-17 10:41 AM
Re: KiXtart Golf V: Game24

Madruga and others,

can you give me an example why "((ab)c)d" is also a combination?
I think it's the same as "(ab)cd"

Also the number of operator permutations I think is 128.
Why? check this:

-1*-4*-2*-3

So the possible permutations are 2*4*4*4=128


Richard H.Administrator
(KiX Supporter)
2002-09-17 11:03 AM
Re: KiXtart Golf V: Game24

KixGolf v3.0.3 score = 449, running under KiXtart v4.11 RC 1
Time taken (ticks): 10003, Pentium Pro 180.

Passes all tests, including finding a solution for "3,3,8,8"

{edit} I only fixed the "3,3,8,8" when I saw the messages about an hour ago, so I guess Jack is first to post with a correct solution {/edit}

[ 17. September 2002, 11:09: Message edited by: Richard Howarth ]


LonkeroAdministrator
(KiX Master Guru)
2002-09-17 11:48 AM
Re: KiXtart Golf V: Game24

pat, if you read our older posts, you would see discussion on this issue.
isn't:
-1*-4*-2*-3

just the same as:
1*4*-2*-3


MightyR1
(MM club member)
2002-09-18 12:27 AM
Re: KiXtart Golf V: Game24

Jooel,

the result is the same, but the formula isn't:

I like it when it't 20 degrees Celsius outside, but when it's -20 degrees I'd rather stay inside!!! [Big Grin]


Fernando Madruga
(Starting to like KiXtart)
2002-09-17 01:08 PM
Re: KiXtart Golf V: Game24

quote:

can you give me an example why "((ab)c)d" is also a combination?
I think it's the same as "(ab)cd"

I guess you're right... I was just laying down all the choices, so I could later "trim"/simplify them.

It looks as if the outer parentheses will only make sense if the operator before 'c' is a low precedence one (+ or -); if that is the case, then the inner parentheses will not be needed and so becomes '(abc)d'... On the other hand, if it's a high precedence one (* or /) then the outer parentheses will not be needed and it becomes '(ab)cd'...

Maybe those 7 cases someone else pointed out as being used by the java applet will be enough... Haven't checked into it yet though...


Richard H.Administrator
(KiX Supporter)
2002-09-17 01:17 PM
Re: KiXtart Golf V: Game24

Maybe I'm missing something...
(1+2)+3/3 = 4
((1+2)+3)/3 = 2


Howard Bullock
(KiX Supporter)
2002-09-17 01:37 PM
Re: KiXtart Golf V: Game24

KixGolf v3.0.3 score = 413, running under KiXtart v4.10

Sealeopard
(KiX Master)
2002-09-17 02:15 PM
Re: KiXtart Golf V: Game24

I think I've found a solution with the rounding problems when using CDBL. I can reformat a formula in such a way that it does not require doubles but only integers. This method could be used for those permutations where fractions might show up as interim results.
code:
                  3
(3+3/7)*7 = ( 3 + - ) * 7
7

3 * 7 + 3
= ( --------- ) * 7
7

= ( 3 * 7 + 3 ) / 7 * 7

= ( 3 * 7 + 3 ) * 7 / 7

= 24

or generic

(a+b/c)*d = ( a * c + b) * d / c

By essentially moving the division I end up with an integer devidied by an integer.

[ 17. September 2002, 14:16: Message edited by: sealeopard ]


Jack Lothian
(MM club member)
2002-09-17 02:21 PM
Re: KiXtart Golf V: Game24

Jens,

I woke up this morning thinking the same as Richard. Madruga's 4 extra combination are legitimate & different.

What I also realized is Madruga is fundamentally changing the rules of the game since he is permitting nested parenthesis. Note in all examples of the school game on the web, there is either a template or rules that don't permit nested parenthesis or multiple operaters between numbers.

While your rules might permit nested parenthesis most of us picked up on the fact you wanted us to solve the standard school template. You might clarify this point.


Jack Lothian
(MM club member)
2002-09-17 02:29 PM
Re: KiXtart Golf V: Game24

Jens,

We can have up to 3 divisions though & they can be placed within & without parenthesis & in various combinations with other operators. While I think you are correct in saying that we could recast all so that decimal math was unneeded, programming all the continuances could be a major undertaking. Just identifying all the division patterns plus their alternatives might be a several day project.

Also to avoid decimal math your solution needs to go one step further. If your final result is a fraction, you need to check if the denominator is a factor in the numerator. If it is, then integer division can be used to verify compliance with 24 & otherwise it can not be a solution since the result is non integer.

[ 17. September 2002, 14:36: Message edited by: Jack Lothian ]


Fernando Madruga
(Starting to like KiXtart)
2002-09-17 02:30 PM
Re: KiXtart Golf V: Game24

quote:

Maybe I'm missing something...
(1+2)+3/3 = 4
((1+2)+3)/3 = 2

You are indeed... The 2nd example does NOT need the inner brackets: (1+2+3)/3 = 2...


Richard H.Administrator
(KiX Supporter)
2002-09-17 02:37 PM
Re: KiXtart Golf V: Game24

Aha. Got it.

KixGolf v3.0.3 score = 423, running under KiXtart v4.11 RC 1

{edit}
KixGolf v3.0.3 score = 414, running under KiXtart v4.11 RC 1

[ 17. September 2002, 14:53: Message edited by: Richard Howarth ]


Fernando Madruga
(Starting to like KiXtart)
2002-09-17 02:40 PM
Re: KiXtart Golf V: Game24

As for the rounding error question, I don't think we'll have too much trouble with it. Just check the result to be within an error margin as I did in my version of the test program. It should work for all situations: with just 3 operations, you will surelly not have an error THAT big... Besides, with only 4 1-digit numbers and 3 operations, you would not arrive to a "near-perfect" score unless it's a correct answer...

As for the nested parentheses, in fact I had not noticed that I'd raise such an issue! [Smile] As I said in another post, I was simply laying down the options to have a clearer view of the problem and potential solutions... Being as it is, that this is a "game" about program size and not efficiency, I may as well end up using all parentheses if that simplifies my code in any way... [Smile]


Fernando Madruga
(Starting to like KiXtart)
2002-09-17 02:57 PM
Re: KiXtart Golf V: Game24

Did some checking: my verification for the example nested parentheses seems to hold true for all the other nested parentheses! So, it looks as if they are not needed as any expression using them can be rewriten using only one set instead of two... In that case, we get left with only 7 diferent cases... [Smile] Does that 7 ring a bell on anyone? [Smile]

Richard H.Administrator
(KiX Supporter)
2002-09-17 03:24 PM
Re: KiXtart Golf V: Game24

KixGolf v3.0.3 score = 409, running under KiXtart v4.11 RC 1
Runs much slower now though.


Howard Bullock
(KiX Supporter)
2002-09-17 03:28 PM
Re: KiXtart Golf V: Game24

Well it looks like it's back to the drawing board. [Wink]

Fernando Madruga
(Starting to like KiXtart)
2002-09-17 03:37 PM
Re: KiXtart Golf V: Game24

I think we can rule out one of the 7 situations: a(bcd).

{EDIT} BOY! Was I wrong on this one!!! Read below... {/EDIT}

Why? Follow me...
We can have one of 4 operators between 'a' and the rest of the expression.

code:
a+(bcd) -> (bcd)+a  : does not matter what ops are inside as
+ is low precedence

a-(bcd) -> nothing! : What kind of expression would you need
inside parens to get 24 by subtracting
to 0..9?? Yes, I know that 0-(-something)
will be positive, but we can't have another
negative number inside the parens!!!
{edit} Actually, we can, but it does not create a solution! {/edit}
{edit} And it can be rewritten as not to need the parens! {/edit}

a/(bcd) -> nothing! : Again, what kind of number would we need
inside parens to get 24? A very small number!
In order to be so, we'd need something like
a/(b/c/d) because a/(b+c/d) or a/(b/c+d) would
not give a number below 1 unless the added item
was 0 and even then it would not be "small enough"
to get 24... (hope you're still following me!)
If we did not use a / inside the parens, then
the number would not be between 0 and 1 and so,
dividing a number from 1 to 9 by it would not
yield the needed result! Finally, a/(b/c/d) can
be simplified as a/b/c/d !!!

a*(bcd) -> (bcd)*a : We will arrive at this test case sooner or later!
So, no need to handle it in here.

Please check my assumptions, but I do believe that a(bcd) can be safely
left out of the game as we're not trying to get ALL solutions but just
ONE!

The same may hold true for more cases, but I have to go now. I'll check
the others later...

[ 18. September 2002, 02:06: Message edited by: Fernando Madruga ]


Jack Lothian
(MM club member)
2002-09-17 03:53 PM
Re: KiXtart Golf V: Game24

Well Richard, I think I must conceed, you gone to far. I think I could bring my score down but 400 is out of reach with the approach I chose. I am looking forward to seeing your solution.

Jack Lothian
(MM club member)
2002-09-17 04:00 PM
Re: KiXtart Golf V: Game24

Madruga

What about 8/(1*1/4)? Of course you could restructure this & get a large number of alternatives but in general duplicates always exist & eliminating them is more challanging than solving the problem.

[ 17. September 2002, 16:04: Message edited by: Jack Lothian ]


Fernando Madruga
(Starting to like KiXtart)
2002-09-17 04:03 PM
Re: KiXtart Golf V: Game24

quote:

Madruga

What about 8/(1*1/4)?

=> 8*4+1-1 is another valid solution to be found without using parens...


Richard H.Administrator
(KiX Supporter)
2002-09-17 04:04 PM
Re: KiXtart Golf V: Game24

Jack,
Keep going. It's surprising what you can strip out after staring at the code for 10 minutes.

And you never know, I may have violated some rule which will invalidate the code.

But just to keep you on your toes...

KixGolf v3.0.3 score = 404, running under KiXtart v4.11 RC 1


Sealeopard
(KiX Master)
2002-09-17 05:07 PM
Re: KiXtart Golf V: Game24

Comment to the use of parenthesis, so far I've only seen the use of exactly three operators and either zero, one, or two sets of parentheses. Examples:
0 = a+b+c+d
1 = (a+b/c)*d
2 = (a+b)*(c+d)

Also, I do not think that there is a need for nested parentheses since I have not been able to find a formula that require a nested parenthesis and which cannot be rewritten without the need of a nest parenthesis.

For example ((a/b)*c)+d = (a/b*c)+d.


MightyR1
(MM club member)
2002-09-17 09:59 PM
Re: KiXtart Golf V: Game24

TomTieDom, [Confused]

found something else what surprised me:

code:
$a='cdbl(8)/(cdbl(3)-cdbl(8)/cdbl(3))'
$rc=Execute("$$b=$a")
? 'Result $$b = '$b
? 'Result 24=$$b = '+(24=$b)
? 'Result $$b=24 = '+($b=24)
? 'Result type = '+VarTypeName($b)

comes up with
code:
Result $b    = 24
Result 24=$b = 1
Result $b=24 = 0
Result type = Double

[Confused] [Confused]

Does anyone have an explaination for this behaviour???


Jack Lothian
(MM club member)
2002-09-17 10:02 PM
Re: KiXtart Golf V: Game24

God richard,

I don't know how you got to 400. After 2 more hours work I am at 721.


Jack Lothian
(MM club member)
2002-09-17 10:06 PM
Re: KiXtart Golf V: Game24

Kixtart sets variable type from left to right I believe. Thus in the first test you are doing an integer test & in the second a floating point check. As lonkero has shown floating point has a leak. Thus the comparison fails.

Thank you Patrick,

Your example did it for me. The execute statement must literally see the cbdl function surrounding all 4 numbers for it to work consistently. I got rid of my fudge factor & I am down to a score of 702.

[ 17. September 2002, 22:50: Message edited by: Jack Lothian ]


Fernando Madruga
(Starting to like KiXtart)
2002-09-18 01:09 AM
Re: KiXtart Golf V: Game24

I've been doing some perl experiments... Did you know that there are 465 unique 4 number combos that will evaluate to 24 according to the rules? (0038,0308,0380,... and all it's permutations all count as one).

Also, of all these possible 465 solutions:
code:
  13 (unlucky number!) depend on having two sets of (), that is (ab)(cd)
131 depend on having at least one '+'
174 depend on having at least one '-'
306 depend on having at least one '*'
36 depend on having at least one '/'

By now, it's clear to you guys: I was trying to simplify the algorithm by not including something!!!

Just thought to share my findings with you guys. Haven't coded a single KiXtart line yet... [Smile]

[ 18. September 2002, 01:09: Message edited by: Fernando Madruga ]


LonkeroAdministrator
(KiX Master Guru)
2002-09-18 01:27 AM
Re: KiXtart Golf V: Game24

fernando, as I got my papers... 3 of them filled up of plans how to do it, I decided to give up.

and surely did the right thing. now I can spend my nights doing something usefull [Big Grin]


Fernando Madruga
(Starting to like KiXtart)
2002-09-18 02:00 AM
Re: KiXtart Golf V: Game24

You're not on this one? That's bad...

It's fun... It's my 1st one from "scratch": all I did in the last one was
crop some bytes out of someone else's code...
Maybe I'll do some coding this time... [Smile]

I did however continue my findings:
code:
   0 need (ab)cd
0 need a(bc)d
0 need ab(cd)
------------------
1 need (abc)d
------------------
3 need a(bcd)
13 need (ab)(cd)
------------------
131 need at least one '+'
174 need at least one '-'
306 need at least one '*'
36 need at least one '/'

So, and for the purpose of this game that is to find ONE
(repeat: ONE) solution, we can eliminate these constructs:
(ab)cd, a(bc)d, ab(cd).

The (abc)d construct is only used for these numbers
(and respective permutations): 1277 == (7*7-1)/2.

The a(bcd) construct is needed for these 3 sets:
1346 == 6/(1-3/4); 1456 == 6/(5/4-1); 1668 == 6/(1-6/8)

As for the (ab)(cd), 13 is too much to test for...
Even 3 may prove to be too much! [Smile]

Hope this helps you guys, even though I may be shooting myself in the foot,
but hey! this is just a friendly competition...

Gonna do some work, then sleep over it. I'll probably only get back to this
in some 48 hours or so to start (and finish) my coding for this one, so
don't be surprised if you don't read from me for a couple of days...

[ 18. September 2002, 17:31: Message edited by: Fernando Madruga ]


Jack Lothian
(MM club member)
2002-09-18 06:29 PM
Re: KiXtart Golf V: Game24

A problem …

After thinking on the issues discussed above, I believe several of the points brought up by Jens are important for this project. This basic problem is a topic that was talked about a lot in the 50s through the 70s. During this period most mainframes were IBM which had a ridiculously low word size of 4 bytes. This limited the size & accuracy of all numbers. If I remember, it limited integers to 9 digits & floating point to an accuracy of 7 digits. After this point you got an integer overflow or truncation in floating point.

The serious problems occur when you divide by a prime number & the result generates a repeating decimal pattern. Floating point math on a computer must truncate the pattern & thus internally the result is inaccurate.

An example: (3.0/7.0)*(7.0/3.0) will not generate 1 in most computer languages. Instead it will generate a decimal number very close to 1. Converting the resultant to integer will not produce exact results with any type of “int” function since the value in general can be above 1 or below 1 & with higher level primes the distance from 1 can get larger. Rounding doesn’t help because it can’t tell the difference between 0.5 or 0.99999 or 1.00001 or 1.49999.

Another factor is the mixing of operations types in floating point math. For multiplication or division, a scientific notation representation of the numbers gives the greatest accuracy but you can not add two scientific numbers so for addition floating point arithmetic uses pseudo integer formalism. This implies resultant decimal accuracy of an addition/subtraction is equal to the lowest accuracy of the 2 numbers.

Thus we get things like: 20*(1.0/3.0) + (1.0/3.0) = 20*(0.333333)+(0.3333333)= 6.9999933

Note as you increase the size of the leading multiplier the inaccuracy increases.

The 2 above factors tend to produce floating point resultants that have small pseudo random numbers added to them. This is why exact compares in floating point tend not to work. The problem worsens as the number of potential primes increases and the size of the numbers increase. If we had been asked to do another common variant of the game that uses a deck of cards then we might have all noticed the problem sooner because it uses a number range of 1 to 13 which includes 2 extra & larger primes.

The solution …

I have come to the conclusion that Jens point about not using decimal math is an absolute requirement for the routine to work consistently. All calculations must be done in integer math & this means all divisions must be re-structured as Jens suggested above so that division is never done unless the final result will be an integer.

A note to Madruga …

If you used floating point math in your perl script you can not be sure you found all solutions correctly.


Fernando Madruga
(Starting to like KiXtart)
2002-09-19 12:58 AM
Re: KiXtart Golf V: Game24

Well, I could rewrite it to use some kind of "infinite" precision math routines: it would probably take a few days instead of some minutes, but would not fail...

However, you have to look at floating point math in another way: is the PC's floating point accuracy enough to overcome potential "rounding" errors? I think that, in this case, where we have only 4 numbers in the range 0..9 and 3 (THREE!) operations, any inacuracy that is introduced is certainly VERY close to 0, that is, below 0.000001 or most likely even lower than that.

Today's computers conforms to IEEE 8 byte floating point math: it's inexpensive (processing wise due to the builtin math coprocessor) and has "decent" accuracy (don't feel like digging some specs now!).

If you consider that, with only 3 operators, and something like 10+ decimal places of accurate calculation you will SURELY not have an error above the 8th decimal digit, I assume that testing for 24 within 1^-6 is most likely enough...

Also, I don't know how to prove this mathematically, but you would not get a number THAT close to 24 with only these 4 digits & 3 operators...

I'll do the following: I'll change my generator program to save ALL possible combinations regardless of whether they evaluate to near 24 or not, and I'll then see what is the number that comes closer to 24, without actually being 24 and that shouldn't be 24.

I'll post the results later...

[ 19. September 2002, 01:00: Message edited by: Fernando Madruga ]


Howard Bullock
(KiX Supporter)
2002-09-19 01:23 AM
Re: KiXtart Golf V: Game24

Has everyone lost sight of what the purpose of this exercise is? Take a problem with a set of specific given criteria, mix in some KiXtart ingenuity, comradery, and FUN. Uncover some shortcuts, inconsistencies, workarounds, etc. Satisfy the given requirements not all possible requirements. After we play & learn a little, the code can then be written in a percise bulletproof fashion. We are still in the FUN stages. Don't scare away those that don't share is the enthusiasm for extremes.

Fernando Madruga
(Starting to like KiXtart)
2002-09-19 01:44 AM
Re: KiXtart Golf V: Game24

I second that Howard!

The only reason I wrote the perl program to compute all possible solutions, was because I figured that, being a small and easily computable set, I could perhaps simplify the algorithm! I did, as 3 types of parentheses constructs can be safely eliminated!

BTW: I'm now running the "updated" script, that will save all possible values, correct or not, but I'm doing this only for fun! I want to know if I'm right in my previous post...

Meanwhile, and this is not to blame Ruud, perl's floating point implementation is a LOT more robust: I ported the exact same script to KiXtart and (while taking loads more time to run! [Smile] ), it only found less than half the solutions! In fact, for some numbers, it wasn't even able to find ANY solution when the perl script DID find at least one! [Smile]

Again, KiXtart is certainly *not* the best tool for this "game" in case you're taking it a bit too serious, but it's a good tool for loads of other stuff!


Jack Lothian
(MM club member)
2002-09-19 01:52 AM
Re: KiXtart Golf V: Game24

howard,

Being a mathematician, I have a tendency to get over involved in anything that has to do with math. Thanks for the reminder.


Richard H.Administrator
(KiX Supporter)
2002-09-19 09:29 AM
Re: KiXtart Golf V: Game24

I kinda like the high-brow tangents these things fly off into.

There is always the danger I might learn something new, and to a jaded techie that's one of the major bonuses of this board.

The code I have does *not* work with all possible combinations - it only finds 422 of Fernando's 465.

It's been crippled because of keeping the size down. In the processes I've also doubled the time that it takes to run, just to save 2 characters.

However, it does adhere to the rules and gives the correct results [Razz]

It's also given me a corker of a UDF that I'll publish once the first round is over. It is so cute I'm going to name my first-born after it.


LonkeroAdministrator
(KiX Master Guru)
2002-09-19 09:33 AM
Re: KiXtart Golf V: Game24

yeah...
this chit chat is nice reading especially when it's weekend.
allthough, I think we should do next golf on general so this mumble can't get off topic in anyway... [Wink]


Fernando Madruga
(Starting to like KiXtart)
2002-09-19 10:48 AM
Re: KiXtart Golf V: Game24

Well Howarth, if it does not find all 465, it is bound to fail some tests, as one of them is a random one! [Smile]

Being 422 aprox. 91% of 465, it's bound to fail on 1 out of 10 (avg) runs... [Smile]

Just to let you know... [Smile]


Fernando Madruga
(Starting to like KiXtart)
2002-09-19 11:06 AM
Re: KiXtart Golf V: Game24

As promised, here are the numbers that evaluate closer to 24:

code:
23.8
23.8333333333333
23.8571428571429
23.875
23.8888888888889
24.1111111111111
24.125
24.1428571428571
24.1666666666667
24.2

As you can see, the closest ones are 23.8888888888889 and 24.1111111111111. They are VERY far from the needed 24 result, so we could even just check for 23.9
I think that this particular info may be of interest to all that are "fighting" with this game... [Smile]

[ 19. September 2002, 11:17: Message edited by: Fernando Madruga ]


Richard H.Administrator
(KiX Supporter)
2002-09-19 11:09 AM
Re: KiXtart Golf V: Game24

True.

The point is that it passes the tests. The tests may be flawed, but the code passes them. The random "test" is pointless because it does not evaluate the truth of the answer - any response is correct.

Besides, those 1 in 10 chances occur less often than you think [Wink]

On a completely different note, I won't be able to post the code until Tuesday - a bit late really.

Does anyone not actively participating want to hold it for me and post it when this coding phase closes?


Fernando Madruga
(Starting to like KiXtart)
2002-09-19 11:31 AM
Re: KiXtart Golf V: Game24

quote:

The point is that it passes the tests. The tests may be flawed, but the code passes them. The random "test" is pointless because it does not evaluate the truth of the answer - any response is correct.

Sorry to disagree with you on this one, but "any response is correct" is not true! You're suposed to check the provided result! And if you "cheat" by "looking the other way" on the random test, you'll fail to comply with the given objectives!

Besides, I might take some minutes out of my lunch hour to improve "my" version of the test program so that it "fixes" that manual input... [Smile]


LonkeroAdministrator
(KiX Master Guru)
2002-09-19 11:38 AM
Re: KiXtart Golf V: Game24

mmm...

I think the test script should contain more than one random...
maybe even 10-20 randoms in the row.

it's not hard to check if the answer is correct or not...
 


Richard H.Administrator
(KiX Supporter)
2002-09-20 12:01 AM
Re: KiXtart Golf V: Game24

quote:
Sorry to disagree with you on this one, but "any response is correct" is not true! You're suposed to check the provided result! And if you "cheat" by "looking the other way" on the random test, you'll fail to comply with the given objectives!
It's not cheating, it's taking advantage of a loophole.

If the code correctly responds to the random numbers when run it passes the test *and* it complies with all the given objectives.

Having said all that, I don't see why the test script shouldn't check for all the valid permutations that you've found so far, except that it would take quite a long time to run, and it doesn't leave much time to tighten up existing code. (some of us have to sneak this is in during quiet moments at work, heh).

An exhaustive test would also enumerate all the invalid values, to be sure that a formula is not returned in that case.


Howard Bullock
(KiX Supporter)
2002-09-19 02:54 PM
Re: KiXtart Golf V: Game24

I have lost track of the standings so far and am reposting my current score considering most of the previous discussion.

quote:
Game24 KiXtart Golf running under KiXtart v4.11

Numbers = 1, 2, 3, 4
Please doublecheck your solution to guarantee a correct result
(1.0+2.0+3.0)*4.0 = 24

Numbers = 2, 2, 6, 8
Please doublecheck your solution to guarantee a correct result
(2.0+6.0)+8.0*2.0 = 24

Numbers = 4, 4, 6, 6
Correct answer answer, there is no solution to this combination

Numbers = 3, 3, 8, 8
Please doublecheck your solution to guarantee a correct result
8.0/(3.0-8.0/3.0) = 24

Numbers = 0, 5, 9, 5
No solution found
<> 24

Numbers = 3, 4, 7, 7
Please doublecheck your solution to guarantee a correct result
(3.0+4.0*7.0)-7.0 = 24

Numbers = 1, 2, 8, 9
Please doublecheck your solution to guarantee a correct result
(8.0*9.0)/(2.0+1.0) = 24

Time: 8232 ticks

KixGolf v3.0.3 score = 542, running under KiXtart v4.10

C:\Data\Scripts\Golf>C:\Data\Kix2001\KiX2001.411\kix32 golf4.kix

My code is using 5 different sets of "()", checking all permutation of operators, and all permutations of numbers.

If anyone can prove that more "()"'s are needed, I can add a set of "()"'s with 6 strokes.

I still need to optimize a little.

[ 19. September 2002, 14:55: Message edited by: Howard Bullock ]


Jack Lothian
(MM club member)
2002-09-19 03:03 PM
Re: KiXtart Golf V: Game24

Richard,

You can mail your code to me & I will post it for you but there is a risk I might not be able to post it. My son uses my computer whenever I am not on it because mine is faster than his computer & last night it died after he installed something. I can't even use explorer on the damn thing & I will have to rebuilt but I should have it fixed by the weekend.

For what its worth, I think you should post your code using whatever criteria you choose. It is up to Jens to decide the final results & as Howard says its only fun.

I also had to decrease efficiency to save code size but that's part of the game - right. I am intrigued to see how you got to 400. I look at my code & I wonder where can I cut 300 characters even if I knowingly decrease accuracy. I can’t see how to do it. So I would like to see the script even if it misses some combos.

Anyway, I think this accuracy issue is deeper than some might think. I found 2 sites on the Internet that either generate solutions or solve them & both seem to occasionally give incorrect answers. For one, I reviewed the source code & it uses the same basic methodology that I do but it gives different answers from me. I attribute it to the fact that floating-point calculations are ever so slightly differently in both codes. With infinite repeating decimal patterns lengthening the word size will never completely eliminate the issue.

The last I remember Richard was at 400.

I am at 700 but if I remove some () cases I might be able to get to Howard’s number.


LonkeroAdministrator
(KiX Master Guru)
2002-09-19 03:07 PM
Re: KiXtart Golf V: Game24

heh...

haven't you heard that there is systems which may restrict the abuse of computer?

I've used nt-line since 99 on my home computers and seen that it is really good way to disable the ability to what I don't want my quests to do


Jack Lothian
(MM club member)
2002-09-19 03:17 PM
Re: KiXtart Golf V: Game24

Lonkero,

Yes I know, but unfortunately I tolerate things that my son does that I would never tolerate at work. He thinks he's a hot shot & I am old fart who doesn't really understand the new world. While I disagree with him, he does have more endurance & energy & he wins most of the disputes. The life of a parent can be a challange sometimes.

I am seriously thinking of getting a proper backup system at home. This is getting annoying.

By the way what is "nt-line"?

[ 19. September 2002, 15:22: Message edited by: Jack Lothian ]


Richard H.Administrator
(KiX Supporter)
2002-09-19 03:22 PM
Re: KiXtart Golf V: Game24

Thanks Jack, it's on it's way...

Fernando Madruga
(Starting to like KiXtart)
2002-09-19 03:26 PM
Re: KiXtart Golf V: Game24

quote:

It's not cheating, it's taking advantage of a loophole.

If the code correctly responds to the random numbers when run it passes the test *and* it complies with all the given objectives.

Sorry... Wrong again... [Smile]

Anything that is not repeatable, can't be said to conform to these specs... You see, what happens if the exact same time someone is trying to comprove your code it fails on them? It's almost like going: "this is dangerous: I'll stick my head into the sand and hopefully they'll miss me"...

P.S.: I'm not trying to remove the fun here...


LonkeroAdministrator
(KiX Master Guru)
2002-09-19 03:27 PM
Re: KiXtart Golf V: Game24

I shortened my words from nt and w2k to nt-line.

NewTech-line.

also, I've made some systems run on dualboot.

first, it starts dos7 on 1Gb drive which has the image of w2k install-drive on it.

when the the image is dropped it reboots automatically and w2k is run...

then when w2k boots up it has in its runkey a command which changes the boot order to be first the dos and ofcourse timeout 0.

this way, it does not matter what they install.

and if your kid is too wise, install nt so he may not even see what's on this fat32 partition [Big Grin]


Jack Lothian
(MM club member)
2002-09-19 03:45 PM
Re: KiXtart Golf V: Game24

Thanks Jooel,

Maybe my son is correct - the sense of nt-line is obvious.

Also, I have been thinking of setting up a dual-boot system for some time know. I would also like to try out Linux so maybe now is the time to make the big leap to triple boot.


Fernando Madruga
(Starting to like KiXtart)
2002-09-19 03:51 PM
Re: KiXtart Golf V: Game24

I updated the test script to check for all valid solutions when it's given random numbers, and also to tun 20 random tests instead of one. It's fast: only 2 seconds, so it's not THAT much overhead added to your function! Also, I added a version number to the 1st line printed (it now says: "Game 24 v 1.1")

code:
[d:\work\admin\kixtart\kixgolf4]timer /1 on %+ kix32 test.kix %+ timer /1 off
Timer 1 on: 14:37:54

Game24 KiXtart Golf running under KiXtart v4.11

In => 1, 2, 3, 4; Out => = => WRONG!!
In => 2, 2, 6, 8; Out => = => WRONG!!
In => 4, 4, 6, 6; Out => = => Correct!!
In => 3, 3, 8, 8; Out => = => Correct!!
In => 0, 4, 8, 9; Out => = => NOT in solution set!!
In => 8, 8, 3, 1; Out => = => Correct!!
In => 5, 1, 5, 6; Out => = => Correct!!
In => 8, 8, 4, 3; Out => = => NOT in solution set!!
In => 9, 9, 4, 8; Out => = => Correct!!
In => 6, 9, 4, 9; Out => = => Correct!!
In => 0, 7, 0, 6; Out => = => NOT in solution set!!
In => 1, 8, 1, 1; Out => = => Correct!!
In => 6, 8, 3, 2; Out => = => Correct!!
In => 1, 5, 4, 8; Out => = => Correct!!
In => 2, 9, 7, 8; Out => = => Correct!!
In => 5, 8, 2, 7; Out => = => Correct!!
In => 1, 0, 3, 7; Out => = => Correct!!
In => 1, 1, 7, 7; Out => = => NOT in solution set!!
In => 5, 6, 0, 3; Out => = => NOT in solution set!!
In => 2, 9, 9, 1; Out => = => NOT in solution set!!
In => 5, 3, 9, 0; Out => = => Correct!!
In => 0, 1, 7, 8; Out => = => NOT in solution set!!
In => 5, 9, 7, 0; Out => = => NOT in solution set!!
In => 0, 7, 6, 6; Out => = => NOT in solution set!!
In => 3, 4, 7, 7; Out => = => WRONG!!
In => 1, 2, 8, 9; Out => = => WRONG!!
In => 3, 3, 7, 7; Out => = => WRONG!!

kix32 Kixgolf3.kix $f=test.kix

KixGolf v3.0.3 score = 38, running under KiXtart v4.11
Timer 1 off: 14:37:57 Elapsed: 0:00:02,83

[d:\work\admin\kixtart\kixgolf4]

Here it is:

code:
BREAK ON

Global $Target, $Valid

$Target = 24
$ErrorMargin = 0.0001
$Valid = "003800460128013601370138013901450146014701480155015602260234"
+ "023602380239024402460248025702580266026802690288033403350337"
+ "033803390344034603480349035803590366036703680378038803890445"
+ "044604470448045604660467046804690478048805660569058806890699"
+ "078908881118112611271128112911341135113611371138113911441145"
+ "114611471148114911551156115711581166116811691188122412251226"
+ "122712281229123312341235123612371238123912441245124612471248"
+ "124912551256125712581259126612671268126912771278127912881289"
+ "133313341335133613371338133913441345134613471348134913561357"
+ "135813591366136713681369137713781379138813891399144414451446"
+ "144714481449145514561457145814591466146714681469147714781479"
+ "148814891555155615591566156715681569157815791588158915991666"
+ "166816691679168816891699177917881789179918881889222322242225"
+ "222722282229223322342235223622372238223922442245224622472248"
+ "224922552256225722582259226622672268226922772278228822892333"
+ "233523362337233823392344234523462347234823492355235623572358"
+ "235923662367236823692377237823792388238923992444244524462447"
+ "244824492455245624572458245924662467246824692477247824792488"
+ "248924992557255825592566256725682569257725782579258825892666"
+ "266726682669267826792688268926992778278827892888288928993333"
+ "333433353336333733383339334433453346334733483349335533563357"
+ "335933663367336833693377337833793389339934443445344634473448"
+ "344934553456345734583459346634683469347734783479348934993556"
+ "355735583559356635673568356935783579358835893599366636673668"
+ "366936773678367936883689369937773778377937883789379938883889"
+ "389939994444444544464447444844494455445644574458446844694477"
+ "447844794488448945554556455745584559456645674568456945774578"
+ "457945884589459946664667466846694677467846794688468946994777"
+ "477847884789479948884889489955555556555955665567556855775578"
+ "558855895599566656675668566956775678567956885689569957795788"
+ "578958885889666666686669667966886689678967996888688968997889"

$rc=SETOPTION('Explicit','ON')
$rc=SETOPTION('NoVarsInString','ON')
$rc=SRND(@MSECS)

? 'Game24 v 1.1 KiXtart Golf running under KiXtart v'@KIX
? ''
Dim $i

test24(1,2,3,4,1)
test24(2,2,6,8,1)
test24(4,4,6,6,2)
test24(3,3,8,8,2)
for $i = 1 to 20
test24(RND(9),RND(9),RND(9),RND(9),3)
next
test24(3,4,7,7,1)
test24(1,2,8,9,1)
test24(3,3,7,7,1)
? ""

; Inputs: $i1..$i4 => 4 numbers to pass to game24
; $behaviour = 1 -> Expected result
; $behaviour = 2 -> Expected to fail
; $behaviour = 3 -> Don't know (random)
function test24($i1,$i2,$i3,$i4,$behaviour)
DIM $rc, $out, $result, $error, $str, $i, $found, $temp, $nums[4], $numbers

$str = 'In => '+$i1+', '+$i2+', '+$i3+', '+$i4+'; Out => '
$out=Game24($i1,$i2,$i3,$i4)
$i = 1
while $i <= Len($out)
if ( SubStr($out,$i,1) >= '0' ) and ( SubStr($out,$i,1) <= '9' )
$out = Left($out,$i) + '.0' + SubStr($out,$i+1)
$i = $i + 2;
endif;
$i = $i + 1;
loop
$error=Execute("$$result=("+$out+")")
$result=Trim($result)
$str = $str + $out + " = " + $result
if ( $behaviour = 3 )
; $str = $str + " => Not sure..."
; sort numbers used, so as to check array of possible solutions
$nums[0] = $i1
$nums[1] = $i2
$nums[2] = $i3
$nums[3] = $i4
do
$found = 0
for $i = 0 to 2
if $nums[$i] > $nums[$i+1]
$found = 1
$temp = $nums[$i+1]
$nums[$i+1] = $nums[$i]
$nums[$i] = $temp
endif
next
until $found == 0
$numbers = "" + $nums[0] + $nums[1] + $nums[2] + $nums[3]
; check for presence in array
$found = 0
$i = 1
while ( $found == 0 ) and ( $i < Len($Valid) )
if ( SubStr( $Valid, $i, 4 ) == $numbers )
$found = 1
endif
$i = $i + 4
loop
if $found
$str = $str + " => Correct!!"
else
$str = $str + " => NOT in solution set!!"
endif
else
if ( ($behaviour=1) and ($result>=$Target-$ErrorMargin)
and ($result<=$Target+$ErrorMargin) )
or ( ($behaviour=2) and ($result='') )
$str = $str + " => Correct!!"
else
$str = $str + " => WRONG!!"
endif
endif
? $str
endfunction

Dim $shellcommand
$shellcommand='kix32 Kixgolf3.kix $f='+@scriptname
? $shellcommand
Shell $shellcommand

; Operators: 64 combinations
; +++ ++- ++* ++/ +-+ +-- +-* +-/ +*+ +*- +** +*/ +/+ +/- +/* +//
; -++ -+- -+* -+/ --+ --- --* --/ -*+ -*- -** -*/ -/+ -/- -/* -//
; *++ *+- *+* *+/ *-+ *-- *-* *-/ **+ **- *** **/ */+ */- */* *//
; /++ /+- /+* /+/ /-+ /-- /-* /-/ /*+ /*- /** /*/ //+ //- //* ///

; Digits: 24 permutations
; abcd abdc acbd acdb adbc adcb
; bacd badc bcad bcda bdac bdca
; cabd cadb cbad cbda cdab cdba
; dabc dacb dbac dbca dcab dcba

; Parentheses: 5 combinations
; a b c d
; a b (c d)
; (a b)(c d)
; a(b c d)
; (a b c)d

; 0 need (ab)cd
; 0 need a(bc)d
; 0 need ab(cd)
; ------------------
; 1 need (abc)d
; ------------------
; 3 need a(bcd)
; 13 need (ab)(cd)
; ------------------
; 131 need at least one '+'
; 174 need at least one '-'
; 306 need at least one '*'
; 36 need at least one '/'
;!
function game24($a,$b,$c,$d)

endfunction

;!
;!



[ 19. September 2002, 16:21: Message edited by: Fernando Madruga ]


LonkeroAdministrator
(KiX Master Guru)
2002-09-19 03:55 PM
Re: KiXtart Golf V: Game24

wow!
quote:

kix32 Kixgolf3.kix $f=test.kixKix
Golf v3.0.3 score = 38, running under KiXtart v4.11
Timer 1 off: 14:37:57 Elapsed: 0:00:02,83
[d:\work\admin\kixtart\kixgolf4]

wow again! you got only 38 strokes [Eek!]

why you boys keep on fighting anymore [Confused]


Sealeopard
(KiX Master)
2002-09-19 04:10 PM
Re: KiXtart Golf V: Game24

Firstly, I am willing to accept any code sent to me for posting on Saturday. I have not yet found time to code a solution myself because of a lack of time (been working for the last two weeks straight).

Secondly, the next KiXtart Golf tournament will be posted into the General forum as per suggestion of both Jack and Jooel.

Thirdly, the tests that I implemented in my first post with regards to the validity of the function return are indeed cruel. I'm an idealist and I do believe that anybody participating in the KiXtart Golf games does it because of an intrest in codeing KiXtart, taking KiXtart to the next level, likes to solve tricky stuff, and so on. Thus, I trust everybody to actually make sure the code fulfills the challenge without me pouring through every line of code to see whether there's a loophole.

Fourthly, I do hope everybody still has fun despite the problems we're running into with regards to integer/floating point calculations.

[ 19. September 2002, 16:25: Message edited by: sealeopard ]


Fernando Madruga
(Starting to like KiXtart)
2002-09-19 04:24 PM
Re: KiXtart Golf V: Game24

Eheh... I said I'd only start coding my game24 tonight, and so it will be! [Smile]
Maybe tomorrow I can have a "valid" score...

P.S.: I, for one, am having LOADS of fun with this one! And I haven't even started coding! (Maybe that fun will turn to pain when I do... [Smile] )

[ 19. September 2002, 16:25: Message edited by: Fernando Madruga ]


Howard Bullock
(KiX Supporter)
2002-09-20 04:05 AM
Re: KiXtart Golf V: Game24

KixGolf v3.0.3 score = 476, running under KiXtart v4.10
KixGolf v3.0.3 score = 474, running under KiXtart v4.10

It is getting tougher for me now.
KixGolf v3.0.3 score = 468, running under KiXtart v4.10
KixGolf v3.0.3 score = 466, running under KiXtart v4.10
KixGolf v3.0.3 score = 463, running under KiXtart v4.10
KixGolf v3.0.3 score = 453, running under KiXtart v4.10
KixGolf v3.0.3 score = 447, running under KiXtart v4.10

[ 20. September 2002, 21:30: Message edited by: Howard Bullock ]


LonkeroAdministrator
(KiX Master Guru)
2002-09-20 09:12 PM
Re: KiXtart Golf V: Game24

no one striking back?

this long period (1week) on the first private coding phase has got this thing to flatten a little bit...

no great me-first-wars anymore...
 


BrianTX
(Korg Regular)
2002-09-20 09:20 PM
Re: KiXtart Golf V: Game24

hey ho!

Hi guys.. another fine kixgolf game I see. I haven't had time to foray into this.. work at hand ya know..... Very interesting, though.. !

(I'm going to post some code in another spot.. see if anyone is interested... it's on analyzing Microsoft proxy logs..)

Brian


LonkeroAdministrator
(KiX Master Guru)
2002-09-20 09:27 PM
Re: KiXtart Golf V: Game24

brian, these golfs are almost boring when you are not fighting for your life!

no, really, you might inform us when you have some days less work so we might plan the golf to suit your schedule also [Big Grin]

rombl!

 


BrianTX
(Korg Regular)
2002-09-20 09:35 PM
Re: KiXtart Golf V: Game24

Are you not getting much competition these days, Lonkero? Unfortunately, (or perhaps fortunately), my life has become busier with lots of social activities, church activities, family events, etc. so that I don't have as much time to let the geek out that is cooped up inside of me!

Brian


Howard Bullock
(KiX Supporter)
2002-09-20 09:36 PM
Re: KiXtart Golf V: Game24

You still have a few hours! [Big Grin]

LonkeroAdministrator
(KiX Master Guru)
2002-09-20 09:44 PM
Re: KiXtart Golf V: Game24

church?
is that religion?

as if it is, it's bad. [Big Grin]

 


Howard Bullock
(KiX Supporter)
2002-09-20 10:48 PM
Re: KiXtart Golf V: Game24

Brian, if you only need (ab)(cd) and a(bcd) how would you show (a+b+c)/d as a possibility? Did I miss something?

{edit} Seems that I jumped the gun. Just noticed your edit.

[ 20. September 2002, 22:54: Message edited by: Howard Bullock ]


Howard Bullock
(KiX Supporter)
2002-09-20 10:55 PM
Re: KiXtart Golf V: Game24

Brian, what happened to your post?

BrianTX
(Korg Regular)
2002-09-20 11:05 PM
Re: KiXtart Golf V: Game24

hmm. i must be lame brained today.. I deleted that post because it was stupid.. but i had it partially right:

3 possibilities:
a(bcd),(ab)(cd), and (abc)d...

All the others are redundants.. Just my two cents.. (The only reason you need (abc)(d) is because the / and - are not commutative.)

Brian


Howard Bullock
(KiX Supporter)
2002-09-20 11:53 PM
Re: KiXtart Golf V: Game24

If that is the case I can trim a little more. [Wink] Haven't thought through it in great detail.

Fernando Madruga
(Starting to like KiXtart)
2002-09-21 12:11 AM
Re: KiXtart Golf V: Game24

You could have started trimming sooner: back in page 4 of this thread, I had already stated that, although in other terms... [Smile]

Gonna start my coding now. Wish me luck guys! [Smile]


Howard Bullock
(KiX Supporter)
2002-09-21 01:38 AM
Re: KiXtart Golf V: Game24

KixGolf v3.0.3 score = 438, running under KiXtart v4.10

Fernando Madruga
(Starting to like KiXtart)
2002-09-21 01:46 AM
Re: KiXtart Golf V: Game24

PPL: need some help... What's the best way to debug a KiXtart program and watch variables? The built-in debugger is very basic... [Frown]

Please advise...


Howard Bullock
(KiX Supporter)
2002-09-21 01:49 AM
Re: KiXtart Golf V: Game24

For big projects or repeatative vars (hehe), I have always used WriteLog() UDF and write a file to trace program execution. I document whatever items seem to be affecting my code until the bugs are squashed.

[ 21. September 2002, 01:50: Message edited by: Howard Bullock ]


Fernando Madruga
(Starting to like KiXtart)
2002-09-21 02:30 AM
Re: KiXtart Golf V: Game24

Well... I've managed to fix the bug. However, I don't think I'll be any match to you guys: I've just finished the permutation generation code, and am already running at 277!! When I add the operators, parentheses and tests, I'll be WAY over the current results... [Frown]

Anyway, I'll try and finish this one... I may be leaving KiXtart and this forum real soon.


Howard Bullock
(KiX Supporter)
2002-09-21 02:38 AM
Re: KiXtart Golf V: Game24

Why would you be leaving?

Fernando Madruga
(Starting to like KiXtart)
2002-09-21 03:14 AM
Re: KiXtart Golf V: Game24

I have to make a correction: "may be" -> "will be"...

I'm starting to dislike KiXtart: even though it has some nice builtin functions for use in logon scripts, it does lack a LOT...

I've become used to more high level languages, or even not so high level but with more descriptive error messages and better debuggers...

And this particular KixGolf edition served to show that we can't even rely on floating point! Having written the exact same program in Perl and KiXtart, KiXtart's version fails a LOT...

Even though I tried to "ignore" some of KiXtart's "missing" features, I don't like being "tied up"... Everywhere I turn to make something other than the most basic things, KiXtart won't do it... [Frown]

These last 2 KixGolf contests served to show me one thing: doing some major KiXtart development, as I was planning to, would be a MAJOR pain, and I've become used to making the computer work for me, as opposed to having to work for the computer... [Smile]

Also, I've managed to convince my boss that we should buy ScriptLogic's software, and so I won't be needing to do any KiXtart programming at all! If I ever need a small script, I'll do it in Perl or maybe Python (learning this one now...)

That's the main reason why I'm leaving. After all, if not "KiXtarting", there's no reason to stay in a KiXtart BB!!

As a sidenote: I don't think I'll complete the game script, after all: I am already running at 400+ and it's still missing the parentheses and test condition! And those two will surely add another 100+ keystrokes. Also, my weekend is going to be somewhat busy (got to go for tonight).

[ 21. September 2002, 03:15: Message edited by: Fernando Madruga ]


**DONOTDELETE**
(Lurker)
2002-09-21 06:51 PM
Re: KiXtart Golf V: Game24

I have been playing with this on and off for days, and only
got a working script about 6 hours ago!
Not compressed much, but I doubt I can do much better.
Golf Score 541.


Fernando Madruga
(Starting to like KiXtart)
2002-09-23 05:42 PM
Re: KiXtart Golf V: Game24

What? Last post was in 21/09/2002 @ 18:51?

Things look VERY quiet in here... [Smile]

Anyway, ppl, in the process of rewriting the 6 hour Perl program to compute all solutions into a 21 minute Python version, I found that one solution had been missed by the perl version! That's 3388 wich does have a valid solution as 8/(3-8/3). So, please add this line:
quote:

+ "3388"

before the following line:
quote:

$rc=SETOPTION('Explicit','ON')

in my previously published version of the test program.

BTW: If I do get some spare time, I might try to complete this game anyway... As part of my Python learning program I'll make a program to compute a simpler algorithm. If I do find one, I'll try to make a KiXtart program out of it, and if I don't bump into many walls doing it, I may as well end up posting my version of game24...

[ 23. September 2002, 17:43: Message edited by: Fernando Madruga ]


Sealeopard
(KiX Master)
2002-09-23 05:55 PM
Re: KiXtart Golf V: Game24

Fernando: We moved on to the second part of KiXtart Golf in KixGolf Results/Code