Quick Puzzle: what does this program print?


You have 30 seconds left… just kidding :-)

 

using System;

using System.Collections;

using System.Reflection;

 

class Hello

{

    Type Unknown { get { return World.GetType(); } }

 

    object[] Knowledge() { return Unknown.GetProperties(); }

 

    string[] Library()

    {

        return Array.ConvertAll<object, string>(

            Knowledge(),

            delegate(object x) { return x.ToString(); });

    }

 

    public static Hello World { get { return new Hello(); } }

 

    static void Main(string[] args)

    {

        if (args.Length > 0)

            Console.WriteLine(args[0]);

        else

            Main(World.Library());

    }

}

 

[update. The code above compiles only with the C# 2.0 compiler. The simplest way to get started is to download Visual C# Express from here]

 

Comments (5)

  1. I haven’t tried running it, but wouldn’t it be better if the Console.WriteLine call looked like:

    Console.WriteLine(args[0].Replace(‘.’, ‘ ‘) + "!");

  2. By the way, that ConvertAll function is cool. And this little quiz is a neat way of showing it off :)

  3. Ovidiu says:

    Interesting, but I was able to figure it out :-/ Which means this is nothing compared to the International Obfuscated C Code Contest. There are plenty of snippets there that made me go "Huh?!" many times :) My all time favourite is http://www.ioccc.org/2000/primenum.c

  4. Adi Oltean says:

    >> Which means this is nothing compared to the International Obfuscated C Code Contest.

    I didn’t want to go there :-)

    BTW, my favorite is: http://www.ioccc.org/1984/anonymous.c