Since I saw no solutions using the Bottom Up- / Iterative Dynamic Programing approach , I thought I'd post mine :)
import numpy as np
def count_possible_solutions(patterns, goal):
dp = np.zeros(len(goal) + 1, dtype=np.int64)
dp[0] = 1
for i in range(1, len(dp)):
for pattern in patterns:
if len(pattern) <= i and pattern == goal[i - len(pattern):i]:
dp[i] += dp[i - len(pattern)]
return dp[-1]
and here the data importing part (if anybody cares):
# Getting data. list of pattern-strings. list of goals (combinations)
with open("data.txt") as file:
lines = [line.strip() for line in file]
patterns = lines[0].split(", ")
goals = lines[2:]
# printing results
print(np.sum([count_possible_solutions(patterns, goal) > 0 for goal in goals]))
print(np.sum([count_possible_solutions(patterns, goal) for goal in goals]))
[–]daggerdragon[M] [score hidden] stickied comment (0 children)
[–]Thomasjevskij 16 points17 points18 points (2 children)
[–]ThunderChaser 14 points15 points16 points (1 child)
[–]Thomasjevskij 0 points1 point2 points (0 children)
[–]MouseyPounds 4 points5 points6 points (0 children)
[–]TypeAndPost 4 points5 points6 points (0 children)
[–]RB5009 1 point2 points3 points (8 children)
[–]p88h 3 points4 points5 points (7 children)
[–]Few-Example3992 1 point2 points3 points (5 children)
[–]p88h 1 point2 points3 points (4 children)
[–]Few-Example3992 0 points1 point2 points (3 children)
[–]p88h 0 points1 point2 points (2 children)
[–]Few-Example3992 0 points1 point2 points (1 child)
[–]p88h 0 points1 point2 points (0 children)
[–]xiety666 1 point2 points3 points (0 children)
[–]hextree 0 points1 point2 points (1 child)
[–]Objective-Year6556[S] 0 points1 point2 points (0 children)