Page 2 of 5 <12345>
Topic Options
#70084 - 2002-09-23 09:16 PM Re: KixGolf Results/Code
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
My first code posting resolves the 5's correctly. That would seem to indicate the Richard's code using a(b(cd)) does not work either. My second posting was qualified on the case that the parentheses used in Richard's code held up. This case seems to indicate that his code would fail if the random test selected four 5's.

That being said, my second posting with a score of 314 would not be acceptable, Richard's code would not be acceptable, and my first code with a score of 434 is the current valid working code.

Jens, can we have a ruling?

[ 23. September 2002, 21:20: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#70085 - 2002-09-23 09:20 PM Re: KixGolf Results/Code
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
I will test all codes with the 5555 combination tonight at home. I've tried to run each code through all permutations but that doesn't seem to be possible since I'm always getting 'out-of-memory' errors.
_________________________
There are two types of vessels, submarines and targets.

Top
#70086 - 2002-09-23 09:50 PM Re: KixGolf Results/Code
Jack Lothian Offline
MM club member
*****

Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
I believe that Richard's nested parenthesis of "a (b (c d))" can be morphed into all possible versions of "a b c d", "a (b c d)", and "a b (c d)" but not into all the possible permutations of 2 other variations found necessary by Madruga i.e "(a b c) d" and "(a b)(c d)". Interestingly, Richard identified 1 generalized type of parenthesis that covers about 80% cases for the 5 variants. Thus he gets most of the solutions.

A quick & dirty test by me seems to show Howard's first set of code works correctly.

[ 23. September 2002, 21:55: Message edited by: Jack Lothian ]
_________________________
Jack

Top
#70087 - 2002-09-23 09:50 PM Re: KixGolf Results/Code
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Fernando, my code produces a valid output for 3,3,8,8 -> 8.0/(3.0-8.0/3.0) = 24 but your test script says that it fails:
quote:
In: 3388; Out: = => WRONG!!
I think you may need to recheck you code. [Wink] Or am I using it incorrectly?
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#70088 - 2002-09-23 10:43 PM Re: KixGolf Results/Code
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
That's odd! I added a ? $out right after calling your game24 function (I assume you're talking about the 1st one posted with 434 score?) and it prints nothing...
code:
(1.0*2.0)*(3.0*4.0)
In: 1234; Out: (1.0*2.0)*(3.0*4.0) = 24 => Correct!!
2.0*(6.0+8.0-2.0)
In: 2268; Out: 2.0*(6.0+8.0-2.0) = 24 => Correct!!

In: 4466; Out: = => Correct!!

In: 3388; Out: = => WRONG!!

Are you sure it is returning the value?
If it's some bug in my test program, you guys will have to help here... [Smile]

[ 23. September 2002, 22:43: Message edited by: Fernando Madruga ]
_________________________
Later,   [b]Mad[/b]ruga

Top
#70089 - 2002-09-23 11:05 PM Re: KixGolf Results/Code
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
I've tried to do some additional testing, and I must say: all you guys that develop anything more complex than 1 line of KiXtart should be given a medal!

Honestly! Check the following script: it's my test script with Howard's 1st code: if I run it with the last get $h commented out, it prints this:
code:
[d:\work\admin\kixtart\kixgolf4]kix32 test2.kix

Game24 v 1.1 KiXtart Golf running under KiXtart v4.11

8.0/(3.0-8.0/3.0)
8.0/(3.0-8.0/3.0)
8.0/(3.0-8.0/3.0)

In: 3388; Out: = => WRONG!!

If I run it with the get $h working, and after pressing any key twice, it prints this:
code:
[d:\work\admin\kixtart\kixgolf4]kix32 test2.kix

Game24 v 1.1 KiXtart Golf running under KiXtart v4.11

8.0/(3.0-8.0/3.0)

In: 3388; Out: = => WRONG!!

Can someone tell me why? How can you guys debug code in this thing?

Here's the test code mentioned:
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"
+ "3388"

$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(3,3,8,8,1)
quit
;test24(1,2,3,4,1)
;test24(2,2,6,8,1)
;test24(4,4,6,6,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)
; ? $out
if instr($out,".") == 0
$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
endif
$error=Execute("$$result=("+$out+")")
$result=Trim($result)
Dim $tmpStr
$tmpStr = $out
while (len($tmpStr)<22)
$tmpStr = $tmpStr + " "
loop
$str = $str + left($tmpStr, 22) + " = " + $result
if (len($result)<2)
$str = $str+" "
endif
if ( $behaviour = 3 )
; 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 and ( ($result>=$Target-$ErrorMargin) and
($result<=$Target+$ErrorMargin) )
$str = $str + " => Correct!!"
else
if not $found and $result=""
$str = $str + " => Correct!!"
else
$str = $str + " => WRONG!!"
endif
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: 4 combinations
; 123456789 12345 (15 chars)
; 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)

