Get Started »

# Math Puzzles

The Wolfram Language is an excellent platform for working through challenging math problems and puzzles. Once you know the principles, exploration is easy.

Suppose you wanted to find the number of positive integers up to 1,000,000 that have no common factors with 1,000,000.

You could start by testing the first million positive integers against 1,000,000 with CoprimeQ:

 In[1]:= ⨯ `CoprimeQ[Range[1000000], 1000000] // Short`
 Out[1]=

Automatically remove the False entries by replacing them with Nothing:

 In[2]:= ⨯ `% /. False -> Nothing // Short`
 Out[2]=

Then find the Length of the resulting list:

 In[3]:= ⨯ `Length[%]`
 Out[3]=

Combine these steps into one line:

 In[4]:= ⨯ `Length[CoprimeQ[Range[1000000], 1000000] /. False -> Nothing]`
 Out[4]=

Symbolic expressions often yield direct solutions. Given a positive integer k, can you find a formula for the sum 1k+2k+...+nk?

Solution for k=2:

 In[1]:= ⨯ ```\!\( \*UnderoverscriptBox[\(\[Sum]\), \(i = 1\), \(n\)] \*SuperscriptBox[\(i\), \(2\)]\)```
 Out[1]=

The general solution is the nth harmonic number of order `−`k:

 In[2]:= ⨯ ```\!\( \*UnderoverscriptBox[\(\[Sum]\), \(i = 1\), \(n\)] \*SuperscriptBox[\(i\), \(k\)]\)```
 Out[2]=

With built-in graphics, it’s easy to visualize geometric problems. Consider the following figure:

 In[1]:= ⨯ ```Labeled[Graphics[ shape = {Rectangle[], Rectangle[{0, 1}], Rectangle[{1, 0}]}], n]```
 Out[1]=

For a given base length n, is it possible to fill this shape with similar shapes of base length 1?

Solution for n=2:

 In[2]:= ⨯ ```Graphics[{ Scale[shape, 2, {0, 0}], {Yellow, shape}, {Green, Translate[shape, {1, 1}]}, {Blue, Translate[Rotate[shape, -90 \[Degree]], {0, 2}]}, {Red, Translate[Rotate[shape, 90 \[Degree]], {2, 0}]} }]```
 Out[2]=

Solution for n=3:

 In[3]:= ⨯ ```Graphics[{ Scale[shape, 3, {0, 0}], {Orange, shape}, {Magenta, Translate[Rotate[shape, -90 \[Degree]], {0, 2}]}, {Green, Translate[shape, {1, 1}]}, {Red, Translate[Rotate[shape, 90 \[Degree]], {2, 0}]}, {Black, Translate[shape, {0, 4}]}, {Blue, Translate[Rotate[shape, 180 \[Degree]], {1, 4}]}, {Gray, Translate[shape, {2, 2}]}, {Purple, Translate[Rotate[shape, -90 \[Degree]], {4, 1}]}, {Yellow, Translate[Rotate[shape, 90 \[Degree]], {4, 0}]} }]```
 Out[3]=

Famous puzzles, problems and riddles are available through natural-language input:

 In[1]:= X `Tower of Hanoi 2 disk solution`
 Out[1]=

Many more in-depth examples can be found at the Wolfram Demonstrations Project.