Page 4 of 7 « First<23456>Last »
Topic Options
#69815 - 2002-09-17 02:18 AM Re: KiXtart Golf V: Game24
Jack Lothian Offline
MM club member
*****

Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
True but one of jens primary goals was to use real number math not just integer number math. It was in this context, I felt was it was incorrect.
_________________________
Jack

Top
#69816 - 2002-09-17 02:23 AM Re: KiXtart Golf V: Game24
Jack Lothian Offline
MM club member
*****

Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
Interestingly, I stripped 100 characters out of my code mainly through eliminations of cdbl's & at about character 98, my script started to fail again. Got put them all back in I guess.
_________________________
Jack

Top
#69817 - 2002-09-17 02:43 AM Re: KiXtart Golf V: Game24
Fernando Madruga Offline
Starting to like KiXtart

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

I missed that "real math" thing... [Smile]

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
#69818 - 2002-09-17 03:10 AM Re: KiXtart Golf V: Game24
Jack Lothian Offline
MM club member
*****

Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
If there are 11 combinations of brackets my script is wrong since I only had 7. It is easy to fix but it would add another 100 characters to my script.

Initially, I thought the extras were just simple rotations of the orginal 7 but I could be wrong. The java script on the web only deals with 7 basic permutations as well. I am too tired right now to worry it out though.

As to your question, all contributions are welcome but this is just a fun thing & I don't think we need to over do it.
_________________________
Jack

Top
#69819 - 2002-09-17 03:21 AM Re: KiXtart Golf V: Game24
Howard Bullock Offline
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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#69820 - 2002-09-17 10:41 AM Re: KiXtart Golf V: Game24
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
Madruga and others,

can you give me an example why "((ab)c)d" is also a combination?
I think it's the same as "(ab)cd"

Also the number of operator permutations I think is 128.
Why? check this:

-1*-4*-2*-3

So the possible permutations are 2*4*4*4=128
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#69821 - 2002-09-17 11:03 AM Re: KiXtart Golf V: Game24
Richard H. Administrator Offline
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
#69822 - 2002-09-17 11:48 AM Re: KiXtart Golf V: Game24
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
pat, if you read our older posts, you would see discussion on this issue.
isn't:
-1*-4*-2*-3

just the same as:
1*4*-2*-3
_________________________
!

download KiXnet

Top
#69823 - 2002-09-18 12:27 AM Re: KiXtart Golf V: Game24
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
Jooel,

the result is the same, but the formula isn't:

I like it when it't 20 degrees Celsius outside, but when it's -20 degrees I'd rather stay inside!!! [Big Grin]
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#69824 - 2002-09-17 01:08 PM Re: KiXtart Golf V: Game24
Fernando Madruga Offline
Starting to like KiXtart

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

can you give me an example why "((ab)c)d" is also a combination?
I think it's the same as "(ab)cd"

I guess you're right... I was just laying down all the choices, so I could later "trim"/simplify them.

It looks as if the outer parentheses will only make sense if the operator before 'c' is a low precedence one (+ or -); if that is the case, then the inner parentheses will not be needed and so becomes '(abc)d'... On the other hand, if it's a high precedence one (* or /) then the outer parentheses will not be needed and it becomes '(ab)cd'...

Maybe those 7 cases someone else pointed out as being used by the java applet will be enough... Haven't checked into it yet though...
_________________________
Later,   [b]Mad[/b]ruga

Top
#69825 - 2002-09-17 01:17 PM Re: KiXtart Golf V: Game24
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Maybe I'm missing something...
(1+2)+3/3 = 4
((1+2)+3)/3 = 2

Top
#69826 - 2002-09-17 01:37 PM Re: KiXtart Golf V: Game24
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
KixGolf v3.0.3 score = 413, running under KiXtart v4.10
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#69827 - 2002-09-17 02:15 PM Re: KiXtart Golf V: Game24
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
I think I've found a solution with the rounding problems when using CDBL. I can reformat a formula in such a way that it does not require doubles but only integers. This method could be used for those permutations where fractions might show up as interim results.
code:
                  3
(3+3/7)*7 = ( 3 + - ) * 7
7

