#69817 - 2002-09-17 02:43 AM
Re: KiXtart Golf V: Game24
|
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
|
Top
|
|
|
|
#69819 - 2002-09-17 03:21 AM
Re: KiXtart Golf V: Game24
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
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 ]
|
Top
|
|
|
|
#69821 - 2002-09-17 11:03 AM
Re: KiXtart Golf V: Game24
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
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 ]
|
Top
|
|
|
|
#69826 - 2002-09-17 01:37 PM
Re: KiXtart Golf V: Game24
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
KixGolf v3.0.3 score = 413, running under KiXtart v4.10
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 496 anonymous users online.
|
|
|