Skip to content

Instantly share code, notes, and snippets.

@erickedji
Created April 21, 2009 05:09
Show Gist options
  • Select an option

  • Save erickedji/98950 to your computer and use it in GitHub Desktop.

Select an option

Save erickedji/98950 to your computer and use it in GitHub Desktop.
Khaled's challenge (RVB<->Integer)
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