Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def even_numbers(limit):
- x = 0
- while x < limit:
- yield x
- x += 2
- def factors(x):
- p = 2
- while p <= x:
- if x % p ==0:
- yield p
- p += 1
- def prime_factors(x):
- p = 2
- while p <= x:
- if x % p == 0 and len(factors(x)) == 2:
- yield p
- p += 1
- def factorial(x):
- if x == 0:
- return 1
- return factorial(x - 1) * x
- def permutation(s, x):
- if len(s) == 1:
- return tuple(s)
- if len(s) == 0:
- return ()
- s = list(s)
- selection = x % len(s)
- head = (s[selection],)
- del s[selection]
- return head + permutation(set(s), x // (len(s)+1))
- def permutations(s):
- x = factorial(len(s)) - 1
- while x >= 0:
- yield permutation(s, x)
- x -= 1
Advertisement
Add Comment
Please, Sign In to add comment