Fernando Madruga
Starting to like KiXtart
Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
|
On second though, Howard, are you sure your code is ok? I mean, you work with only 16 permutations of the possible 24!! Try runing under my improved test script (streamlined the output, and fixed some bugs). Also, and since one of the solutions that your code fails to find is one that has nothing to do with the permutations, there's bound to be some major error in there other than the missing permutations... Try your code with the 5555 set and check it out...
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(1,2,3,4,1) test24(2,2,6,8,1) test24(4,4,6,6,2) test24(3,3,8,8,1) 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) 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) endfunction ;! ;!
{edit} Added an if to only add (.0)s if there's no '.' in the returned string. {/edit} [ 23. September 2002, 20:40: Message edited by: Fernando Madruga ]
_________________________
Later,
[b]Mad[/b]ruga
|