Coffee Time Challenges

As many of you know, I proudly work at facebook.

Every now and then, I post little puzzles on my feed for my friends and colleagues. I call these coffee time challenges . They are designed as small, bite-sized, problems to be mulled over whilst taking a short coffee break. These are, typically, not hard puzzles, and usually there are multiple ways of solving. Sometimes people solve them using pencil, paper and first principle math. Other times people will write regular expressions, LINQ, Perl or Python scripts*. Sometimes brute force is used, sometimes elegance; there is no right or wrong way to solve, just a correct answer. I try to select puzzles that do not involve clever ‘gotchas’, or ‘tricks’. Those kinds of problems are trivial to those that are aware of the secret, and leave a sense of disappointment to others when then learn the cheat. The puzzles are all self-descriptive and no external knowledge is needed to complete them. A good coffee time challenge is one where what you need to find is instantly understandable, and the challenge is how to find that answer. *I like to use VB6, just because I can!

Many of these puzzles are not my own invention, some are, but most are inspired from, or copied from, other ideas I’ve seen. They have become quite popular with my friends and colleagues, so I thought I would share some here on my blog. Below are a selection of my more recent coffee time challenges. For some of the problems I’ve provided a hint link, and for all the questions I have given the solution. I’ve provided the solutions so you can confirm the answer if you attempt to recreate, but I’ve not provided any code. The fun in solving these puzzles lies in writing the code, not the answer. The enjoyment comes, not from getting the correct answer, but from being able to write code/script to get the correct answer. I'm not saying these are good coding interview questions, but I will say that if you can't write code that solves puzzles like the ones below that you should strongly consider a career change :) Incidentally, do you know how much you spend in your lifetime on coffee?

1) Two Bases

Challenge : Find three digits X , Y and Z such that XYZ in base 10 (ten) is equal to ZYX in base 9 (nine)?

Click for hint

There are more elegant ways to solve it, but the solution set is so small, you might as well just brute force it.

Click for solution

445 10 = 544 9 X=4 Y=4 Z=5

2) One Million

Challenge : Write 1,000,000 as the product of two numbers; neither of which contains any zeroes.

Click for hint

What are the prime factors? Make sure factors of two and five are not on opposite sides

Click for solution

15625, 64

3) High Product

Challenge : Use the digits 0-9 to create two numbers. What is the highest product you can achieve when these two numbers are multiplied together?

Click for hint

Bigger numbers go at the front.

Click for solution

875310 × 9642 = 8,439,739,020 or 87531 × 96420 = 8,439,739,020

4) Exactly a third

Challenge : Arrange the numerals 1-9 into a single fraction that equals exactly 1/3 (one third). No other math symbols wanted; just concatenation some digits for the numerator, and some to make a denominator.

Click for solution

5823 / 17469 or 5832 / 17496

5) Three dice

Challenge : I roll three dice, and multiply the three numbers together. What is the probability the total will be odd?

Click for hint

You should be able to do this without a computer! To get an odd product, all three dice have to roll odd.

Click for solution

1/8

6) Word Doc

Challenge : I open up a Word document and type all the numbers 1-10000 , separated by spaces, (I did not use any 'thousands' punctuation; just raw numbers). Then, my daughter came along and used search and replace, and changed all the digits '0' into spaces. If I now sum up all the numbers in the document what is the total? (Any number delineated by one or more spaces is a distinct number).

Click for solution

37,359,001

7) Legs

Challenge : In a room there are a mixture of people and dogs. There are 72 heads, and 200 legs. How many dogs are in the room? (No tricks, no chromosomal abnormalities, no disabilities …)

Click for hint

This is simple algebra. If you need to write code to solve this, please stop reading.

Click for solution

28 dogs

8) One, Two, Three

Challenge : Using just one 1 , one 2 , and one 3 (no concatenation of digits) and any combination mathematical symbols you wish (addition, subtraction, multiplication, division, parenthesis, exponents, factorial, square root …). Write an equation to gives the total 19 .

Click for hint

You will either get this, or you will not. The answer requires the use of two factorials, a square root, a division, and an addition.

Click for solution

9) One, Seven

Challenge : As above, how about making a total of 71 using just one 1 and one 7 (again, no concatenation of digits, or this would be trivial!)

Click for hint

You will either get this, or you will not. The answer requires the use of one factorial, a square root, and an addition.

Click for solution

10) Buckets

Challenge : Put the numbers 1-13 into three buckets with the constraint that the difference between any two pairs of numbers in any bucket is not a number also in that bucket. (e.g. If you place 5,7 in a bucket, then you cannot place 2 in that same bucket).

Click for solution

[[2, 3, 7, 11, 12], [5, 6, 8, 9], [1, 4, 10, 13]] or [[2, 3, 11, 12], [5, 6, 7, 8, 9], [1, 4, 10, 13]]

11) Product and Sum

Challenge : I’ve written down all the integers from 1 to 65,502 inclusive. I select two of them, cross them out, and multiply them together to get a product. When I sum up the remaining 65,500 numbers, I get the same result. What two numbers did I pick?

Click for hint

What is the formula for triangular numbers?

Click for solution

46,465 and 46,168

12) Adjacent Squares

Challenge : Arrange the integers 1-17 (inclusive) so that each adjacent pair of numbers is a perfect square. e.g. 14, 2, 7 … (The first and last do not have to wrap around)

Click for hint

You can use a square more than once, and there are not many to chose from. There is a very limited number of possible numbers that follow any other number.

Click for solution

16 9 7 2 14 11 5 4 12 13 3 6 10 15 1 8 17

13) How many

