Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How many unit hexagonal tiles can be placed inside a larger hexagon of sides $a,b,c,a,b,c$? I originally came across this puzzle on the codeforces website.

My first question: what is the mathematics behind solving these kind of puzzles? Just plain algebra?

My second question, more philosophical: how many of you solved this instantly? I could not solve it even after a bit of googling. I am interested in developing my intuition or mathematical aptitude for solving these kind if problems. Any advice? Its been many years since I am out of college.

Some test cases for you to check your answers before you post them. Input 2 3 4 Answer 18

Input 2 2 2 Answer 7

Input 7 8 13 Answer 224

Input 985 2 2 Answer 2956

share|cite|improve this question
Look at the picture at the codeforces site with $a=1$. This is basically a rectangle, so counting the tiles is straightforward. Now draw a picture for various $a$'s to see how many tiles $a>1$ removes. Guess and verify. – copper.hat Aug 18 '12 at 19:05
@copper.hat: I dont get it. How does a>1 remove tiles? – hAcKnRoCk Aug 19 '12 at 7:51
It should read 'see how many tiles are removed when $a$ is greater than one'. The answer is that $a (a-1)$ tiles are removed. So the formula should be $(b+1)(c+1)-a(a-1)$. Sometimes succinctness obfuscates. – copper.hat Aug 19 '12 at 8:03
hmm.thanks for your quick response. But Sorry the answer is wrong. For a=7,b=8,c=13, the correct answer is 224. Your expression gives 84. – hAcKnRoCk Aug 19 '12 at 8:53
Sorry, I meant $(b+a-1)(c+a-1)-a(a-1)$. – copper.hat Aug 19 '12 at 10:03
up vote 3 down vote accepted

View the border hexagon as a projection of box, so that the hexagonal tiles appear to represent somewhat-lumpy spheres stacked in layers.

Hex Box

How does the number of visible spheres (that is, the number of tiles) compare to the area of the three visible faces of the box?

(Image adapted from the figure given on the Codeforces web site.)

To answer your personal questions: I solved this instantly, once I adopted the proper (ahem) perspective; at that point, "the mathematics behind solving" this particular problem became almost-trivial. My advice about such problems in general is to seek out similar insights; reading contest books ---and anything by Martin Gardner--- can help in building your intuition.

By the way, I can't take too much credit for the box insight. Years ago, I came across a fairly classic puzzle about how many unit double-equilateral-triangle rhombi fit into one of these elongated hexagons; the answer becomes clear upon coloring the rhombi based upon which direction (out of three) the long diagonal points: the coloring immediately creates an illusion of stacked cubes, with each color corresponding to the direction in which each cube face ... um ... faces (up, forward, sideways). Ever since then, I've tended to see projected cubes whenever I look at hexagons ... which underscores my point that exposure to mathematical puzzles builds intuition.

share|cite|improve this answer
Brilliant illustration. I loved it. I get it now. The number of tiles on the visible faces is (ab+bc+ca). Then the number of tiles that have been counted multiple times in the previous product (a+b+c) + 1 (the tile at the intersection of the red, green and blue lines). Voilà. – hAcKnRoCk Aug 20 '12 at 21:14
And thanks a lot for answering the philosophical questions. To Read: Martin Gardner's math books is on my to do list :-) What an awesome community by the way! – hAcKnRoCk Aug 20 '12 at 21:24

Edit: My first answer (appended in brackets) is much too complicated. Here is the final version:

The given hexagonal array $H$ of beads can be viewed (in two ways) as the union of three parallelogram shaped arrays containing $ab$, $bc$, and $ca$ beads respectively, any two of them sharing an edge of length $a$, $b$, or $c$, and all three of them having one bead in the interior of $H$ in common. By the inclusion-exclusion principle the total number $N$ of beads is therefore given by $$N=(ab + bc + ca) -(a+b+c)+1\ .$$

[Assume $a\leq b\leq c$, where $a$ is the number of tiles on the vertical edge. Partition the figure by two auxiliary vertical lines into two trapezoidal parts and a central parallelogram shaped part. The $b$ vertical rows in the trapezoidal parts contain resp. $a$, $a+1$, $\ldots$, $a+b-1$ hexagons, and the $c-b-1$ "inner" vertical rows of the parallelogram shaped part contain $a+b-1$ hexagons each. (When $c=b$ then $c-b-1=-1$ which takes care of the fact that in this case the longest vertical column, of length $a+b-1$, has been counted twice so far.) Therefore the total number $N(a,b,c)$ of tiles is given by $$\eqalign{N(a,b,c)&=\bigl(a+(a+1)+\ldots+(a+b-1)\bigr)+(c-b-1)(a+b-1)\cr &= b\bigl(a+(a+b-1)\bigr)+(c-b-1)(a+b-1)\cr &=(ab+bc+ca)-(a+b+c)+1\ .\cr}$$ Since the resulting total is a symmetric function of $a$, $b$, $c$ the assumption $a\leq b\leq c$ used in the proof turns out to be unnecessary.]

share|cite|improve this answer
oops. Sorry Sir.My fault.I have removed that comment saying your answer is wrong. Now, I have upvoted your answer. Although before accepting your answer, i would like to clarify the logic behind. So, $a+(a+1)+...$ is the number of unit hexagons in 1 trapezoid. right? This is an arithmetic progression. How did you find out the last term (a+b-1)? Second, I dont understand how you arrived at $(c−b−1)(a+b−1)$? One more thing is about your assumption. The formula works even when your assumption is violated. a = 985;b=2;c=2 – hAcKnRoCk Aug 19 '12 at 9:10

Hint: if we let $a$ be the minimum dimension, think of filling out the corners where $a$ is to make a parallelogram. How many hexagons do you need to use to fill the two corners? What are the resulting dimensions of the parallelogram?

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.