Some algorithms in code (C#)