Search code examples
phpfacebookmathconceptual

Reverse number order lowest become highest and highest become lowest?


I have a issue, I am using Facebook Score API. But by default it only sorts scores descending so for example 1000, is higher then 10. But my problem is my scores are based on time, so in my case 10 is better then 1000. And I don't really want to have to do it manually which requires looping over every facebook friend, seeing if they have a score, if they do cache it in an object, then reverse sort it.

So I am wondering if there is some way that I could make

10 or 6 or what ever a larger number then 1000 (so basically large numbers become small, and small numbers become large) which could then be reversed. I can do something to both ends (before they are posted, and when I retrieve them). But they have to remain numbers.

Any ideas if this is possible?

It cannot be a decimal or a negative number. The numbers will never be higher then 100,000 so it's basically 1-100000


Solution

  • If 100,000 is the highest number the score can be, then store the score as 100000 - actual_score. Later, you can retrieve the actual score by doing the same operation: 100000 - recorded_score.