Challenge : ABCDEFGHIJ is a ten-digit-number. All of the digits are distinct. If 11111 divides it evenly, how many possibilities are there for ABCDEFGHIJ ?

Click for hint

Prime factors, or brute force? If you go brute force, how can you reduce the numbers you need to check?

Click for solution

3456

14) Reciprocals

Challenge : Find six distinct integers: A, B, C, D, E, F the reciprocals of which add up to exactly one. e.g. 1/A + 1/B + … 1/F = 1

Click for hint

Lots of possible answers, all you need is one.

Click for solution

1/2 + 1/4 + 1/6 + 1/18 + 1/60 + 1/90 = 1 1/2 + 1/4 + 1/6 + 1/18 + 1/63 + 1/84 = 1 1/2 + 1/4 + 1/6 + 1/19 + 1/57 + 1/76 = 1 1/2 + 1/4 + 1/6 + 1/20 + 1/45 + 1/90 = 1 1/2 + 1/4 + 1/6 + 1/20 + 1/48 + 1/80 = 1 1/2 + 1/4 + 1/6 + 1/20 + 1/50 + 1/75 = 1 1/2 + 1/4 + 1/6 + 1/20 + 1/55 + 1/66 = 1 1/2 + 1/4 + 1/6 + 1/21 + 1/42 + 1/84 = 1 1/2 + 1/4 + 1/6 + 1/21 + 1/44 + 1/77 = 1 1/2 + 1/4 + 1/6 + 1/22 + 1/36 + 1/99 = 1 1/2 + 1/4 + 1/6 + 1/22 + 1/44 + 1/66 = 1 1/2 + 1/4 + 1/6 + 1/24 + 1/32 + 1/96 = 1 1/2 + 1/4 + 1/6 + 1/24 + 1/33 + 1/88 = 1 1/2 + 1/4 + 1/6 + 1/24 + 1/36 + 1/72 = 1 1/2 + 1/4 + 1/6 + 1/24 + 1/40 + 1/60 = 1 1/2 + 1/4 + 1/6 + 1/24 + 1/42 + 1/56 = 1 1/2 + 1/4 + 1/6 + 1/25 + 1/30 + 1/100 = 1 … …

15) Fan Fun

Challenge : You’re taking care of a friend’s house whilst he’s on vacation. In one room you pull the chain on a ceiling fan, and when it doesn’t respond you realize the house has temporarily lost power. Doh! Unfortunately, you have to leave now, and you’ll be away for several days.

You know that the fan was in the “off” position before you pulled the chain, and that pulling the chain successively will cycle it through its remaining settings (“off,” “high”, “medium”. etc.). You don’t know how many settings there are, but you are sure there aren’t more than four.

How can you ensure the fan will be in the “off” positions when power is restored?

Click for hint

Do the words Lowest Common Multiple mean anything to you?

Click for solution

If you pull the chain a total of 12 times, it will return to the “off” position irrespective if there are two, three or four speed settings. Therefore, pull it eleven more times.

16) LED Clock

Challenge : You are in a totally dark room. The only light in the room comes from an old LED digital alarm clock (with four seven segment displays). The clock display is HH:MM (no seconds). The clock is configured to display time in 24 hour format and the leading digit is blank if not used. What is the period of time between when the room is at its darkest, to when it is at its lightest?

Click for hint

What time has the most number of display segments lit? What the least?

Click for solution

18 hours and 57 minutes. ( 1:11 to 20:08 )

17) Use all the digits

Challenge : Find a five-digit number, all digits distinct and non-zero, such that that number is equal to the sum of all three-digit numbers can be made with the digits of that number.

i.e. A number ABCDE that is equal to ABC + ABD + ABE + BCA + CBA + BDA + DBA + … etc.

Click for hint

How often does each digit appear in each position?

Click for solution

35964

18) Sticky Calculator Buttons

Challenge : My daughter just spilled orange juice over my scientific calculator. The number buttons 0-9 are all stuck (not working), as are the basic arithmetic functions + - * /

Thankfully, all the scientific buttons work (trig, powers, inverse, exponential, log, root, factorial …)

The display currently reads “0”.

How can I use the buttons that work to make the display show “1”, then press buttons to convert this to a “2”, and finally “3”?

Click for hint

You might find this easier by simply trying it out. There are multiple solutions. Do you remember your cardinal trig points?

Click for solution

To get "1", simply press Cos To get "2", press Tan-1 then Sin then 1/ X followed by X2 To get "3", press 1/ X then Sin-1 then Tan then 1/ X followed by X2

19) Using twos

Challenge : Multiple parts, some easy, some hard. Add mathematical symbols (factorial, +, -, / , *, sqr , trig functions, log, decimal points, exponents …) to make the desired sums. Concatenation is allowed.

1] Make 11 using three 2s 2] Make 1 using three 2s 3] Make 10 using two 2s 4] Make 5 using two 2s

Click for hint

You either get these, or you do not.

Click for solution

20) Filling my pool

Challenge : If I fill up my pool using my red hose pipe, it takes me eight and a half hours. If I fill it up using both my red hose pipe and my blue hose pipe, it takes just five and a quarter hours. How long will it take me to fill my pool if I used just the blue hose pipe?

(All the common sense simplifications apply: constant flow rates, don't try to complicate things with physics!)

Click for solution

357/26 hours (approx. 13 hours 44 mins)

21) Start and end

Challenge : Find the smallest possible natural number that ends in 6 such that if the 6 is erased and placed in front of the remaining digits, the resulting number is 4 times as large as the original number.

Click for solution

153846

You can find a complete list of all the articles here. Click here to receive email alerts on new articles.