Fernando Madruga
Starting to like KiXtart
Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
|
Oops...
I missed that "real math" thing...
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 ]
_________________________
Later,
[b]Mad[/b]ruga
|