Starting from:

$29.99

24 Card Game HW



1 24 Card Game
In this assignment, you have to find all the valid postfix notations that include the four cards,
and also addition, subtraction, multiplication, division, modulus and concatenation operations.
Evaluate these postfix notations and see which of them lead to 24.
2 Generating valid postfix expressions
The find_postfix() function will find all valid postfix notations for each 4 card combination and
evaluate them to see if they are equal to 24. You will first call your isvalid() method to check the
expression is valid. Then you will call the evaluate() method inside of this function to evaluate the
expression. There are five different possible forms of a valid postfix notation for 4 cards, where C
denotes a card value and X denotes an operation:
1. CCXCCXX
2. CCCCXXX
3. CCCXCXX
4. CCXCXCX
5. CCCXXCX
Every valid possible postfix expression will take one of these five forms. Note that when you
have 4 values, it is only possible to have 3 operations in the postfix expression for it to be a valid
expression. You will need to use three nested loops iterating over the ops list created for you in
order to generate every possible postfix notation. Once you have generated all of these notations,
evaluate them, and if an expression evaluates to 24, add it to the set of results.
3 concatenate() function
In this function, you will concatenate the values of two cards and return the combined value. This
is one of the operations used in the ops list.
For example: if the card values are 4 and 7, this function should return 47.
1
4 Output of your code
The output of your code is stored in a results set. The contents of the results set along with the
number of solutions is displayed as the final output. For example: Input given is “AAAJ”
J A + A A + *
A A + A J + *
A J + A A + *
A A + J A + *
4 solutions.
2

More products