﻿ Coffee Time Challenges

# 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 base10 (ten) is equal to ZYX in base9 (nine)?

Click for hint

Click for solution

## 2) One Million

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

Click for hint

Click for solution

## 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

Click for solution

## 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

## 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

Click for solution

## 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

## 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

Click for solution

## 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

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

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

## 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

Click for solution

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

Click for solution

## 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

Click for solution

## 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

Click for solution

## 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

Click for solution

## 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

Click for solution

## 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

Click for solution

## 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 …)

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

Click for solution

## 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

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

## 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