this is the thinking about algorithms thing but in c sharp and in half the lines of code