Created
July 2, 2012 17:14
-
-
Save raullenchai/3034378 to your computer and use it in GitHub Desktop.
Compute the Inverse of a Permutation in F_2^n
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
import math | |
def isPerm(x): | |
if math.log(len(x), 2)% 1 != 0: | |
return False | |
for i in range(len(x)): | |
try: | |
x.index(i) | |
except ValueError: | |
return False | |
return True | |
def inv(x): | |
finv = [ 0 for i in range(len(x)) ] | |
for i in range(len(x)): | |
finv[f[i]] = i; | |
return finv | |
if __name__ == '__main__': | |
f = [1,3,2,0] | |
if isPerm(f): | |
print inv(f) | |
else: | |
print 'Not a Permutation!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment