24 Game
Does anyone remember the 24 card game? It's played with a deck of cards minus the face cards and 10. So there are four suits of 1(ace) to 9. Then the cards are divided between two players and each player lays two cards on the table. The first player to use those cards, along with addition, subtraction, multiplication, and division, to get to 24 wins the pile. The game is fun and easy but how can you calculate if four numbers are solvable? How many combinations of the 40 cards have solutions?
Yesterday I wrote a program that there
are 6561 possible combinations and 2133 card combinations with
solutions of 24. First the program loops through each combination of
cards. Then it checks each combination to see of there is a solution
of 24. I also wrote a method that will print the solution with
parenthesis to keep the precedence of each operator correct. There
are also options to customize the game. You can change the low and
high cards, check for solutions other than 24 and even check for a
range of solutions. Instead of putting this project in a jar file I'm
just going to post the code here and the output here.
