Source As PDF

Fish Riddle

  • Patrick M. Elsen
  • Updated 2021-01-19

The internet is full of distractions, and unfortunately, I am not always impervious to all of them. Some of them can lead to interesting results. Today, my distraction came in the shape of a riddle from a riddle from a TED-Ed video, which got me to explore my (rusty, but still somewhat present) math skills1.

Now, I was excited to learn about the puzzle to see if I could use programming (I was thinking of a constraint solver or possibly just brute-forcing it) to solve it. But alas, it turns out that it’s just solvable with plain maths πŸ€·πŸ½β€β™€οΈ. So let’s dive in and see what we can do here.

1 The problem

You can watch the video to get the story of the puzzle, but it breaks down like this: you have three quadrants, each with a number of fish tanks and sharks in it. You know how many there are in both the first and second quadrants, and you must find out how many there are in the third quadrant.

So let’s first introduce a number of variables to help is keep track of things. We define:

2 The constraints

There are six constraints given in the puzzle.

  1. There are 50 creatures in total, including sharks and fish.

fi=nitisi=hifiβˆ‘i=13si=50\begin{array}{rcl} f_i & = & n_i t_i\\ s_i & = & h_i f_i\\ \sum_{i=1}^{3} s_i & = & 50 \end{array}

  1. Each sector has anywhere from one to seven sharks, with no two sectors having the same nmber of sharks.

βˆ€i∈{1,2,3}:1≀hi≀7βˆ€i,j∈{1,2,3}:hiβ‰ hj \begin{array}{rl} \forall i \in \{1, 2, 3\}: & 1 \leq h_i \leq 7\\ \forall i, j \in \{1, 2, 3\}: & h_i \neq h_j \end{array}

  1. Each tank has an equal number of fish. Since this is true, we will just use tt to refer to any of tit_i, since they are all the same.

βˆ€i,j∈{1,2,3}:ti=tj \begin{array}{rl} \forall i, j \in \{1, 2, 3\}: & t_i = t_j \end{array}

  1. In total, there are 13 or fewer fish tanks.

βˆ‘i=13ni≀13 \begin{array}{rcl} \sum_{i=1}^{3} n_i & \leq & 13 \end{array}

  1. Sector Alpha has two sharks and four tanks.

h1=2n1=4 \begin{array}{rcl} h_1 & = & 2\\ n_1 & = & 4 \end{array}

  1. Sector Beta has four sharks and two tanks.

h2=4n2=2 \begin{array}{rcl} h_2 & = & 4\\ n_2 & = & 2 \end{array}

3 Solution

The objective for us is to find both the values of tt, h3h_3 and n3n_3. To do this, I started out by using the given constraints to find the number of possible values for each of them.

Applying the given constraint #2, we can limit the search space for h3h_3 easily.

h3∈{xβˆˆβ„•|1≀x≀7,βˆ€i∈{1,2}:xβ‰ hi}h3∈{1,3,5,6,7} \begin{array}{rcl} h_3 & \in & \{ x \in \mathbb{N} | 1 \leq x \leq 7, \forall i \in \{1, 2\}: x \neq h_i\}\\ h_3 & \in & \{1, 3, 5, 6, 7\} \end{array}

Similarly, using the given constraint #3, we can limit the search space for n3n_3 easily.

n3∈{xβˆˆβ„•|0≀xβ‰€βˆ‘i=12ni}n3∈{0,1,2,3,4,5,6,7} \begin{array}{rcl} n_3 & \in & \{ x \in \mathbb{N} | 0 \leq x \leq \sum_{i=1}^{2} n_i\}\\ n_3 & \in & \{0, 1, 2, 3, 4, 5, 6, 7\} \end{array}

Finding out the search space for tt is unfortunately not that simple. First, we need to know how many creatures are currently accounted for.

βˆ‘i=12si=6+6t \begin{array}{rcl} \sum_{i=1}^{2} s_i & = & 6 + 6t\\ \end{array}

From constraint 1, we know that there are 50 creatures. Thus, from the amount of creatures we have right now and from that, we can calculate how many are not accounted for yet, rr (for rest). We also know that the missing creatures must be in our sector (sector Gamma), so we have ourselves a nice simple equation.

r=50βˆ’6+6tr=h3+n3t44βˆ’6t=h3+n3t44=h3+(6+n3)t \begin{array}{rcl} r & = & 50 - 6 + 6t\\ r & = & h_3 + n_3 t\\ 44 - 6t & = & h_3 + n_3 t\\ 44 & = & h_3 + (6 + n_3) t \end{array}

Now, given this equation and knowing the search space for both h3h_3 and n3n_3, we can easily restrict the search space for tt. If we pop in the maximum values for h3h_3 and n3n_3 and solve it, we can find the minimum value for tt, and vice versa for the maximum value.

44=7+(6+7)tmintminβ‰ˆ344=1+(6+0)tmaxtmaxβ‰ˆ7 \begin{array}{rcl} 44 & = & 7 + (6 + 7) t_{min}\\ t_{min} & \approx & 3\\ 44 & = & 1 + (6 + 0) t_{max}\\ t_{max} & \approx & 7 \end{array}

With this information, we can limit the search space for tt, because we know that it must be within the bounds of tmint_{min} and tmaxt_{max}.

t∈{xβˆˆβ„•|tmin≀x≀tmax}t∈{3,4,5,6,7} \begin{array}{rcl} t & \in & \{ x \in \mathbb{N} | t_{min} \leq x \leq t_{max}\}\\ t & \in & \{3, 4, 5, 6, 7\} \end{array}

Now, to actually solve this whole mess, we need to rearrange our equation a little bit.

44=h3+(6+n3)t44βˆ’h3=(6+n3)t \begin{array}{rcl} 44 & = & h_3 + (6 + n_3) t\\ 44 - h_3 & = & (6 + n_3) t \end{array}

With this equation, we can see that 44βˆ’h344 - h_3 must be divisible by both (6+n3)(6 + n_3) and tt. So, given that we have a list of candidates for h3h_3, we can simply check their divisors and see if any of them are candidates for tt.

| $$h_3$$ | equation | $$\{x \in \mathbb{N} \vert x \mid (44 - h_3), t_{min} \leq x \leq t_{max}\}$$ |
|---------|----------|---------------------------------------------------------------------------|
| $$ 1$$  | $$ 43 = (6 + n_3) t$$ | $$ \{\}$$ |
| $$ 3$$  | $$ 41 = (6 + n_3) t$$ | $$ \{\}$$ |
| $$ 5$$  | $$ 39 = (6 + n_3) t$$ | $$ \{3\}$$ |
| $$ 6$$  | $$ 38 = (6 + n_3) t$$ | $$ \{\}$$ |
| $$ 7$$  | $$ 37 = (6 + n_3) t$$ | $$ \{\}$$ |

Seeing that only h3=5h_3 = 5 produced a valid t=3t = 3, these must be our values. Now, all that is left to do is pop them right back into the equation to find n3n_3.

39=(6+n3)321=3n37=n3 \begin{array}{rcl} 39 & = & (6 + n_3) 3\\ 21 & = & 3n_3\\ 7 & = & n_3 \end{array}

There we go, n3=7n_3 = 7. This means that in sector Gamma, there are five sharks and seven fish tanks. Every fish tank contains three fish.

Too bad that this could be solved on paper, I’m hoping that next time I can finally get an excuse to play around with a fancy constraint solver or implement something. But in the meantime, it was fun to do and I hope I didn’t get anything wrong.


  1. The video is available at https://youtu.be/lLOALyWls2k.β†©οΈŽ