Function Resource

Game24Solutions

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.

ResourceFunction["Game24Solutions"][ cards, Goal myNumber ]

Solve the 24 Game with an arbitrary number of cards and goal number.

ResourceFunction["Game24Solutions"][ cards, Goal myNumber, AllowPowerTrue ]

Solve the 24 Game with an arbitrary number of cards and goal number, with power added to the list of possible operations.

Details and Options

Returns a list of Hold expressions, where each expression corresponds to a unique solution.
Returns an empty list if the puzzle is impossible.

Examples

Basic Examples

Use the function to find solutions to the 24 Game with four cards:

In[1]:=
ResourceFunction[ "https://www.wolframcloud.com/obj/rauan234/DeployedResources/\
Function/Game24Solutions"][{6, 2, 7, 4}]
Out[1]=

Each element of the output list is a Hold expression representing a solution to the puzzle. If no solutions were found, and empty list is returned:

In[2]:=
ResourceFunction[ "https://www.wolframcloud.com/obj/rauan234/DeployedResources/\
Function/Game24Solutions"][{8, 13, 21, 34}]
Out[2]=

Solve the puzzle with five cards given:

In[3]:=
ResourceFunction[ "https://www.wolframcloud.com/obj/rauan234/DeployedResources/\
Function/Game24Solutions"][{8, 4, 7, 1, 9}, PrettyPrint -> True]
Out[3]=

Here and in further examples PrettyPrint was set to True to make the output more easily readable. See the options section for more information.


Play with the game with the goal number being 36:

In[4]:=
ResourceFunction[ "https://www.wolframcloud.com/obj/rauan234/DeployedResources/\
Function/Game24Solutions"][{6, 3, 5, 3}, Goal -> 36, PrettyPrint -> True]
Out[4]=

Solve the game when using powers is allowed:

In[5]:=
ResourceFunction[ "https://www.wolframcloud.com/obj/rauan234/DeployedResources/\
Function/Game24Solutions"][{4, 2, 3, 5}, AllowPower -> True, PrettyPrint -> True]
Out[5]=

Scope

The cards must come in a list:

In[6]:=
ResourceFunction[ "https://www.wolframcloud.com/obj/rauan234/DeployedResources/\
Function/Game24Solutions"][{1, 2, 3, 4}, PrettyPrint -> True]
Out[6]=
In[7]:=
ResourceFunction[ "https://www.wolframcloud.com/obj/rauan234/DeployedResources/\
Function/Game24Solutions"][1, 2, 3, 4, PrettyPrint -> True]
Out[7]=

The values of all cards and the goal number must be positive integers:

In[8]:=
ResourceFunction[ "https://www.wolframcloud.com/obj/rauan234/DeployedResources/\
Function/Game24Solutions"][{-1, Sqrt[2], 3 I, Log[4]}, Goal -> 24/7]
Out[8]=

Even though in the original 24 Game there is a limit to how high the value of a card can be, Game24Solve allows to solve the puzzle with any positive integer values of cards:

In[9]:=
ResourceFunction[ "https://www.wolframcloud.com/obj/rauan234/DeployedResources/\
Function/Game24Solutions"][{104, 92, 1973, 3946}, PrettyPrint -> True]
Out[9]=

Options

Set PrettyPrint to True so that the solution was presented as a Column of Strings:

In[10]:=
ResourceFunction[ "https://www.wolframcloud.com/obj/rauan234/DeployedResources/\
Function/Game24Solutions"][{4, 3, 2, 1}, PrettyPrint -> True]
Out[10]=

This option doesn't affect the content of the output but simply changes the way it is presented. It doesn't affect the algorithms the function uses or its' running time:

In[11]:=
ResourceFunction[ "https://www.wolframcloud.com/obj/rauan234/DeployedResources/\
Function/Game24Solutions"][{4, 3, 2, 1}, PrettyPrint -> False]
Out[11]=