Created
April 21, 2009 05:09
-
-
Save erickedji/98950 to your computer and use it in GitHub Desktop.
Khaled's challenge (RVB<->Integer)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def int2rvb(n): | |
| n = n - 1 # normaliser | |
| b = n % 256 | |
| v = (n % (256**2)) / 256 | |
| r = (n % (256**3)) / 256**2 | |
| return (r, v, b) | |
| def rvb2int(r, v, b): | |
| return r*(256**2) + v*256 + b + 1 | |
| for i in range(1, 16777217): | |
| (r, v, b) = int2rvb(i) | |
| if (i != rvb2int(r, v, b)): | |
| print "Aïe!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment