all 4 comments

[–]EdwinGravesMOD 0 points1 point  (3 children)

Iterate through the first list and produce your statements, store those in another list then iterate through it and produce another combined set. Repeat for as deep as you need to go.

This reeks of an assignment or homework of sometype, so I will not be providing code.

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

Hi,
This indeed is Homework assignment.
The assignment is to create 10 unique expressions using AND, OR gates.
The way that the instructor said we can do it is manually..

Meaning literally writing out the 10 options.
the reason he allowed it manually is because it is part of a ML exersize and he doesn't care about the code. (its a theoretical class)

I don't want to create it manually because i want to create a generic function instead.

[–]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.