Dim $h, $j, $l, $p, $q, $r, $s, $t, $v, $, $x, $y

$h = "+","-","/","*"
for $y=1 to 4
for $x=1 to 4
for each $p in $h
for each $q in $h
for each $r in $h
for each $j in split("0,8,10,18~0,12~4,16","~")
$ = ".0"
$s = ""+$a+$+$p+$b+$+$q+$c+$+$r+$d+$
for each $ in split($j,",")
$l = chr(40 + ($l="("))
$s = "" + left($s,$) + $l + substr($s,1+$)
next
$t = execute("$$v=$s")
if abs($v-24)< 1E-9
goto E
endif
next
next
next
next
$ = $b
$b = $c
$c = $d
$d = $
next
$ = $a
$a = $b
$b = $
next
$s = ""

:E
$game24 = $s
? $s
;get $h
endfunction
;!
;!



[ 23. September 2002, 23:06: Message edited by: Fernando Madruga ]
_________________________
Later,   [b]Mad[/b]ruga

Top
#70090 - 2002-09-23 11:54 PM Re: KixGolf Results/Code
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
[Razz] [Big Grin] [Eek!] [Cool] Working on it.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#70091 - 2002-09-24 12:40 AM Re: KixGolf Results/Code
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
BTW, Howard, I've been through your permutation code, and found something's missing!

I extracted all but the code to generate the permutations and turned it into this independent script:

code:
BREAK ON

Dim $a, $b, $c, $d, $, $x, $y

$a = 'a'
$b = 'b'
$c = 'c'
$d = 'd'

for $y=1 to 4
for $x=1 to 4
? ""+$a+$b+$c+$d
$ = $b
$b = $c
$c = $d
$d = $
next
$ = $a
$a = $b
$b = $
next

I thought it would only do 16 of the 24 permutations, but it does even less!!
It only does 12 "diferent" permutations, as 4 are repeated!!
This means that you test only HALF the valid permutations!!!

code:
It.  Permutation
01 abcd
02 acdb
03 adbc
04 abcd
05 cadb
06 cdba
07 cbad
08 cadb
09 dcba
10 dbac
11 dacb
12 dcba
13 bdac
14 bacd
15 bcda
16 bdac

Putting it another way, where the number(s) in front are
the iteration number(s) where that sequence is visited:

code:
abcd 01 04
abdc
acbd
acdb 02
adbc 03
adcb
bacd 14
badc
bcad
bcda 15
bdac 13 16
bdca
cabd
cadb 05 08
cbad 07
cbda
cdab
cdba 06
dabc
dacb 11
dbac 10
dbca
dcab
dcba 09 12

This means, or so I think, that you never test the
following permutations:

abdc acbd adcb badc bcad bdca cabd cbda cdab dabc dbca dcab

So, it's very likely that your code would fail on things like: 6143 and 6451.

[ 24. September 2002, 00:41: Message edited by: Fernando Madruga ]
_________________________
Later,   [b]Mad[/b]ruga

Top
#70092 - 2002-09-24 12:41 AM Re: KixGolf Results/Code
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
To answer the question about printing the output three times from within my function. I think we found a KiXtart bug.

Kholm, suggested that I remove the exit at the end of the function to save four strokes. I did that without testing because he and I thought when the execution hit the ENDFUNCTION statement the function would exit automatically. WRONG! I think that using the GOTO (Yuk!) inside the nested loops causes a problem. The GOTO seems to behaving like a "GOSUB" statement and the ENDFUNCTION like a "RETURN". Without the exist statement in the code, execution returns to the GOTO and the FOR loops continue processing. When the loops were finished processing the value of $Game24 is set to "".

So your program was correct in the strange output since it received strange output.
code:
Game24 v 1.1 KiXtart Golf running under KiXtart v4.11

