Page 5 of 5 <12345
Topic Options
#70144 - 2002-09-25 03:19 AM Re: KixGolf Results/Code
Jack Lothian Offline
MM club member
*****

Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
Madruga,

Finding, something that has only one solution means that I have to rerun the test 5 times because I set the brackets permutations as the outside loop & I then set the priority order for the permutations. I would need to do 1 run with each bracket type at the end of the priority order. Painful - I would rather not since each run takes 2 hours. None of my previous runs are helpful since they all contained the no bracket case as the number 1 priority which is clearly wrong.

In my posted sample output above, I believe all outputs of the form "(a b) c d" & "(a b)(c d)" are unique solutions to that form. Since only 4 cases of "a (b c d)" were found they are also probably unique. As to the other cases??

[ 25. September 2002, 03:22: Message edited by: Jack Lothian ]
_________________________
Jack

Top
#70145 - 2002-09-25 03:33 AM Re: KixGolf Results/Code
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
Well... I give up. (BTW: I haven't oficially "given up" on this contest, but I take this opportunity to do so...)

I "merged" Jack Lothian's full suite set into my test program. You now have two options:
  • $TestSuite = 1 -> runs 50 random tests
  • $TestSuite = 2 -> runs Jack Lothian's test suite
(If you don't specify, it will run both...) Also, it logs into "game24.log".

This is where the "I give up" comes in!! I think this "should" work, but I'm getting a very weird error. Please someone grab this one (it comes pre-packaged with Howards function) and fix it as I'm going to bed. {edit} Howard has already fixed this and I updated the code here to incorporate his fixes. {/edit}

Also, if I have enough spare time later today during my lunch hour, I'll try to find out exactly what are the parenthesis combos that are needed.

BTW: I could post here the 457.176 bytes file where I stored all possible solutions, should anyone be interested in parsing through it instead of re-calculating. It's 25.295 lines of stuff like this:
code:
7889 : 8-(7-9)*8
7889 : 8-8*(7-9)

(It can be turned into an 89.331 bytes zip file)

{edit} Forgot to post the code... [Smile] {/edit}
{edit} Pasted fixed code. Thks Howard! {/edit}
code:
BREAK ON

Global $Target, $Valid, $TestSuite, $Lix

$Lix = DisplayText( 'Game24 v 2.0 KiXtart Golf running under KiXtart v'+@KIX )
$Lix = DisplayText( '' )

Global $OUTPUTLINE, $LOGGING, $LOGGINGFILE, $OUTPUT, $SCROLLING, $WRAPATEOL

$LOGGING = 1
$LOGGINGFILE = "game24.log"
$SCROLLING = 1

$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"

$GOOD = "0038004601280136013701380139014501460147"
+ "0148015501560226023402360238023902440246"
+ "0248025702580266026802690288033403350337"
+ "0338033903440346034803490358035903660367"
+ "0368037803880389044504460447044804560466"
+ "0467046804690478048805660569058806890699"
+ "0789088811181126112711281129113411351136"
+ "1137113811391144114511461147114811491155"
+ "1156115711581166116811691188122412251226"
+ "1227122812291233123412351236123712381239"
+ "1244124512461247124812491255125612571258"
+ "1259126612671268126912771278127912881289"
+ "1333133413351336133713381339134413451346"
+ "1347134813491356135713581359136613671368"
+ "1369137713781379138813891399144414451446"
+ "1447144814491455145614571458145914661467"
+ "1468146914771478147914881489155515561559"
+ "1566156715681569157815791588158915991666"
+ "1668166916791688168916991779178817891799"
+ "1888188922232224222522272228222922332234"
+ "2235223622372238223922442245224622472248"
+ "2249225522562257225822592266226722682269"
+ "2277227822882289233323352336233723382339"
+ "2344234523462347234823492355235623572358"
+ "2359236623672368236923772378237923882389"
+ "2399244424452446244724482449245524562457"
+ "2458245924662467246824692477247824792488"
+ "2489249925572558255925662567256825692577"
+ "2578257925882589266626672668266926782679"
+ "2688268926992778278827892888288928993333"
+ "3334333533363337333833393344334533463347"
+ "3348334933553356335733593366336733683369"
+ "3377337833793388338933993444344534463447"
+ "3448344934553456345734583459346634683469"
+ "3477347834793489349935563557355835593566"
+ "3567356835693578357935883589359936663667"
+ "3668366936773678367936883689369937773778"
+ "3779378837893799388838893899399944444445"
+ "4446444744484449445544564457445844684469"
+ "4477447844794488448945554556455745584559"
+ "4566456745684569457745784579458845894599"
+ "4666466746684669467746784679468846894699"
+ "4777477847884789479948884889489955555556"
+ "5559556655675568557755785588558955995666"
+ "5667566856695677567856795688568956995779"
+ "5788578958885889666666686669667966886689"
+ "678967996888688968997889"

$BAD = "0000000100020003000400050006000700080009"
+ "0011001200130014001500160017001800190022"
+ "0023002400250026002700280029003300340035"
+ "0036003700390044004500470048004900550056"
+ "0057005800590066006700680069007700780079"
+ "0088008900990111011201130114011501160117"
+ "0118011901220123012401250126012701290133"
+ "0134013501440149015701580159016601670168"
+ "0169017701780179018801890199022202230224"
+ "0225022702280229023302350237024502470249"
+ "0255025602590267027702780279028902990333"
+ "0336034503470355035603570369037703790399"
+ "0444044904550457045804590477047904890499"
+ "0555055605570558055905670568057705780579"
+ "0589059906660667066806690677067806790688"
+ "0777077807790788079908890899099911111112"
+ "1113111411151116111711191122112311241125"
+ "1133115911671177117811791189119912221223"
+ "1299135514991557155815771667167716781777"
+ "1778189919992222222622792299233425552556"
+ "2599267727772779279929993358346734883555"
+ "3577445944664467449947794999555755585569"
+ "5579577757785799589959996667667766786699"
+ "6777677867796788699977777778777977887789"
+ "779978887899799988888889889989999999"

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

Dim $i

if ( $TestSuite == 0 ) or ( $TestSuite == 1 )
$Lix = DisplayText( "Running Test Suite #1: fifty random combos" )
; Random tests
for $i = 1 to 50
test24(RND(9),RND(9),RND(9),RND(9),3)
next
endif
if ( $TestSuite == 0 ) or ( $TestSuite == 2 )
$Lix = DisplayText( "Running Test Suite #2: Jack Lothian's Validation Suite" )
; 1st let's run tests WITH solutions
for $i = 1 to len($GOOD) step 4
test24(Int(SubStr($GOOD,$i,1)),Int(SubStr($GOOD,$i+1,1)),Int(SubStr($GOOD,$i+2,1)),Int(SubStr($GOOD,$i+3,1)),1)
next
; Now let's run tests WITHOUT solutions
for $i = 1 to len($BAD) step 4
test24(Int(SubStr($BAD,$i,1)),Int(SubStr($BAD,$i+1,1)),Int(SubStr($BAD,$i+2,1)),Int(SubStr($BAD,$i+3,1)),2)
next
endif

$Lix = DisplayText( '' )

; 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
$Lix = DisplayText( $str )
endfunction

Dim $shellcommand
$shellcommand='kix32 Kixgolf3.kix $f='+@scriptname
$Lix = DisplayText( $shellcommand )
Shell $shellcommand

;FUNCTION DisplayText
;
;AUTHOR Jens Meyer (sealeopard@usa.net)
;
;ACTION Prints an information text on screen
;
;SYNTAX DISPLAYTEXT(STRING [, TEXTCOLOR])
;
;PARAMETERS $string
; Required string containing the information text
;
; $textcolor
; Optional text color
;
;RETURNS 0 if successful, otherwise 1
;
;REMARKS Requires the global variables $OUTPUTLINE (output line counter),
; $LOGGING (true if additional logging to textfile is enabled),
; $LOGGINGFILE (filename for additional logging),
; $OUTPUT (default output redirector, defaults to the screen),
; $SCROLLING (enables scrolling display mode).
; Text will get wrapped into the next line(s).
; $WRAPATEOL is used to maintain state between function calls and
; should speed up execution time.
;
;DEPENDENCIES none
;
;EXAMPLE $retcode=displaytext('This is an informal text!')
;
;KIXTART BBS http://kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000036
;
function displaytext($text, optional $textcolor)
Dim $textlength

if vartype($WRAPATEOL)<2
global $WRAPATEOL
$WRAPATEOL=setoption('WrapAtEOL','ON')
if $WRAPATEOL='OFF'
$retcode=setoption('WrapAtEOL','OFF')
$WRAPATEOL=0
else
$WRAPATEOL=1
endif
endif

if $OUTPUTLINE>22 and $SCROLLING=0
cls
$OUTPUTLINE = 0
endif

if $text<>''
if $textcolor=''
$textcolor='w/n'
endif
$retcode=execute('color '+$textcolor)

? ' '
$textlength = len($text)
if $textlength<=78 or $WRAPATEOL
if $LOGGING
$retcode=redirectoutput($LOGGINGFILE,0)
? $text
$retcode=redirectoutput($OUTPUT)
endif
at($OUTPUTLINE,1) $text
if $WRAPATEOL
$OUTPUTLINE=$OUTPUTLINE + val(($textlength+1)/80) + 1
else
$OUTPUTLINE = $OUTPUTLINE + 1
endif
else
if $LOGGING
$retcode=redirectoutput($LOGGINGFILE,0)
? substr($text,1,78)
$retcode=redirectoutput($OUTPUT)
endif
at($OUTPUTLINE,1) substr($text,1,78)
$OUTPUTLINE = $OUTPUTLINE + 1
$text = substr($text,79,$textlength-78)
$retcode=displaytext($text, $textcolor)
return
endif
endif

$displaytext=@error

endfunction

; 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: 5 needed combinations
; abcd
; (ab)(cd)
; a(bcd)
; (abc)d

; 0 need (ab)cd \
; 0 need a(bc)d - 1 solution (1169) needs at any one of these!
; 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, $z
$h = "+","-","/","*"
for $z=1 to 4
for $y=1 to 4
for $x=1 to 2
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
$ = $c
$c = $d
$d = $
next
$ = $b
$b = $c
$c = $d
$d = $
next
$ = $a
$a = $d
$d = $
next
$s = ""

:E
$game24 = $s
exit
endfunction
;!
;!



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

Top
#70146 - 2002-09-25 03:44 AM Re: KixGolf Results/Code
Jack Lothian Offline
MM club member
*****

Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
I believe the 50 random sets will just be simple rotation of the sets I gave. If your program is following jens specs & generating all the 24 permutations of the incoming 4 numbers then the 50 random sets are irrelevant. In theory, the 715 sets I gave cover the complete universe of possibilities.
_________________________
Jack

Top
#70147 - 2002-09-25 03:46 AM Re: KixGolf Results/Code
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
Why 715? Where did you get that number from, that is, how did you arrive at that number?

(Just curious:))

{edit} Also, it's in there just to be a "quick" check... 715 checks can take some time to go through... {/edit}

[ 25. September 2002, 03:48: Message edited by: Fernando Madruga ]
_________________________
Later,   [b]Mad[/b]ruga

Top
#70148 - 2002-09-25 03:56 AM Re: KixGolf Results/Code
Jack Lothian Offline
MM club member
*****

Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
All other sets are rotations of these basic sets. They came from the basic 4 "For" statements that I mentioned earlier in the discussion in a comment to Richard. I suspect it's the ratio of 2 factorials.

I just had an interesting thought. If someone can reduce the number of operators or the number of number rotations & still pass the above test then it should still meet Jens criteria. It will be just like Howard dropping 3 bracket types & still getting the correct solution.

[ 25. September 2002, 04:04: Message edited by: Jack Lothian ]
_________________________
Jack

Top
#70149 - 2002-09-25 03:58 AM Re: KixGolf Results/Code
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
That will be left as an exercise to the reader(s)... [Smile]

Good night all. C U Later.
_________________________
Later,   [b]Mad[/b]ruga

Top
#70150 - 2002-09-25 04:33 AM Re: KixGolf Results/Code
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Missing right quote:
code:
  $Lix = DisplayText( "Running Test Suite #1: twenty random combos )  

{edit} I double pasted the script and cause myself some grief.

Bad Var: $LOGGINGGILE = "game24.log" should be $LOGGINGFILE = "game24.log"

It is now running:

code:
Game24 v 2.0 KiXtart Golf running under KiXtart v4.12 Beta 1
Running Test Suite #1: twenty random combos1\kix32 junk.kix
In: 0100; Out: = => Correct!!
In: 4442; Out: (4.0+4.0+4.0)*2.0 = 24 => Correct!!
In: 0881; Out: = => Correct!!
In: 6774; Out: (6.0+7.0)+7.0+4.0 = 24 => Correct!!
In: 9676; Out: (9.0-7.0)*(6.0+6.0) = 24 => Correct!!
In: 0552; Out: = => Correct!!
In: 3017; Out: (3.0+0.0)*(1.0+7.0) = 24 => Correct!!
In: 0292; Out: = => Correct!!
In: 1098; Out: = => Correct!!
In: 9254; Out: (9.0+2.0-5.0)*4.0 = 24 => Correct!!
In: 6262; Out: (6.0+2.0)*6.0/2.0 = 24 => Correct!!
In: 0214; Out: = => Correct!!
In: 9713; Out: (9.0/3.0)*(7.0+1.0) = 24 => Correct!!
In: 5428; Out: (5.0-4.0+2.0)*8.0 = 24 => Correct!!
In: 7329; Out: (7.0*3.0-9.0)*2.0 = 24 => Correct!!
In: 5107; Out: = => Correct!!
In: 7057; Out: = => Correct!!
In: 5557; Out: = => Correct!!
In: 4231; Out: (4.0+2.0)*(3.0+1.0) = 24 => Correct!!
In: 2960; Out: (2.0*9.0)+6.0+0.0 = 24 => Correct!!
In: 1567; Out: (1.0+5.0*6.0)-7.0 = 24 => Correct!!
In: 4342; Out: (4.0*3.0)*(4.0-2.0) = 24 => Correct!!
In: 6242; Out: (6.0+2.0+4.0)*2.0 = 24 => Correct!!
In: 6974; Out: (6.0/4.0)*(9.0+7.0) = 24 => Correct!!
In: 9281; Out: (9.0+2.0*8.0)-1.0 = 24 => Correct!!
In: 3431; Out: 3.0*(4.0+3.0+1.0) = 24 => Correct!!
In: 0977; Out: = => Correct!!
In: 2371; Out: (2.0+3.0*7.0)+1.0 = 24 => Correct!!
In: 4421; Out: (4.0+4.0)*(2.0+1.0) = 24 => Correct!!
In: 0020; Out: = => Correct!!
In: 8607; Out: = => Correct!!



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

Top
#70151 - 2002-09-25 01:18 PM Re: KixGolf Results/Code
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
Thanks!

That's one of the disadvantages of having a free form language: you don't keep errors within a couple of lines! They show up in the most "weird" places tons of lines after...

I'll incorporate the changes into the posted script.
_________________________
Later,   [b]Mad[/b]ruga

Top
#70152 - 2002-09-25 03:15 PM Re: KixGolf Results/Code
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Richard, I tried to use your udfAnagram() to replace code in Game24() but couldn't get to a point of reducing code.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
Page 5 of 5 <12345


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

Who's Online
0 registered and 170 anonymous users online.
Newest Members
gkustra, emnipetro, Hirze, thequeen, ameliaryan
17642 Registered Users

Generated in 0.035 seconds in which 0.012 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