Skip to content

Commit

Permalink
Update pyramid-transition-matrix.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 authored Jan 1, 2018
1 parent 22376b3 commit 072c19a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Python/pyramid-transition-matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def pyramidTransition(self, bottom, allowed):
def pyramidTransitionHelper(bottom, edges, lookup):
def dfs(bottom, edges, new_bottom, idx, lookup):
if idx == len(bottom)-1:
return pyramidTransitionHelper(new_bottom, edges, lookup)
return pyramidTransitionHelper("".join(new_bottom), edges, lookup)
for i in edges[ord(bottom[idx])-ord('A')][ord(bottom[idx+1])-ord('A')]:
new_bottom[idx] = chr(i+ord('A'));
if dfs(bottom, edges, new_bottom, idx+1, lookup):
Expand All @@ -58,9 +58,9 @@ def dfs(bottom, edges, new_bottom, idx, lookup):

if len(bottom) == 1:
return True
if "".join(bottom) in lookup:
if bottom in lookup:
return False
lookup.add("".join(bottom))
lookup.add(bottom)
for i in xrange(len(bottom)-1):
if not edges[ord(bottom[i])-ord('A')][ord(bottom[i+1])-ord('A')]:
return False
Expand All @@ -71,4 +71,3 @@ def dfs(bottom, edges, new_bottom, idx, lookup):
for s in allowed:
edges[ord(s[0])-ord('A')][ord(s[1])-ord('A')].append(ord(s[2])-ord('A'))
return pyramidTransitionHelper(bottom, edges, set())

0 comments on commit 072c19a

Please sign in to comment.