In: 3388; Out: 8.0/(3.0-8.0/3.0) = 24 => Correct!!
In: 1234; Out: (1.0+2.0+3.0)*4.0 = 24 => Correct!!
In: 2268; Out: (2.0+6.0)+(8.0*2.0) = 24 => Correct!!
In: 4466; Out: = => Correct!!
In: 0965; Out: (0.0-6.0)*(5.0-9.0) = 24 => Correct!!
In: 3164; Out: 6.0/(1.0-3.0/4.0) = 24 => Correct!!
In: 7395; Out: (7.0+3.0)+(9.0+5.0) = 24 => Correct!!
In: 1955; Out: (1.0+5.0)*(9.0-5.0) = 24 => Correct!!
In: 6396; Out: (6.0+3.0)+(9.0+6.0) = 24 => Correct!!
In: 4736; Out: = => Correct!!
In: 9439; Out: (9.0*4.0)-(3.0+9.0) = 24 => Correct!!
In: 4478; Out: (4.0+4.0*7.0)-8.0 = 24 => Correct!!
In: 1254; Out: (5.0-1.0)*(4.0+2.0) = 24 => Correct!!
In: 0714; Out: (0.0+7.0-1.0)*4.0 = 24 => Correct!!
In: 2000; Out: = => Correct!!
In: 9196; Out: (9.0+1.0*9.0)+6.0 = 24 => Correct!!
In: 0200; Out: = => Correct!!
In: 7547; Out: (7.0*5.0)-(4.0+7.0) = 24 => Correct!!
In: 4270; Out: = => Correct!!
In: 4362; Out: (4.0+3.0*6.0)+2.0 = 24 => Correct!!
In: 3778; Out: (3.0+7.0-7.0)*8.0 = 24 => Correct!!
In: 2476; Out: (2.0+4.0*7.0)-6.0 = 24 => Correct!!
In: 8624; Out: (8.0+6.0*2.0)+4.0 = 24 => Correct!!
In: 7564; Out: (7.0+5.0-6.0)*4.0 = 24 => Correct!!
In: 3477; Out: (3.0+4.0*7.0)-7.0 = 24 => Correct!!
In: 1289; Out: (8.0*9.0)/(2.0+1.0) = 24 => Correct!!
In: 3377; Out: (3.0+3.0/7.0)*7.0 = 24 => Correct!!

kix32 Kixgolf3.kix $f=junk.kix

KixGolf score = 438



