Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import string
- alph = [' ','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
- def factorial(n):
- f = 1
- while(n > 1):
- f = f * n
- n = n - 1
- return f
- def binomial(a,b):
- if b > a:
- return 0
- return factorial(a)/(factorial(b)*factorial(a-b))
- def clean(s):
- return s.rjust(5, ' ').lower()
- def nxt(s):
- TERM = ['v','w','x','y','z']
- start = 4
- if(s[start] != TERM[start]): # If the index doesn't need to roll over,
- s[start] = alph[alph.index(s[start]) + 1] # Increment the last letter
- else: # We need to do le count!
- # find where we should start the count
- while(s[start] == TERM[start]):
- start = start - 1
- # count it! :D
- s[start] = alph[alph.index(s[start]) + 1]
- t = start + 1
- # make necessary trailing incrementations
- while(t < 5):
- s[t] = alph[alph.index(s[t-1])+1]
- t = t + 1
- return s
- def brute_gen():
- l = list()
- e = ['v','w','x','y','z']
- s = [' ',' ',' ',' ','a']
- while(s != e):
- l.append(str(s))
- s = nxt(s)
- l.append(e)
- return l
- def Problem2(s):
- s = clean(s)
- l = brute_gen()
- m = [' ',' ',' ',' ',' ']
- for x in range(5):
- m[x] = s[x]
- m = str(m)
- if (l.count(m) != 0):
- print l.index(m)
- else:
- print 'No.'
- def valid(s):
- if(len(s) != 5):
- return False
- for c in s:
- if(alph.count(c) == 0):
- return False
- for c in s:
- if(alph.index(c) == -1):
- return False
- for i in range(4):
- if(alph.index(s[i]) >= alph.index(s[i+1])):
- return False
- return True
- Problem2("r")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement