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.

Digital clock by claylib
[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?

Solving the Resident Evil Zero game math puzzle

Previously,

On the screen is shown a “00/81″. A number pad with number keys 1 to 9 is on the right. When a number key is entered, a knob is lit in red and the value of the number is added to the numerator of the displayed ratio. There are 10 unlit knobs.

The puzzle should be obvious. Match the numerator and the denominator with 10 entries.

So how would I solve it? My hint as stated, was:

the last entry is the most important

The first 9 entries are to get you as close to the required number as possible. This is actually similar to blackjack, a card game where you try to get as close to 21 points as possible without going over. The difference is that you don’t get to choose your next number (or card value) in blackjack. You do here.

Blackjack
[image by pavlen]

So my first instinctual thought was to finish up the first 9 entries to get to the last entry. My second instinctual thought was to make these 9 entries all the same number value. It’s a timed effort. I don’t have time to go figure out different combinations of sums.

Based on those thoughts, my next (instinctual) step was to divide the required number by 9, rounding down to nearest integer. Don’t ask me why at this point, because I’ll know the reason only after thinking it through, and I’m not thinking it through at this point.

So we have 81 divide by 9, and rounded down, we get 9. We have a problem. It’s not just 9. It’s exactly 9. There’s no number value 0 for the final entry. So we use 8 (1 less than 9).

Then we multiply 8 by 9 (entries) to get 72. And then 81 (required number) – 72 is 9, the final entry. So the answer is 8,8,8,8,8,8,8,8,8,9.

This method gives the simplest of combinations (only 2 distinct numbers used) and is the fastest to get you to the end point, the final entry. It’s the final entry that “corrects” the sum to the required number.

I have to say, the changing of 9 to 8 is (I’m starting to use the word generously) instinctive. I don’t know how changing 9 to 8 would solve the problem. I just know.

Let’s use this method on the second part of the puzzle: 67.

67 divide by 9 rounded down gives 7. 7 multiplied by 9 is 63. 67 – 63 is 4. So the answer is 7,7,7,7,7,7,7,7,7,4.

There you have it, the algorithm to solving the math puzzle. The second puzzle uses the “normal” mode of the algorithm. The first puzzle tested the edge case of the algorithm.

Hmm… can we write a function that spits out the combination using the above algorithm? Can we write a function that spits out all possible combinations?

Can you solve this game math puzzle in seconds?

The game in question is Resident Evil Zero. Didn’t think there’d be a math puzzle in a survival horror game? Neither did I.

The game video footage (video link) is over 10 minutes long, so I’ll highlight the relevant parts. Warning: the player is uh, slightly liberal in his use of words. This video’s considered ok, comparing with his other videos. His commentary is colourful and funny, which is why I watch his videos. He makes surviving in a horror story, fun. *smile*

The player mentions a difficult math puzzle at about 1 minute 44 seconds (henceforth noted 1:44) into the video. That got my attention. A math puzzle in a game?

He even tagged it as such:

Stupid math puzzle

I watched the video till about 7:44, where the math puzzle finally made its entrance.

Resident Evil Zero math puzzle part 1

On the screen is shown a “00/81″. A number pad with number keys 1 to 9 is on the right. When a number key is entered, a knob is lit in red and the value of the number is added to the numerator of the displayed ratio. There are 10 unlit knobs.

The puzzle should be obvious. Match the numerator and the denominator with 10 entries.

This is the math puzzle?! Still, in an action game, any kind of math puzzle is probably fatal. I can fumble on simple additions too. Guess I need to practise more.

Anyway, his answer was 9,9,9,9,9,9,9,8,7,3 for a total of 81. Puzzle solved. Wait, there’s more.

Resident Evil Zero math puzzle part 2

In the second part of the puzzle (at about 8:13), the numerator was obscured. The denominator was 67. This time, the player had to really know what he should enter before entering anything. He fumbled for the right combination for about 2 minutes. And he hadn’t saved the game since the beginning of the game…

With about 20 seconds left on the clock, he finally solved it. His answer was 5,5,5,5,9,9,9,9,3,8 for a total of 67.

So my challenge to you is, can you quickly come up with a solution in a timed situation? How would you solve the problem? What goes through your mind while you’re coming up with an algorithm for it?

I’d love to hear your thoughts and comments. I’ll publish what my thoughts are too (some days later). Hint: the last entry is the most important.

You’re most welcome to submit well thought solutions in pseudocode too, eliminating the limited time factor.

Puzzle of 7 points and 6 straight lines – 2nd solution

This is the second solution to this puzzle: Construct a geometric shape with 7 points such that there are 6 straight lines, and each line must pass through 3 points. The first solution was already discussed last week.

And here’s the construction:

2nd solution to 7 point and 6 line puzzle

The 7 points are labelled A to G. The 6 lines are ADB, AFC, AGE, DGF, DEC and FEB. No, I didn’t label the points so I’ll have AGE and the short forms of the months December and February. It just happened that way…

The construction starts with point A, and you draw two lines down to get points B and C. The lines AB and AC must be of the same length. Then from point B, draw a perpendicular line to meet line AC. That meeting point is F.

From this construction, angles AFB, AFE, CFB and CFE are right angles (90 degrees).

Do the same thing from point C and draw a perpendicular line to meet line AB, and you’ll get point D. Similarly, angles ADC, ADE, BDC and BDE are right angles.

The point E is formed from the cross point of lines DC and FB that was just formed.

Draw a line joining D and F. Draw another line joining A and E. The cross point of lines DF and AE is point G.

The first solution focused on getting the points right, and then forming lines to fit them. This solution focused on constructing the lines, and the required points magically appear.

On hindsight, we didn’t need the right angles to be there. As long as D and F meet the lines AB and AC respectively in the same ratio, the solution is still valid. There are 2 criteria to meet:

  • Lines AB and AC must be of the same length. This allows symmetry.
  • The length ratios AD:AB and AF:AC must be equal. This is dependent on the previous criteria.

[Update] Yes, that is one heck of a correction. 3 criteria:

  • Points B, A, and C don’t form a straight line (they’re not collinear)
  • D is somewhere on the line AB (and D not equal to A nor B)
  • F is somewhere on the line AC (and F not equal to A nor C)

Then follow similar construction steps for points E and G and as Eric puts it, the rest just happens. Thank you Eric for pointing this out.

Ok, 2 solutions were presented. I hope you had fun reading and thinking about the puzzle.

Puzzle of 7 points and 6 straight lines

My friend presented me with a puzzle: Construct a geometric shape with 7 points such that there are 6 straight lines, and each line must pass through 3 points.

My friend came up with a solution, but he wasn’t sure, so he consulted me. Actually there was a “model” answer, but he wanted to find another solution. So we had 2 solutions. I’ll present that model answer here so you can understand the puzzle better.

Equilateral triangle solution

Points A, B and C form an equilateral triangle. Points D, E and F are the midpoints of lines AB, AC and BC respectively. Point G is the centre of the triangle.

Note: 3 points are collinear if they lie on a straight line.

The 7 points are A to G. The 6 lines are formed by ADB, AEC, BFC, AGF, BGE and CGD.

[I'm not going to go too much into math theories and proofs. Besides, I'm not even sure if I can recall them after losing track for so long...]

The first three lines should be easy to understand. D is the midpoint of AB, so ADB is a straight line. So it is for AEC and BFC.

E is the midpoint of AC, and BE is the perpendicular bisector (remember ABC is an equilateral triangle). And G lies on the line BE, since G is the centre of the triangle. So BGE is a straight line.

Using this reasoning, AGF and CGD are also straight lines.

I know, the explanation I gave isn’t quite backed up with math proofs, more with intuitive reasoning. But I’m sure they are (I just don’t know exactly which theorems to cite…).

So I have 2 favours:

  • Send me a more proper explanation of the solution given above
  • Or send me another solution (remember I have another one?)

I know there are at least 2 solutions. Just wondering if there are more. I will post my other solution, together with any submissions from you next Monday. Or earlier, depending on the number of submissions. You’re welcome to do both. *smile*

Since this is a geometric construction, a picture together with some explanations is appreciated. You can host the image on a site like Flickr, then add a comment to this post with a link to that image and a brief explanation.

Or you can send me your solution via email to vincent at polymathprogrammer dot com. Let me know if you want to remain anonymous (why?), and I’ll just post your solution only.

Your construction doesn’t have to be exact in proportions. Meaning if there’s a right angle, it doesn’t have to be 90 degrees exactly, so long as it looks like it’s 90 degrees. Just add some explanation to supplement the drawing. Try Paint.NET if you don’t have any image editing software.

Have fun!