OdeToCode IC Logo

A Message For You

Wednesday, January 3, 2007

Some might say it's a day late, but nevertheless, it is a message. And it's for you.

Of course, you'll have to figure out what the message is by reading the source code. This year's code isn't quite as ugly as last year's code, but if you can figure this one out without a compiler - three cheers! If you do figure it out, you might still want to run the code as a console application to see the full effect...

using System;
using System.Collections;

class _2007_
{
    
static void Main()
    {
        
int x, y; x = y = 0;
        
Console.SetWindowSize(84, 7);
        
do
        {
            
foreach (string i in Order)
            {
                
foreach (int n in numbers[Int32.Parse(i)])
                {
                    
Console.SetCursorPosition(x + n % 5,
                                              y + n / 5);
                    
Console.ForegroundColor = SomeColor;
                    
Console.Write("@");
                }
                x += 6;
            }
        }
while (!Console.KeyAvailable && (x = y = 0) < 1);
    }

    
static IEnumerable Order
    {
        
get
        {
            
yield return 4.ToString(); yield return 6.ToString();
            
yield return 2.ToString(); yield return 2.ToString();
            
yield return 1.ToString(); yield return 0.ToString();
            
yield return 3.ToString(); yield return 8.ToString();
            
yield return 5.ToString(); yield return 0.ToString();
            
yield return 1.ToString(); yield return 8.ToString();
            
yield return 6.ToString(); yield return 7.ToString();
        }
    }

    
static int[][] numbers =
    {            
        
new int[] { },
        
new int[] {0,4,5,9,11,12,13,17,22},
        
new int[] {0,1,2,3,5,9,10,11,12,13,15,20},
        
new int[] {0,4,5,6,9,10,12,14,15,18,19,20,24},
        
new int[] {0,4,5,9,10,11,12,13,14,15,19,20,24},
        
new int[] {0,4,5,9,10,14,15,17,19,20,21,23,24},
        
new int[] {1,2,3,5,9,10,11,12,13,14,15,19,20,24},
        
new int[] {0,1,2,3,4,5,9,10,11,12,13,15,18,20,24},
        
new int[] {0,1,2,3,4,5,10,11,12,13,14,15,20,21,22,23,24}
    };

    
static ConsoleColor SomeColor
    {
        
get
        {
            
return (ConsoleColor)colors.GetValue(
                    rand.Next(colors.Length)
                );
        }
    }

    
static Array colors = Enum.GetValues(typeof(ConsoleColor));
    
static Random rand = new Random();
}