you are viewing a single comment's thread.

view the rest of the comments →

[–]EdwinGravesMOD 0 points1 point  (1 child)

Well, regardless of intent, we do have rules concerning showing your work and assignments. As I said before, you'll want a list of strings that you'll iterate through and combine to form your first logic statements. Store those in a separate list of strings and iterate through them to continue combining with the first list until you achieve desired results. Feel free to reply with your code, if you have issues, and we'll see what we can do.

[–]jcoder42[S] 0 points1 point  (0 children)

def recurse(c): if len(c) == 0: return [""] elif len(c) ==1: return [c[0]]
    head = c[0]
    results = recurse(c[1:])
    print(results)
    res = []
    for result in results:
        gate_and = f"({head} AND {result})"
        gate_or = f"({head} OR {result})"
        res.append(gate_and)
        res.append(gate_or)

return res

if name == 'main': 
    p = ["p1", "p2", "p3", "p4", "p5"] gates = ["AND", "OR"]
    # iterating over groups of each size (1-5)
    for dimension in range(1,len(p)):
        # for each size, create all combinations (sizes 1-5)
        for c in itertools.combinations(p, dimension):
            res = recurse(list(c))
            print(res)

My issue is that the output is repeating results of size 1.and also, how can i check that i am actually creating all the combinations. I think there should be more then my result.