3 * 7 + 3
= ( --------- ) * 7
7

= ( 3 * 7 + 3 ) / 7 * 7

= ( 3 * 7 + 3 ) * 7 / 7

= 24

or generic

(a+b/c)*d = ( a * c + b) * d / c

By essentially moving the division I end up with an integer devidied by an integer.

[ 17. September 2002, 14:16: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#69828 - 2002-09-17 02:21 PM Re: KiXtart Golf V: Game24
Jack Lothian Offline
MM club member
*****

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

I woke up this morning thinking the same as Richard. Madruga's 4 extra combination are legitimate & different.

What I also realized is Madruga is fundamentally changing the rules of the game since he is permitting nested parenthesis. Note in all examples of the school game on the web, there is either a template or rules that don't permit nested parenthesis or multiple operaters between numbers.

While your rules might permit nested parenthesis most of us picked up on the fact you wanted us to solve the standard school template. You might clarify this point.
_________________________
Jack

Top
#69829 - 2002-09-17 02:29 PM Re: KiXtart Golf V: Game24
Jack Lothian Offline
MM club member
*****

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

We can have up to 3 divisions though & they can be placed within & without parenthesis & in various combinations with other operators. While I think you are correct in saying that we could recast all so that decimal math was unneeded, programming all the continuances could be a major undertaking. Just identifying all the division patterns plus their alternatives might be a several day project.

Also to avoid decimal math your solution needs to go one step further. If your final result is a fraction, you need to check if the denominator is a factor in the numerator. If it is, then integer division can be used to verify compliance with 24 & otherwise it can not be a solution since the result is non integer.

[ 17. September 2002, 14:36: Message edited by: Jack Lothian ]
_________________________
Jack

Top
#69830 - 2002-09-17 02:30 PM Re: KiXtart Golf V: Game24
Fernando Madruga Offline
Starting to like KiXtart

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

Maybe I'm missing something...
(1+2)+3/3 = 4
((1+2)+3)/3 = 2

You are indeed... The 2nd example does NOT need the inner brackets: (1+2+3)/3 = 2...
_________________________
Later,   [b]Mad[/b]ruga

Top
#69831 - 2002-09-17 02:37 PM Re: KiXtart Golf V: Game24
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Aha. Got it.

KixGolf v3.0.3 score = 423, running under KiXtart v4.11 RC 1

{edit}
KixGolf v3.0.3 score = 414, running under KiXtart v4.11 RC 1

[ 17. September 2002, 14:53: Message edited by: Richard Howarth ]

Top
#69832 - 2002-09-17 02:40 PM Re: KiXtart Golf V: Game24
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
As for the rounding error question, I don't think we'll have too much trouble with it. Just check the result to be within an error margin as I did in my version of the test program. It should work for all situations: with just 3 operations, you will surelly not have an error THAT big... Besides, with only 4 1-digit numbers and 3 operations, you would not arrive to a "near-perfect" score unless it's a correct answer...

As for the nested parentheses, in fact I had not noticed that I'd raise such an issue! [Smile] As I said in another post, I was simply laying down the options to have a clearer view of the problem and potential solutions... Being as it is, that this is a "game" about program size and not efficiency, I may as well end up using all parentheses if that simplifies my code in any way... [Smile]
_________________________
Later,   [b]Mad[/b]ruga

Top
#69833 - 2002-09-17 02:57 PM Re: KiXtart Golf V: Game24
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
Did some checking: my verification for the example nested parentheses seems to hold true for all the other nested parentheses! So, it looks as if they are not needed as any expression using them can be rewriten using only one set instead of two... In that case, we get left with only 7 diferent cases... [Smile] Does that 7 ring a bell on anyone? [Smile]
_________________________
Later,   [b]Mad[/b]ruga

Top
#69834 - 2002-09-17 03:24 PM Re: KiXtart Golf V: Game24
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
KixGolf v3.0.3 score = 409, running under KiXtart v4.11 RC 1
Runs much slower now though.

Top
Page 4 of 7 « First<23456>Last »


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

Who's Online
0 registered and 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.073 seconds in which 0.026 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org