Carol is a small program I wrote to try out Palm Pilot programming. It is based on the numbers game from the popular Channel 4 gameshow, Countdown. The object is to combine six selected values using the normal mathematical operations of addition, subtraction, multiplication and (exact) division to get as close as possible to a target value, all within thirty seconds.
The six selected values are chosen from two categories, the large numbers and the small numbers. The large numbers drawn at random from the four values, 25, 50, 75 and 100. The small numbers are drawn at random from the twenty values, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, each repeated twice. The player therefore selects how many large values are required, none, one, two, three or four, the remaining values being drawn from the small values. One large value and five small values give the easiest game. The target value is a randomly generated number between 100 and 999.
Each selected value may only be used once in the solution, however it is not necessary to use all the values. Indeed it is considered more elegant to use as few values as possible.
Pressing the New button generates a new game. The number of large values can be selected using the drop list. The solution should be entered into the text box. The solution conforms to the following syntax:
literal-expression : decimal-digit-sequence '-' literal-expression primary-expression : literal-expression '(' expression ')' '#' multiplicative-expression : primary-expression multiplicative-expression 'x' primary-expression multiplicative-expression '*' primary-expression multiplicative-expression '/' primary-expression additive-expression : multiplicative-expression additive-expression '+' multiplicative-expression additive-expression '-' multiplicative-expression expression : additive-expression additive-expression '=' literal-expression expression-list : expression expression-list expressionSo the solution consists of a list of expressions each with the normal arithmetic operations. Each expression can use values created in previous expressions. The symbol
#stands for the result of the previous expression. The result is the value of the last expression. For example, all the following three expression lists evaluate to 952:
( 100 + 6 ) * 9 - 2 100 + 6 106 * 9 - 2 100 + 6 # * 9 - 2Note that in the Palm Pilot version, clicking a number or one of the operation buttons inserts it into the solution area. When the solution has been entered it can be checked by pressing the Check button. Pressing the Clear button clears the solution area.