Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions search.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,11 +544,9 @@ def __call__(self, s1): # as of now s1 is a state rather than a percept
self.H[self.s] = min(self.LRTA_cost(self.s, b, self.problem.output(self.s, b),
self.H) for b in self.problem.actions(self.s))

# costs for action b in problem.actions(s1)
costs = [self.LRTA_cost(s1, b, self.problem.output(s1, b), self.H)
for b in self.problem.actions(s1)]
# an action b in problem.actions(s1) that minimizes costs
self.a = list(self.problem.actions(s1))[costs.index(min(costs))]
self.a = argmin(self.problem.actions(s1),
key=lambda b:self.LRTA_cost(s1, b, self.problem.output(s1, b), self.H))

self.s = s1
return self.a
Expand Down
6 changes: 2 additions & 4 deletions text.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,7 @@ def score(self, plaintext):
def decode(self, ciphertext):
"""Return the shift decoding of text with the best score."""

list_ = [(self.score(shift), shift)
for shift in all_shifts(ciphertext)]
return max(list_, key=lambda elm: elm[0])[1]
return argmax(all_shifts(ciphertext), key=lambda shift: self.score(shift))


def all_shifts(text):
Expand Down Expand Up @@ -360,7 +358,7 @@ def decode(self, ciphertext):
problem = PermutationDecoderProblem(decoder=self)
solution = search.best_first_graph_search(
problem, lambda node: self.score(node.state))
print(solution.state, len(solution.state))

solution.state[' '] = ' '
return translate(self.ciphertext, lambda c: solution.state[c])

Expand Down