The confounding digital clock puzzle
Recently, I played Professor Layton and the Curious Village on the Nintendo DS. It’s basically a game filled with puzzle after puzzle for the player to solve.
There are 3D questions testing your visualisation skills (the IQ question on the painted cube for my job interview also came up). There are the logic questions such as “Only 1 of the 4 kids is telling the truth”, and you have to figure out the answer from their statements.
I can solve most of the puzzles in my head. The only time when I needed to write something down was where the puzzle can be distilled into a pair of simultaneous equations. You know the kind, the father is x times as old as the son, and after y number of years, he’d be z times as old as the son, and how old are both of them currently. Or some kind of puzzle with some math variables I need to keep track, but don’t want to do that mentally.

[image by claylib]
Then comes this one puzzle. I was stuck on it for over an hour. I thought, I categorised, I simplified. It’s too mentally taxing to hold all the pieces mentally, and I’m too lazy to write everything out on paper. Here’s the puzzle, paraphrased:
You have a digital clock, displaying the hour and the minute only, with hours in the 12-hour format. How many times during an entire day will 3 or more identical digits appear consecutively in a row? For example, 03:33 is counted as once.
My brother solved it by using Excel to generate all the combinations, and eliminating each combination by inspection. I didn’t want to do that. After some time, I did the only sensible thing. I wrote a program to solve it. Muahahahaha…
// any date will do, as long as the time is set
// to zero for the hour and minute (and second?)
DateTime dt = new DateTime(2008, 10, 1, 0, 0, 0);
string s = dt.ToString("yyyyMMdd");
string sTime;
char[] ca;
int iCount = 0;
// while still the same day
while (s.Equals("20081001"))
{
// small hh for 12-hour format
sTime = dt.ToString("hhmm");
ca = sTime.ToCharArray();
// check if first three digits are identical
// or if the last three digits are identical
if ((ca[0] == ca[1] && ca[1] == ca[2]) || (ca[1] == ca[2] && ca[2] == ca[3]))
++iCount;
dt = dt.AddMinutes(1);
s = dt.ToString("yyyyMMdd");
}
Console.WriteLine(iCount);
That took me a couple of minutes to whip up. I added the comments so you can follow the thought process easily. Note the “hhmm” format for 12-hour versus “HHmm” for 24-hour format. 2 seconds to compile and run, and BAM! I got the answer. No, I’m not telling you. Go figure it out yourself.
So I solved the digital clock puzzle with programming. Somehow, it felt like cheating. Anyway, my challenge to you is, can you solve it in a non-programmatic, non-exhaustive-list-writing way?
Comments
5 Responses to “The confounding digital clock puzzle”
Leave a Reply







I solved this problem in my head as follows:
Hours 6:00 through 9:00 cannot generate a string of three identical digits because minutes can only range between 00 and 59.
Hours 1:00 through 5:00 can only generate one case of three identical digits each using the last three positions - the zero in the first position of the hour prevents the first three positions from being used and the second position in the hour determines what the last two must be.
Five cases so far.
Hours 10:00 and 12:00 can only generate one case each - the second position determines what the last two must be and it doesn’t match the first position, so the first three can’t be used.
Seven cases so far.
Which leaves hour 11 as a special case - 11:10 through 11:19 generate 10 cases. 11:11 is interesting because this is the only time that the first and last three positions are the same. However, the rules state “three or more identical digits”, so 11:11 should only be counted once.
Which means the number of results is 17.
I think this solution is more of a pattern based approach rather than an exhaustive list and it’s definitely not a program.
So, do I win a no-prize?
Steven
Hey Steven, you’re almost right! There’s another piece of information in the question. The phrase “during an entire day” is important too. So, uh, no no-prize? *smile*
You know, your method of inspecting each hour to find out how many combinations fit is really good. Your explanation is very clear too. I wish I thought of that when I was struggling… Thanks!
I interpreted this phrase -
“For example, 03:33 is counted as once.” - to mean that 03:33 AM and 03:33 PM only counted as one occurrence.
Bad assumption - I should have hedged my bet.
Bonus question: What if the clock is in 24 hour format?
Steven
Oh yeah, that phrase _is_ ambiguous. I need to phrase questions better… The way it was phrased in the game was quite clear. I didn’t want to plagiarise though…
The main difference in counting with 24 hour format would be … we have to count _more_ combinations starting with 0 and 2!
I cheated… I modified my program a little. The final count isn’t a lot more than the 12 hour version. Some of the 12-hour combinations simply became a 24-hour version, so the final count isn’t as high.
Basically, we still follow your method and check how many combinations for each hour. There’s just double the number of hours to check.
[...] might explain my fascination with puzzles recently, such as the one on digital clocks and the math puzzle in a [...]