#69755  20020915 12:19 AM
KiXtart Golf V: Game24

Sealeopard
KiX Master
Registered: 20010425
Posts: 11162
Loc: Boston, MA, USA

KiXtart Golf V: 24 Game
The general KiXtart Golf rules are at the end of the post. Following are the goal and rules for the current KiXtart Golf challange.
Goal Use four integer numbers from an integer range of 09 and the following basic math operations +, , *, /, (, and ) in such a way that the resulting formula equals 24.
Rules
[*]All four integers must be used [*]Each integer may only be used once [*]Only the basic math operators +, , *, / and parentheses ( and ) are allowed [*]The formula must conform to standard math rules, thus for example 3 / 2 = 1.5 or 1 / 3 = 0.3 period (0.333333....).
[*]The formula must conform to the math rules of precedence (for example * before +)
[*]Some combinations can result in multiple solutions, only one is to be returned
[*]Some combinations may not result in a valid solution, then an empty string is to be returned
Examples: ( 1 + 2 + 3 ) * 4 = 24 1 * 2 * 3 * 4 = 24
The prototye for the function is as follows:
code:
$outputstring=Game24($digit1,$digit2,$digit3,$digit4)
Example Given the input:
code:
$out = Game24(1,2,3,4)
one possible output string for $out might be
code:
$out = '(1+2+3)*4'
or
code:
$out = '1*2*3*4'
Test Code
code:
BREAK ON
DIM $rc, $out, $result, $i1, $i2, $i3, $i4
$rc=SETOPTION('Explicit','ON') $rc=SETOPTION('NoVarsInString','ON') $rc=SRND(@MSECS)
? 'Game24 KiXtart Golf running under KiXtart v'@KIX ? ''
$i1=1 $i2=2 $i3=3 $i4=4 ? 'Numbers = '+$i1+', '+$i2+', '+$i3+', '+$i4 $out=Game24($i1,$i2,$i3,$i4) if trim($out)='' ? 'Incorrect answer, there is a solution to this combination' ? ''+$out+' <> 24' else ? 'Please doublecheck your solution to guarantee a correct result' ? ''+$out+' = 24' endif ? ''
$i1=2 $i2=2 $i3=6 $i4=8 ? 'Numbers = '+$i1+', '+$i2+', '+$i3+', '+$i4 $out=Game24($i1,$i2,$i3,$i4) if trim($out)='' ? 'Incorrect answer, there is a solution to this combination' ? ''+$out+' <> 24' else ? 'Please doublecheck your solution to guarantee a correct result' ? ''+$out+' = 24' endif ? ''
$i1=4 $i2=4 $i3=6 $i4=6 ? 'Numbers = '+$i1+', '+$i2+', '+$i3+', '+$i4 $out=Game24($i1,$i2,$i3,$i4) if trim($out)='' ? 'Correct answer answer, there is no solution to this combination' else ? 'Incorrect answer, there is no solution to this combination' endif ? ''
$i1=3 $i2=3 $i3=8 $i4=8 ? 'Numbers = '+$i1+', '+$i2+', '+$i3+', '+$i4 $out=Game24($i1,$i2,$i3,$i4) if trim($out)='' ? 'Incorrect answer, there is a solution to this combination' ? ''+$out+' <> 24' else ? 'Please doublecheck your solution to guarantee a correct result' ? ''+$out+' = 24' endif ? ''
$i1=RND(9) $i2=RND(9) $i3=RND(9) $i4=RND(9) ? 'Numbers = '+$i1+', '+$i2+', '+$i3+', '+$i4 $out=Game24($i1,$i2,$i3,$i4) if trim($out)='' ? 'No solution found' ? ''+$out+' <> 24' else ? 'Please doublecheck your solution to guarantee a correct result' ? ''+$out+' = 24' endif ? ''
$i1=3 $i2=4 $i3=7 $i4=7 $out=Game24($i1,$i2,$i3,$i4) ? 'Numbers = '+$i1+', '+$i2+', '+$i3+', '+$i4 if trim($out)='' ? 'Incorrect answer, there is a solution to this combination' ? ''+$out+' <> 24' else ? 'Please doublecheck your solution to guarantee a correct result' ? ''+$out+' = 24' endif ? ''
$i1=1 $i2=2 $i3=8 $i4=9 $out=Game24($i1,$i2,$i3,$i4) ? 'Numbers = '+$i1+', '+$i2+', '+$i3+', '+$i4 if trim($out)='' ? 'Incorrect answer, there is a solution to this combination' ? ''+$out+' <> 24' else ? 'Please doublecheck your solution to guarantee a correct result' ? ''+$out+' = 24' endif ? ''
function game24($a,$b,$c,$d) endfunction
================================================================ KiXtart GOLF  How To Play ================================================================
Most importantly, anybody can play, no age restrictions, no penalties, no handicap!
The object in "real" golf is to hit the ball in the hole in the fewest strokes. The object in KiXtart Golf is to get from input (tee) to target (hole) in the fewest keystrokes.
Example: How many positive elements are in array $a?
Array $a could be of structure $a=[1, 2 ,3, 4, 5, 7, 8, 9]
One approach:
code:
for $b=0 to ubound($a) if $a[$b]>0 $c=$c+1 endif next
for a score of 45.
Another solution is: code]DO $b=$b+1 if $a[$b]>0 $c=$c+1 endif UNTIL $b>(UBOUND($a)+1)[/code]
for a score of 53.
Better approach: Code sample 1
================================================================ KiXtart GOLF  The Rules ================================================================
1) The goal of KiXtart Golf is to score the lowest strokes.
2) Strokes are all characters in a piece of code except whitespace characters, unless the whitespace character is necessary for the line of code to work. Therefore, carriage returns and line feeds do not count or spaces in between the '=' sign when assigning variables, e.g. '$a = $b' scores 5.
3) Code can be constructed any way you like, as long as it is syntactically correct with KiXtart.
4) The final solution MUST pass all test scripts that accompagny the KiXtart golf challenge.
5) The use of '$' as a variable is allowed.
6) In case of questions about a particular way to count the KiXtart Golf Challenge organizer has the last call.
7) During the private coding phase, no code is allowed to be posted. Violations result in disqualification of said player.
8) During the public coding phase, code should be posted, reused, and borrowed from other players.
9) The following script can be used to count the KiXtart Golf score: http://www.kixtart.org/cgibin/ultimatebb.cgi?ubb=get_topic;f=2;t=003608
================================================================ KiXtart GOLF  The Duration of the Competition ================================================================
1) Private coding phase: From date/time of posting the tournament challenge to the following Saturday, 3pm EST (BBS+6 time)
2) Public coding phase: From Saturday, 3pm EST (BBS+6 time) to the following Wednesday, 3pm EST (BBS+6 time)
3) Final results: The following Monday, 11am EST (BBS+6 time) [ 16. September 2002, 23:07: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top




#69761  20020915 01:07 PM
Re: KiXtart Golf V: Game24

Anonymous
Anonymous
Unregistered

Given the origins of the game, do you think it is fair for an answer to be able to use Kixtarts 'Integer maths' truncation? i.e. are the following results valid or not ? a) '(9/2)*63' b) '(9*5+4)/2' I think we should state that the result should adhere to 'real world' (ie floating point) maths.

