Trying To Fly

This was a demo I wrote way back in 2004. It runs against the .NET Framework (version 1.1 back then). Wow, it’s been a while…

In the demo, I tell a story of a wooden cuckoo bird trying to fly. All the shapes were rendered using primitives such as spheres, cuboids and 2D planes. Textures were generated using a 3D renderer (Bryce 4). The sounds were downloaded from 3D Cafe, and were listed on the “free” page. While I can’t remember the exact licensing (which wasn’t a big deal back in 2004), I went to the Wayback Machine and checked. There were no licensing terms, either to credit the individual or 3D Cafe.

You can download the demo here.

I wrote a 3D engine called Visionary for my own purposes, which was used to render the demo. It generates 3D primitives (spheres, planes, cuboids) with or without texture mapping. The engine also had support to play sound and music. And I lost the source code to it. The DLL is Visionary.dll, so if you have a good .NET decompiler, I give you permission to use it. I’d appreciate it if you could also send me a copy.

Note that some of the sounds will be loud. Take care of your ears. I tried to edit the sound files, but apparently they were so old that I can’t edit them with Audacity. I can only play them. Maybe I missed something…

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?