simple algorithm question - C#