Top




#69765  20020915 03:04 PM
Re: KiXtart Golf V: Game24

Howard Bullock
KiX Supporter
Registered: 20000915
Posts: 5809
Loc: Harrisburg, PA USA

My 12 year old son plays this game in Math class. Hopefully I'll get some time today to attack this.

Top




#69767  20020915 03:46 PM
Re: KiXtart Golf V: Game24

Howard Bullock
KiX Supporter
Registered: 20000915
Posts: 5809
Loc: Harrisburg, PA USA

You better not get caught underage drinking...or is that only a U.S. thing? [ 15. September 2002, 15:50: Message edited by: Howard Bullock ]

Top




#69769  20020915 04:05 PM
Re: KiXtart Golf V: Game24

Sealeopard
KiX Master
Registered: 20010425
Posts: 11162
Loc: Boston, MA, USA

Guys:
Just to clear up a potential point of confusion: a) '(9/2)*63' ==> (9/2)*63 = (4.5)*63 = 24 is a correct answer for the combination (2,3,6,9) b) '(9*5+4)/2' ==> (9*5+4)/2 = (45+4)/2 = (49)/2 = 24.5 is an invalid answer for the combination (2,4,5,9)
You must use 'real world' math, not the incorrect integer math module build into KiXtart.
I have updated the rules to reflect this issue.
I have also removed the EXECUTE statement that checks for correct answers since it will fail if the '/' is used and the operation results in fractions. This was an oversight in my coding since I forgot about the messedup integer math in KiXtart.
_________________________
There are two types of vessels, submarines and targets.

Top




Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart

0 registered
and 186 anonymous users online.