[ 24. September 2002, 12:24: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#70093 - 2002-09-24 12:51 AM Re: KixGolf Results/Code
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
You're right!

Unfortunately for you, so am I in my previous post... Another one that your program fails is 4429...

Just add one of those with a '1' at the end of the call to test24 and you'll see for yourself...

Sorry...
_________________________
Later,   [b]Mad[/b]ruga

Top
#70094 - 2002-09-24 12:58 AM Re: KixGolf Results/Code
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
Updated KixText.kix

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"
+ "3388"

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

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

test24(6,1,4,3,1)
test24(5,5,5,5,1)
test24(6,4,5,1,1)
test24(3,3,8,8,1)
test24(1,2,3,4,1)
test24(2,2,6,8,1)
test24(4,4,6,6,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=""
$out=Game24($i1,$i2,$i3,$i4)
if instr($out,".") == 0
$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
endif
$error=Execute("$$result=("+$out+")")
$result=Trim($result)
Dim $tmpStr
$tmpStr = $out
while (len($tmpStr)<22)
$tmpStr = $tmpStr + " "
loop
$str = $str + left($tmpStr, 22) + " = " + $result
if (len($result)<2)
$str = $str+" "
endif
if ( $behaviour = 3 )
; 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 and ( ($result>=$Target-$ErrorMargin) and
($result<=$Target+$ErrorMargin) )
$str = $str + " => Correct!!"
else
if not $found and $result=""
$str = $str + " => Correct!!"
else
$str = $str + " => WRONG!!"
endif
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: 4 combinations
; 123456789 12345 (15 chars)
; 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($,$b,$c,$d)
$game24=f(""+$+$b+$c+$d,"")
EndFunction
Function 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
EndIf
EndFunction
;!
;!

_________________________
Later,   [b]Mad[/b]ruga

Top
#70095 - 2002-09-24 12:59 AM Re: KixGolf Results/Code
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
Running the updated KixTest 1.4 on Richard Howarth's code yields the following:

code:
[d:\work\admin\kixtart\kixgolf4]kix32 testRH.kix

Game24 v 1.4 KiXtart Golf running under KiXtart v4.11

In: 6143; Out: 6.0/(1.0-(3.0/4)) = 24 => Correct!!
In: 5555; Out: = => WRONG!!
In: 6451; Out: 4.0/(1.0-(5.0/6)) = 24 => Correct!!
In: 3388; Out: 8.0/(3.0-(8.0/3)) = 24 => Correct!!
In: 1234; Out: 4.0*(3.0*(2.0/1)) = 24 => Correct!!
In: 2268; Out: 8.0+(2.0*(6.0+2)) = 24 => Correct!!
In: 4466; Out: = => Correct!!
In: 0106; Out: = => Correct!!
In: 8755; Out: 7.0-(8.0-(5.0*5)) = 24 => Correct!!
In: 0262; Out: 2.0*(6.0*(2.0-0)) = 24 => Correct!!
In: 3145; Out: 4.0+(5.0*(1.0+3)) = 24 => Correct!!
In: 5746; Out: 4.0*(7.0-(6.0-5)) = 24 => Correct!!
In: 2442; Out: 2.0*(4.0+(4.0*2)) = 24 => Correct!!
In: 1084; Out: 8.0*(4.0-(0.0+1)) = 24 => Correct!!
In: 6622; Out: 6.0/(2.0/(2.0+6)) = 24 => Correct!!
In: 8753; Out: 3.0-(7.0*(5.0-8)) = 24 => Correct!!
In: 3736; Out: 6.0-(3.0-(7.0*3)) = 24 => Correct!!
In: 5295; Out: 5.0+(9.0+(2.0*5)) = 24 => Correct!!
In: 1770; Out: = => Correct!!
In: 8112; Out: 1.0*(8.0*(2.0+1)) = 24 => Correct!!
In: 0705; Out: = => Correct!!
In: 1909; Out: = => Correct!!
In: 2924; Out: 4.0+(2.0+(9.0*2)) = 24 => Correct!!
In: 1119; Out: = => Correct!!
In: 3447; Out: 4.0*(7.0-(4.0-3)) = 24 => Correct!!
In: 6395; Out: 9.0-(5.0*(3.0-6)) = 24 => Correct!!
In: 1294; Out: 4.0*(9.0-(2.0+1)) = 24 => Correct!!
In: 3477; Out: 7.0-(4.0-(7.0*3)) = 24 => Correct!!
In: 1289; Out: 9.0*(8.0/(2.0+1)) = 24 => Correct!!
In: 3377; Out: 7.0*(3.0+(3.0/7)) = 24 => Correct!!

kix32 Kixgolf3.kix $f=testRH.kix

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

{edit} Running it a few more times, uncovered some more failing combos:
code:
In: 1655; Out:                        =    => WRONG!!
In: 6917; Out: = => WRONG!!
In: 4524; Out: = => WRONG!!
In: 1573; Out: = => WRONG!!

{/edit}

{edit} As for the other ones, here are the valid solutions for the misses:
code:
1573 : (1+5)*(7-3)
1573 : (3-1)*(5+7)
1573 : (3-1)*(7+5)
1573 : (5+1)*(7-3)
1573 : (5+7)*(3-1)
1573 : (7+5)*(3-1)
1573 : (7-3)*(1+5)
1573 : (7-3)*(5+1)
1655 : (1+5)*5-6
1655 : (5*6)-(1+5)
1655 : (5*6)-(5+1)
1655 : (5*6)-1-5
1655 : (5*6)-5-1
1655 : (5*6-1)-5
1655 : (5*6-5)-1
1655 : (5+1)*5-6
1655 : (6*5)-(1+5)
1655 : (6*5)-(5+1)
1655 : (6*5)-1-5
1655 : (6*5)-5-1
1655 : (6*5-1)-5
1655 : (6*5-5)-1
1655 : 5*(1+5)-6
1655 : 5*(5+1)-6
1655 : 5*6-(1+5)
1655 : 5*6-(5+1)
1655 : 5*6-1-5
1655 : 5*6-5-1
1655 : 6*5-(1+5)
1655 : 6*5-(5+1)
1655 : 6*5-1-5
1655 : 6*5-5-1
4524 : (2*5-4)*4
4524 : (2+5)*4-4
4524 : (4+4)*(5-2)
4524 : (5*2-4)*4
4524 : (5+2)*4-4
4524 : (5-2)*(4+4)
4524 : 4*(2*5-4)
4524 : 4*(2+5)-4
4524 : 4*(5*2-4)
4524 : 4*(5+2)-4
5555 : (5*5)-(5/5)
5555 : (5*5)-5/5
5555 : 5*5-(5/5)
5555 : 5*5-5/5
6917 : (1+7)*(9-6)
6917 : (7+1)*(9-6)
6917 : (9-6)*(1+7)
6917 : (9-6)*(7+1)

{/edit}

[ 24. September 2002, 01:46: Message edited by: Fernando Madruga ]
_________________________
Later,   [b]Mad[/b]ruga

Top
#70096 - 2002-09-24 01:05 AM Re: KixGolf Results/Code
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I have to add four strokes to cover those numbers (4,4,2,9).

code:
Game24 v 1.1 KiXtart Golf running under KiXtart v4.11

In: 3388; Out: 8.0/(3.0-8.0/3.0) = 24 => Correct!!
In: 4429; Out: (9.0-2.0)*4.0-4.0 = 24 => Correct!!
In: 1234; Out: (1.0+2.0+3.0)*4.0 = 24 => Correct!!
In: 2268; Out: (2.0+6.0)+8.0*2.0 = 24 => Correct!!
In: 4466; Out: = => Correct!!
In: 0380; Out: (0.0+3.0)*8.0+0.0 = 24 => Correct!!
In: 7443; Out: (7.0+4.0/4.0)*3.0 = 24 => Correct!!
In: 4459; Out: = => Correct!!
In: 8978; Out: (9.0-7.0)*8.0+8.0 = 24 => Correct!!
In: 6782; Out: 8.0*(2.0+7.0-6.0) = 24 => Correct!!
In: 0814; Out: (0.0-8.0)*(1.0-4.0) = 24 => Correct!!
In: 9743; Out: (9.0-7.0)*4.0*3.0 = 24 => Correct!!
In: 8953; Out: (5.0-8.0)+3.0*9.0 = 24 => Correct!!
In: 9042; Out: = => Correct!!
In: 0249; Out: = => Correct!!
In: 6671; Out: = => Correct!!
In: 1902; Out: = => Correct!!
In: 2978; Out: (7.0+9.0)*2.0-8.0 = 24 => Correct!!
In: 2529; Out: 2.0*(5.0-2.0+9.0) = 24 => Correct!!
In: 1071; Out: = => Correct!!
In: 8781; Out: (8.0+7.0)+8.0+1.0 = 24 => Correct!!
In: 7439; Out: (7.0+4.0)*3.0-9.0 = 24 => Correct!!
In: 6716; Out: = => Correct!!
In: 4349; Out: (4.0+4.0)*9.0/3.0 = 24 => Correct!!
In: 1027; Out: = => Correct!!
In: 3477; Out: (3.0+4.0*7.0)-7.0 = 24 => Correct!!
In: 1289; Out: (8.0*9.0)/(2.0+1.0) = 24 => Correct!!
In: 3377; Out: (3.0+3.0/7.0)*7.0 = 24 => Correct!!

kix32 Kixgolf3.kix $f=junk.kix

KixGolf score = 442

code:
function game24($a,$b,$c,$d)

Dim $h, $j, $l, $p, $q, $r, $s, $t, $v, $, $x, $y
$h = "+","-","/","*"
for $y=1 to 4
for $x=1 to 4
for each $p in $h
for each $q in $h
for each $r in $h
for each $j in split("0,8~0,8,10,18~0,12~4,16","~")
$ = ".0"
$s = ""+$a+$+$p+$b+$+$q+$c+$+$r+$d+$
for each $ in split($j,",")
$l = chr(40 + ($l="("))
$s = "" + left($s,$) + $l + substr($s,1+$)
next
$t = execute("$$v=$s")
if abs($v-24)< 1E-9
goto E
endif
next
next
next
next
$ = $b
$b = $c
$c = $d
$d = $
next
$ = $a
$a = $b
$b = $
next
$s = ""

:E
$game24 = $s
exit
endfunction

_________________________
Home page: http://www.kixhelp.com/hb/

Top
#70097 - 2002-09-24 01:08 AM Re: KixGolf Results/Code
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
More work for you, Howard... [Smile]

Using the above v1.4 tester with latest Howard's code:

code:
[d:\work\admin\kixtart\kixgolf4]kix32 testHB.kix

Game24 v 1.4 KiXtart Golf running under KiXtart v4.11

In: 6143; Out: = => WRONG!!
In: 5555; Out: (5.0*5.0)-5.0/5.0 = 24 => Correct!!
In: 6451; Out: = => WRONG!!
In: 3388; Out: 8.0/(3.0-8.0/3.0) = 24 => Correct!!
In: 1234; Out: (1.0+2.0+3.0)*4.0 = 24 => Correct!!
In: 2268; Out: (2.0+6.0)+8.0*2.0 = 24 => Correct!!
In: 4466; Out: = => Correct!!
In: 0028; Out: = => Correct!!
In: 2263; Out: 2.0*(6.0+3.0*2.0) = 24 => Correct!!
In: 4717; Out: (1.0+7.0)*(7.0-4.0) = 24 => Correct!!
In: 6834; Out: (6.0/3.0)*(4.0+8.0) = 24 => Correct!!
In: 1832; Out: (1.0+8.0+3.0)*2.0 = 24 => Correct!!
In: 0025; Out: = => Correct!!
In: 8164; Out: 8.0*(1.0+6.0-4.0) = 24 => Correct!!
In: 7912; Out: (7.0-1.0)+2.0*9.0 = 24 => Correct!!
In: 5046; Out: (5.0/0.0)+4.0*6.0 = 24 => Correct!!
In: 5857; Out: (5.0+5.0-7.0)*8.0 = 24 => Correct!!
In: 0899; Out: = => Correct!!
In: 5506; Out: = => Correct!!
In: 0990; Out: = => Correct!!
In: 2219; Out: 2.0*(2.0+1.0+9.0) = 24 => Correct!!
In: 9492; Out: (9.0+4.0)+9.0+2.0 = 24 => Correct!!
In: 2430; Out: (2.0*4.0)*3.0+0.0 = 24 => Correct!!
In: 7038; Out: (7.0/0.0)+3.0*8.0 = 24 => Correct!!
In: 3519; Out: (3.0*5.0)+1.0*9.0 = 24 => Correct!!
In: 2494; Out: (9.0-2.0)*4.0-4.0 = 24 => Correct!!
In: 6672; Out: (6.0+6.0*7.0)/2.0 = 24 => Correct!!
In: 3477; Out: (3.0+4.0*7.0)-7.0 = 24 => Correct!!
In: 1289; Out: (8.0*9.0)/(2.0+1.0) = 24 => Correct!!
In: 3377; Out: (3.0+3.0/7.0)*7.0 = 24 => Correct!!

kix32 Kixgolf3.kix $f=testHB.kix

KixGolf v3.0.3 score = 442, running under KiXtart v4.11

{edit} I'm now adding the valid solutions for the "misses", so as to help you guys sort your codes...

code:
6143 => 6/(1-3/4)
6451 => 4/(1-5/6)
6451 => 6/(5/4-1)

{/edit}

[ 24. September 2002, 01:34: Message edited by: Fernando Madruga ]
_________________________
Later,   [b]Mad[/b]ruga

Top
#70098 - 2002-09-24 01:13 AM Re: KixGolf Results/Code
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
More sad news, this time it's for AJH:

code:
[d:\work\admin\kixtart\kixgolf4]kix32 testAJH.kix

Game24 v 1.4 KiXtart Golf running under KiXtart v4.11

In: 6143; Out: 6./(1.-3./4.) = 24 => Correct!!
In: 5555; Out: 5.*5.-5./5. = 24 => Correct!!
In: 6451; Out: 6./(5./4.-1.) = 24 => Correct!!
In: 3388; Out: 8./(3.-8./3.) = 24 => Correct!!
In: 1234; Out: (1.+2.+3.)*4. = 24 => Correct!!
In: 2268; Out: 2.+2.*8.+6. = 24 => Correct!!
In: 4466; Out: = => Correct!!
In: 0729; Out: = => Correct!!
In: 8114; Out: (8.-1.-1.)*4. = 24 => Correct!!
In: 1546; Out: 4./(1.-5./6.) = 24 => Correct!!
In: 7434; Out: (7.-4.+3.)*4. = 24 => Correct!!
In: 5654; Out: (5.+6.-5.)*4. = 24 => Correct!!
In: 3910; Out: 3.*(9.-1.+0.) = 24 => Correct!!
In: 5142; Out: (5.-1.)*(4.+2.) = 24 => Correct!!
In: 9693; Out: (9./9.+3.)*6. = 24 => Correct!!
In: 6764; Out: (6.*4.)*(7.-6.) = 24 => Correct!!
In: 2400; Out: = => Correct!!
In: 7750; Out: = => Correct!!
In: 4691; Out: 6.*(9.-4.-1.) = 24 => Correct!!
In: 1177; Out: = => Correct!!
In: 9324; Out: (9.+3.)/(2./4.) = 24 => Correct!!
In: 4166; Out: = => WRONG!!
In: 5425; Out: = => WRONG!!
In: 1911; Out: = => Correct!!
In: 9940; Out: = => Correct!!
In: 0106; Out: = => Correct!!
In: 1902; Out: = => Correct!!
In: 3477; Out: 3.+4.*7.-7. = 24 => Correct!!
In: 1289; Out: 2.*8.-1.+9. = 24 => Correct!!
In: 3377; Out: (3.+3./7.)*7. = 24 => Correct!!

kix32 Kixgolf3.kix $f=testAJH.kix

KixGolf v3.0.3 score = 541, running under KiXtart v4.11

{edit} Valid solutions for the missed ones:
code:
4166 : (1+4)*6-6
4166 : (4+1)*6-6
4166 : (4-1)*6+6
4166 : 6*(1+4)-6
4166 : 6*(4+1)-6
4166 : 6*(4-1)+6
4166 : 6+(4-1)*6
4166 : 6+6*(4-1)
4166 : 6-(1-4)*6
4166 : 6-6*(1-4)
5425 : (5+5)*2+4
5425 : 2*(5+5)+4
5425 : 4+(5+5)*2
5425 : 4+2*(5+5)

{/edit}

[ 24. September 2002, 01:38: Message edited by: Fernando Madruga ]
_________________________
Later,   [b]Mad[/b]ruga

Top
#70099 - 2002-09-24 01:16 AM Re: KixGolf Results/Code
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
And this time it's for Jack Lothian... Sorry...

code:
[d:\work\admin\kixtart\kixgolf4]kix32 testJL.kix

Game24 v 1.4 KiXtart Golf running under KiXtart v4.11

In: 6143; Out: cdbl(6.0) / ( cdbl(1 = 24 => Correct!!
In: 5555; Out: cdbl(5.0) * cdbl(5. = 24 => Correct!!
In: 6451; Out: cdbl(6.0) * cdbl(4. = 24,2 => WRONG!!
In: 3388; Out: cdbl(3.0) + cdbl(8. = 24,3333333333333 => WRONG!!
In: 1234; Out: ( cdbl(1.0) + cdbl(2 = 24 => Correct!!
In: 2268; Out: cdbl(2.0) * ( cdbl(2 = 24 => Correct!!
In: 4466; Out: = => Correct!!
In: 0453; Out: = => Correct!!
In: 4930; Out: cdbl(4.0) * ( cdbl(9 = 24 => Correct!!
In: 8900; Out: = => Correct!!
In: 1428; Out: ( cdbl(1.0) + cdbl(4 = 24 => Correct!!
In: 7278; Out: cdbl(7.0) + cdbl(2. = 24 => Correct!!
In: 2087; Out: = => Correct!!
In: 3806; Out: cdbl(3.0) * cdbl(8. = 24 => Correct!!
In: 5604; Out: cdbl(5.0) * cdbl(0. = 24 => Correct!!
In: 2670; Out: = => Correct!!
In: 5696; Out: cdbl(6.0) * cdbl(9. = 24 => Correct!!
In: 9356; Out: ( cdbl(9.0) - cdbl(3 = 24 => Correct!!
In: 9439; Out: ( cdbl(9.0) - cdbl(4 = 24 => Correct!!
In: 8562; Out: ( cdbl(8.0) - cdbl(5 = 24 => Correct!!
In: 9648; Out: cdbl(9.0) * ( cdbl(4 = 24 => Correct!!
In: 6174; Out: cdbl(6.0) * ( cdbl(1 = 24 => Correct!!
In: 7484; Out: cdbl(7.0) * cdbl(4. = 24 => Correct!!
In: 9289; Out: cdbl(9.0) - cdbl(2. = 24 => Correct!!
In: 0052; Out: = => Correct!!
In: 0731; Out: ( cdbl(0.0) + cdbl(7 = 24 => Correct!!
In: 0808; Out: = => Correct!!
In: 3477; Out: cdbl(3.0) + cdbl(4. = 24 => Correct!!
In: 1289; Out: cdbl(2.0) * cdbl(8. = 24 => Correct!!
In: 3377; Out: ( cdbl(3.0) + cdbl(3 = 24 => Correct!!

kix32 Kixgolf3.kix $f=testJL.kix

KixGolf v3.0.3 score = 653, running under KiXtart v4.11

I'm lucky I'm not in ancient Rome... [Smile]

{edit} Another one for JL:
code:
In: 2747; Out:  cdbl(2.0)  *  cdbl(7. = 24,5 => WRONG!!

{/edit}

{edit}
Valid solutions for the missed ones:
code:
2747 : (7+7)*2-4
2747 : 2*(7+7)-4
3388 : 8/(3-8/3)
6451 : 4/(1-5/6)
6451 : 6/(5/4-1)

{/edit}

[ 24. September 2002, 01:41: Message edited by: Fernando Madruga ]
_________________________
Later,   [b]Mad[/b]ruga

Top
#70100 - 2002-09-24 01:59 AM Re: KixGolf Results/Code
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
there [Razz]

I hate it when the KixGolf score keeps increasining.

code:
Game24 v 1.1 KiXtart Golf running under KiXtart v4.11

In: 3388; Out: 8.0/(3.0-8.0/3.0) = 24 => Correct!!
In: 6143; Out: 6.0/(1.0-3.0/4.0) = 24 => Correct!!
In: 6451; Out: 6.0/(5.0/4.0-1.0) = 24 => Correct!!
In: 4429; Out: (9.0-2.0)*4.0-4.0 = 24 => Correct!!
In: 1234; Out: (1.0+2.0+3.0)*4.0 = 24 => Correct!!
In: 2268; Out: (2.0+6.0)+8.0*2.0 = 24 => Correct!!
In: 4466; Out: = => Correct!!
In: 1212; Out: = => Correct!!
In: 1899; Out: = => Correct!!
In: 7861; Out: = => Correct!!
In: 6480; Out: (6.0*4.0)+8.0/0.0 = 24 => Correct!!
In: 2472; Out: (2.0*7.0)*2.0-4.0 = 24 => Correct!!
In: 9952; Out: = => Correct!!
In: 8523; Out: (8.0*2.0)+3.0+5.0 = 24 => Correct!!
In: 3231; Out: (3.0*2.0)*(3.0+1.0) = 24 => Correct!!
In: 8093; Out: (8.0+0.0/9.0)*3.0 = 24 => Correct!!
In: 2676; Out: (7.0-2.0)*6.0-6.0 = 24 => Correct!!
In: 6412; Out: (6.0+2.0)*(4.0-1.0) = 24 => Correct!!
In: 3259; Out: (3.0+5.0*9.0)/2.0 = 24 => Correct!!
In: 2243; Out: (2.0+2.0+4.0)*3.0 = 24 => Correct!!
In: 5131; Out: (5.0+1.0)*(3.0+1.0) = 24 => Correct!!
In: 6271; Out: (6.0-2.0)*(7.0-1.0) = 24 => Correct!!
In: 5665; Out: 5.0*(6.0-6.0/5.0) = 24 => Correct!!
In: 6533; Out: (6.0+5.0-3.0)*3.0 = 24 => Correct!!
In: 9156; Out: (9.0-1.0*5.0)*6.0 = 24 => Correct!!
In: 1064; Out: (1.0+0.0)*6.0*4.0 = 24 => Correct!!
In: 0167; Out: = => Correct!!
In: 3477; Out: (3.0+4.0*7.0)-7.0 = 24 => Correct!!
In: 1289; Out: (8.0*9.0)/(2.0+1.0) = 24 => Correct!!
In: 3377; Out: (3.0+3.0/7.0)*7.0 = 24 => Correct!!

kix32 Kixgolf3.kix $f=junk.kix

KixGolf score = 472

code:
function game24($a,$b,$c,$d)

Dim $h, $j, $l, $p, $q, $r, $s, $t, $v, $, $x, $y, $z
$h = "+","-","/","*"
for $z=1 to 4
for $y=1 to 4
for $x=1 to 4
for each $p in $h
for each $q in $h
for each $r in $h
for each $j in split("0,8~0,8,10,18~0,12~4,16","~")
$ = ".0"
$s = ""+$a+$+$p+$b+$+$q+$c+$+$r+$d+$
for each $ in split($j,",")
$l = chr(40 + ($l="("))
$s = "" + left($s,$) + $l + substr($s,1+$)
next
$t = execute("$$v=$s")
if abs($v-24)< 1E-9
goto E
endif
next
next
next
next
$ = $b
$b = $c
$c = $d
$d = $
next
$ = $a
$a = $b
$b = $
next
$ = $c
$c = $d
$d = $
next
$s = ""

:E
$game24 = $s
exit
endfunction

_________________________
Home page: http://www.kixhelp.com/hb/

Top
#70101 - 2002-09-24 02:22 AM Re: KixGolf Results/Code
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
Nice work, Howard!

However... You're only generating 18 unique permutations...
What does that mean?
It means that there are some unique combos out there that will byte you!!

Coming up with an example soon...

You're only generating half the "c"'s and half the "d"'s, that is:
code:
abcd
abdc
acbd
acdb
adbc
adcb
bacd
badc
bcad
bcda
bdac
bdca
cadb
cbad
cdba
dacb
dbac
dcba

An example that will byte you: 1346...

[ 24. September 2002, 02:26: Message edited by: Fernando Madruga ]
_________________________
Later,   [b]Mad[/b]ruga

Top
#70102 - 2002-09-24 02:28 AM Re: KixGolf Results/Code
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
Man! This Madruga guy is a real pain! [Smile]

Sorry about that folks...
_________________________
Later,   [b]Mad[/b]ruga

Top
#70103 - 2002-09-24 02:48 AM Re: KixGolf Results/Code
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Beat you - 24 permutations (if my Perl hash can count right.)
code:
use strict;
my %d;

&a(1,2,3,4);
print scalar (keys %d) ."\n";
foreach my $x (sort keys %d)
{
print "$x\n";
}

sub a($a,$b,$c,$d)
{
my ($a,$b,$c,$d)=@_;
my $z;
for (my $i = 1; $i <=4; $i++)
{
for (my $j = 1; $j <=6; $j++)
{
for (my $k = 1; $k <=4; $k++)
{
$d{"$a,$b,$c,$d"}=1;
$z = $b;
$b = $c;
$c = $d;
$d = $z;
}
$z = $a;
$a = $b;
$b = $z;
}
$z = $c;
$c = $d;
$d = $z;
}
}

c:\data\scripts>junk.pl
24
1,2,3,4
1,2,4,3
1,3,2,4
1,3,4,2
1,4,2,3
1,4,3,2
2,1,3,4
2,1,4,3
2,3,1,4
2,3,4,1
2,4,1,3
2,4,3,1
3,1,2,4
3,1,4,2
3,2,1,4
3,2,4,1
3,4,1,2
3,4,2,1
4,1,2,3
4,1,3,2
4,2,1,3
4,2,3,1
4,3,1,2
4,3,2,1

code:
function game24($a,$b,$c,$d)

Dim $h, $j, $l, $p, $q, $r, $s, $t, $v, $, $x, $y, $z
$h = "+","-","/","*"
for $z=1 to 4
for $y=1 to 6
for $x=1 to 4
for each $p in $h
for each $q in $h
for each $r in $h
for each $j in split("0,8~0,8,10,18~0,12~4,16","~")
$ = ".0"
$s = ""+$a+$+$p+$b+$+$q+$c+$+$r+$d+$
for each $ in split($j,",")
$l = chr(40 + ($l="("))
$s = "" + left($s,$) + $l + substr($s,1+$)
next
$t = execute("$$v=$s")
if abs($v-24)< 1E-9
goto E
endif
next
next
next
next
$ = $b
$b = $c
$c = $d
$d = $
next
$ = $a
$a = $b
$b = $
next
$ = $c
$c = $d
$d = $
next
$s = ""

:E
$game24 = $s
exit
endfunction



[ 24. September 2002, 02:53: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
Page 2 of 5 <12345>


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.074 seconds in which 0.027 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org