Classic interview challenge, in C#