Skip to content

Instantly share code, notes, and snippets.

@Scinawa
Created March 24, 2016 04:23
Show Gist options
  • Save Scinawa/d3b2d1a3eba8789fc144 to your computer and use it in GitHub Desktop.
Save Scinawa/d3b2d1a3eba8789fc144 to your computer and use it in GitHub Desktop.
Injective functions from N to X
>>> s="ABCD"
>>> repetition=3
>>> a = [i for i in itertools.permutations(s, repetition)]
>>> len(a) == math.factorial(len(s)) / math.factorial(len(s)-repetition)
True
def sample_function(n=0, s=set() ):
f = {}
for i in range(0, n):
f[i]=random.choice(s)
s.remove(f[i]) #injective functions here
def _function(x):
return f[x]
return _function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment