2025-10-10 14:24:50 -04:00
|
|
|
"""
|
|
|
|
|
name: Nicholas Tamassia
|
|
|
|
|
|
|
|
|
|
Honor Code and Acknowledgments:
|
|
|
|
|
|
|
|
|
|
This work complies with the JMU Honor Code.
|
|
|
|
|
|
|
|
|
|
Comments here on your code and submission.
|
|
|
|
|
"""
|
|
|
|
|
|
2025-10-13 21:52:12 -04:00
|
|
|
import pprint
|
|
|
|
|
|
2025-10-10 14:24:50 -04:00
|
|
|
|
|
|
|
|
def valid_shuffle(a: str, b: str, c: str) -> bool:
|
|
|
|
|
|
|
|
|
|
memo: list[list[bool | None]] = [
|
|
|
|
|
([None] * (len(a) + 1)) for _ in range(0, len(b) + 1)
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
memo[len(a)][len(b)] = True
|
|
|
|
|
|
|
|
|
|
def recurse(i: int, j: int) -> bool:
|
|
|
|
|
if i >= len(a) or j >= len(b):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
k: int = i + j
|
|
|
|
|
if k == (len(c) - 2):
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
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
|
2025-10-13 21:52:12 -04:00
|
|
|
memo[i + 1][j] = a_val
|
2025-10-10 14:24:50 -04:00
|
|
|
|
|
|
|
|
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
|
2025-10-13 21:52:12 -04:00
|
|
|
memo[i][j + 1] = b_val
|
2025-10-10 14:24:50 -04:00
|
|
|
|
|
|
|
|
memo[i][j] = a_val or b_val
|
|
|
|
|
|
|
|
|
|
return a_val or b_val
|
|
|
|
|
|
2025-10-13 21:52:12 -04:00
|
|
|
val = recurse(0, 0)
|
|
|
|
|
|
|
|
|
|
pprint.pprint(memo)
|
|
|
|
|
|
|
|
|
|
return val
|
2025-10-10 14:24:50 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# All modules for CS 412 must include a main method that allows it
|
|
|
|
|
# to imported and invoked from other python scripts
|
|
|
|
|
def main():
|
|
|
|
|
a: str = input()
|
|
|
|
|
b: str = input()
|
|
|
|
|
c: str = input()
|
|
|
|
|
|
|
|
|
|
print(valid_shuffle(a, b, c))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|