+ 1
Use modulo to split the number into pieces :
131%10=1
(131/10)%10=3
(131/100)%10=1
Then you can store this in an array and compare ranks starting from the end and from the beginning.
Don't forget to cast all the results into integers to round the values.