Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Find the list of solutions to the 24 Game by trying all possible options
ResourceFunction["Game24Solutions"][ cards ] solve the 24 Game with an arbitrary number of cards. |
"Goal" | 24 | the target integer |
"AllowPower" | False | whether to allow Power as a possible operation |
"OutputForm" | String | determines the format of the output |
Use the function to find solutions to the 24 Game with four cards:
In[1]:= |
Out[1]= |
Each element of the output list is a String expression representing a solution to the puzzle. If no solutions are found, an empty list is returned:
In[2]:= |
Out[2]= |
Solve the puzzle with five cards given:
In[3]:= |
Out[3]= |
The values of all cards and the goal number must be positive integers:
In[4]:= |
Out[4]= |
Even though in the original 24 Game there is a limit to how high the value of a card can be, Game24Solve allows solutions with any positive integer values of cards:
In[5]:= |
Out[5]= |
OutputForm can be set to String, Hold or Inactive:
In[6]:= |
Out[6]= |
In[7]:= |
Out[7]= |
Set the goal number to 36:
In[8]:= |
Out[8]= |
Solve the game when using powers is allowed. Note that allowing Power as an operation increases the computation time as there are more combinations to be checked:
In[9]:= |
Out[9]= |
This work is licensed under a Creative Commons Attribution 4.0 International License