Fish Riddle

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 skills.

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.

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:

The constraints

There are six comstraints given in the puzzle.

  1. There are 50 creatures in total, including sharks and fish.
  1. Each sector has anywhere from one to seven sharks, with no two sectors having the same nmber of sharks.
  1. Each tank has an equal number of fish. Since this is true, we will just use to refer to any of , simce they are all the same.
  1. In total, there are 13 or fewer fish tanks.
  1. Sector Alpha has two sharks and four tanks.
  1. Sector Beta has four sharks and two tanks.


The objective for us is to find both the values of , and . 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 easily.

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

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

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, (for rest). We also know that the missing creatures must be in our sector (sector Gamma), so we have ourselves a nice simple equation.

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

With this information, we can limit the search space for , because we know that it must be within the bounds of and .

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

With this equation, we can see that must be divisible by both and . So, given that we have a list of candidates for , we can simply check their divisors and see if any of them are candidates for .


Seeing that only produced a valid , these must be our values. Now, all that is left to do is pop them right back into the equation to find .

There we go, . 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.