• API
• FAQ
• Tools
• Archive
SHARE
TWEET # alphabet challenge by zelrok a guest May 15th, 2013 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import re
2.
3. alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
4. best  = "JQBPCOUFVWMHAXZTRLIKNGEDSY" # 3038 words
6. # rules = generateRules(alpha) # This generates all the rules (650)
7. # rules = parseRules(words, rules) # This attributes them scores
8. # rules = purgeRules(rules) #  This removes rules opposite each other
9. # eg (A,B) and (B,A), it removes the lower scoring rule.
11. monsterBuild(alpha, rules)
12.
13. def wordAgainstRule(word,rule):
14.     pattern = rule+".*"+rule
15.     if (re.search(pattern,word)==None):
16.         #print("Rule Stands")
17.         return 1
18.     else:
19.         #print("Rule Broken")
20.         return 0
21.
22. def ruleAgainstList(words,rule):
23.     sum = 0
24.     for word in words:
25.         sum += wordAgainstRule(word,rule)
26.     return sum
27.
28. def parseRules(words,rules):
29.     for x in rules:
30.         x = ruleAgainstList(words,x)
31.     rules.sort(key=lambda x: x)
32.     return rules
33.
34. def wordAgainstAlpha(word,alpha):
35.     for i in range(25):
36.         if (wordAgainstRule(word,[alpha[i],alpha[i+1],0])==0):
37.             #print("Not Alphabetical")
38.             return 0
39.     #print ("Alphabetical")
40.     return 1
41.
42. def purgeRules(rules):
43.     for x in rules:
44.         for y in rules:
45.             if (x == y) & (x == y):
46.                 rules.pop(rules.index(y))
47.
48. def generateRules(alpha):
49.     rules = []
50.     for x in alpha:
51.         for y in alpha:
52.             if(x!=y):
53.                 rules.append([x,y,0])
54.     return rules
55.
56. def buildAlpha(alpha,rules):
57.     for x in rules:
58.         if wordAgainstRule(alpha,x) == 0:
59.             return x
60.
61. def letterSwitch(alpha,rule):
62.     alphaArray = []
63.     alphaString = ""
64.     for x in alpha:
65.         alphaArray.append(x)
66.     popped = alphaArray.pop(alphaArray.index(rule))
67.     alphaArray.insert(alphaArray.index(rule), popped)
68.     for x in alphaArray:
69.         alphaString += x
70.     return alphaString
71.
72. def monsterBuild(alpha, rules):
73.     alphas = []
74.     rule = buildAlpha(alpha, rules)
75.     while rule:
76.         alpha = letterSwitch(alpha, rule)
77.         if alpha in alphas:
78.             rules.pop(rules.index(rule))
79.         else:
80.             alphas.append(alpha)
81.         rule = buildAlpha(alpha,rules)
82.         print(rule, alpha)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Top