Thursday, December 4, 2014

SPOJ 302. Count on Cantor (CANTON)

 First we need to figure out the pattern by which the numbers are numerated. This is the pattern but it is kind of reversed, have a look.
http://en.wikipedia.org/wiki/File:Diagonal_argument.svg

The first turn is right then diagonally down, and then when reached the edge it goes down by one and then diagonally up, and the same thing again. Now we need to correctly implement it, you can just make a function which goes from one number to another by a specified direction and changes it whenever necessary, check the source code for a good understanding.


       FULL SOURCE CODE

No comments:

Post a Comment