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
- Anonymous
February 07, 2005
I took a shot at solving it (spoiler):
http://inesontech.blogspot.com/2005/02/nice-c-puzzle.html - Anonymous
February 08, 2005
I haven't tried running it, but wouldn't it be better if the Console.WriteLine call looked like:
Console.WriteLine(args[0].Replace('.', ' ') + "!"); - Anonymous
February 08, 2005
By the way, that ConvertAll function is cool. And this little quiz is a neat way of showing it off :) - Anonymous
February 08, 2005
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 - Anonymous
February 08, 2005
>> 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