Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Code:
- def __init__(self, code):
- self.code = code
- pass
- def get_letter_count(self, letter):
- count=0
- for x in self.code:
- if letter==x:
- count+=1
- return count
- def get_counts(self):
- counts = {}
- for letter in self.code:
- if letter in counts:
- counts[letter]+=1
- else:
- counts[letter]=1
- return counts
- def get_exact_matches(self, other):
- matches = 0
- index=0
- while index<len(self.code):
- if self.code[index]==other.code[index]:
- matches+=1
- index+=1
- return matches
- def get_letter_matches(self, other):
- matches = 0
- OtherCounts =other.get_counts()
- g=self.get_counts()
- for letter in OtherCounts:
- if letter in g:
- if g[letter]>=OtherCounts[letter]:
- m=OtherCounts[letter]
- matches+=m
- else:
- m=g[letter]
- matches+=m
- return matches
- def get_misplacements(self, other):
- x=self.get_exact_matches(other)
- y=self.get_letter_matches(other)
- z=y-x
- if z<0:
- return 0
- else:
- return z
- def __repr__(self):
- return str("[" + self.code +"]")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement