# 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

Contributed by:
Rauan Kaldybayev

ResourceFunction["Game24Solutions"][ solve the 24 Game with an arbitrary number of cards. |

ResourceFunction["Game24Solutions"] takes the following options:

"Goal" | 24 | the target integer |

"AllowPower" | False | whether to allow Power as a possible operation |

"OutputForm" | String | determines the format of the output |

The option "OutputForm" accepts String, Hold and Inactive as values. The result will be a list of solutions with the specified form. This can make the output more convenient for further operations. However, this makes it harder to read and less aesthetic. Moreover, multiplication and division by 1 gets omitted if "OutputForm" is set to Hold, and division and subtraction are presented through multiplication and addition if "OutputForm" is set to Inactive.

ResourceFunction["Game24Solutions"] returns an empty list if the puzzle is impossible.

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]= |

- 1.0.0 – 13 August 2020

This work is licensed under a Creative Commons Attribution 4.0 International License