This commit is contained in:
Daniel Weber 2024-12-19 11:37:27 -05:00
parent 9abf9acc77
commit 33eadbdbb1

View File

@ -14,8 +14,12 @@ def check_matchp1(p, t):
return True
return False
G = {}
def match_count(p, t):
count = 0
if p in G:
return G[p]
else:
if p=='':
return count
for ts in t:
@ -24,23 +28,10 @@ def match_count(p, t):
else:
if p[:len(ts)] == ts[:len(p)]:
sub_count = match_count(p[len(ts):], t)
if sub_count > 0:
count += sub_count
G[p] = count
return count
def find_substrings(p, t):
ss = []
if p=='':
return ss
for ts in t:
if p == ts:
ss.append(ts)
else:
if p[:len(ts)] == ts[:len(p)]:
ss.append(find_substrings(p[len(ts):], t))
return ss
def part_one(p, t):
p1=0
for ps in p:
@ -50,24 +41,15 @@ def part_one(p, t):
def part_two(p, t):
p2 = 0
tset = set(t)
for ts in tset:
print("SUBSTRING: ", ts)
print(find_substrings(ts, tset))
# for c, ps in enumerate(p):
# p2 += match_count(ps, t)
for ps in p:
p2 += match_count(ps, t)
print("p2: ", p2)
def main():
f = open('test.txt', 'r')
f = open('input.txt', 'r')
contents = [x.strip() for x in f.readlines()]
print(contents)
towels = contents[0].split(", ")
patterns = contents[2:]
print(patterns)
print(towels)
part_one(patterns, towels)
part_two(patterns, towels)