#70084 - 2002-09-23 09:16 PM
Re: KixGolf Results/Code
|
Howard Bullock
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 ]
|
Top
|
|
|
|
#70087 - 2002-09-23 09:50 PM
Re: KixGolf Results/Code
|
Howard Bullock
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. Or am I using it incorrectly?
|
Top
|
|
|
|
#70089 - 2002-09-23 11:05 PM
Re: KixGolf Results/Code
|
Fernando Madruga
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
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
|
Top
|
|
|
|
#70091 - 2002-09-24 12:40 AM
Re: KixGolf Results/Code
|
Fernando Madruga
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
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 ]
|
Top
|
|
|
|
#70094 - 2002-09-24 12:58 AM
Re: KixGolf Results/Code
|
Fernando Madruga
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
|
|
|
|
#70096 - 2002-09-24 01:05 AM
Re: KixGolf Results/Code
|
Howard Bullock
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
|
Top
|
|
|
|
#70100 - 2002-09-24 01:59 AM
Re: KixGolf Results/Code
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
there
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
|
Top
|
|
|
|
#70103 - 2002-09-24 02:48 AM
Re: KixGolf Results/Code
|
Howard Bullock
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 ]
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 918 anonymous users online.
|
|
|