Shuffle: Fixed memoization table filling

This commit is contained in:
2025-10-13 21:52:12 -04:00
parent 6a9630c5ac
commit ff22086802

View File

@@ -8,6 +8,8 @@ Honor Code and Acknowledgments:
Comments here on your code and submission.
"""
import pprint
def valid_shuffle(a: str, b: str, c: str) -> bool:
@@ -28,16 +30,22 @@ def valid_shuffle(a: str, b: str, c: str) -> bool:
a_val: bool | None = memo[i + 1][j]
if a_val is None:
a_val = recurse(i + 1, j) if a[i] == c[k] else False
memo[i + 1][j] = a_val
b_val: bool | None = memo[i][j + 1]
if b_val is None:
b_val = recurse(i, j + 1) if b[j] == c[k] else False
memo[i][j + 1] = b_val
memo[i][j] = a_val or b_val
return a_val or b_val
return recurse(0, 0)
val = recurse(0, 0)
pprint.pprint(memo)
return val
# All modules for CS 412 must include a main method that allows it