human
I found an interesting problem on https://www.codewars.com/kata/59c8b38423dacc7d95000008:
Now we will confect a reagent. There are eight materials to choose from, numbered 1,2,..., 8 respectively.

We know the rules of confect:
```
material1 and material2 cannot be selected at the same time
material3 and material4 cannot be selected at the same time
material5 and material6 must be selected at the same time
material7 or  material8 must be selected(at least one, or both)
```

# Task

You are given a integer array `formula`. Array contains only digits 1-8 that represents material 1-8. Your task is to determine if the formula is valid. Returns `true` if it's valid, `false` otherwise.

# Example

For `formula = [1,3,7]`, The output should be `true`.

For `formula = [7,1,2,3]`, The output should be `false`.

For `formula = [1,3,5,7]`, The output should be `false`.

For `formula = [1,5,6,7,3]`, The output should be `true`.

For `formula = [5,6,7]`, The output should be `true`.

For `formula = [5,6,7,8]`, The output should be `true`.

For `formula = [6,7,8]`, The output should be `false`.

For `formula = [7,8]`, The output should be `true`.

# Note

- All inputs are valid. Array contains at least 1 digit. Each digit appears at most once. 

- Happy Coding `^_^`

I tried it in Python, but could not do it. Can you solve it?
assistant
#Here is Python program to determine if the formula is valid.

def isValid(formula):
    m = [0, 1, 2, 3, 4, 5, 6, 7, 8]
    t = []
  
    def mat1_mat2():
        ## material1 and material2 cannot be selected at the same time
        count = 0
        for i in formula:
            if i == 1:
                count+=1
            if i == 2:
                count+=1
        if count == 0:
            t.append(True)
        elif count == 1:
            t.append(True)
        else:
            t.append(False)

    def mat3_mat4():
        ## material3 and material4 cannot be selected at the same time
        count = 0
        for i in formula:
            if i == 3:
                count+=1
            if i == 4:
                count+=1
        if count == 0:
            t.append(True)
        elif count == 1:
            t.append(True)
        else:
            t.append(False)

    def mat5_mat6():
        # material5 and material6 must be selected at the same time
        count = 0
        for i in formula:
            if i == 5:
                count+=1
            if i == 6:
                count+=1
        if count == 0:
            t.append(True)
        elif count == 1:
            t.append(False)
        else:
            t.append(True)

    def mat7_mat8():
        # material7 or material8 must be selected(at least one, or both)
        count = 0
        for i in formula:
            if i == 7:
                count+=1
            if i == 8:
                count+=1
        if count == 1:
            t.append(True)
        elif count == 2:
            t.append(True)
        else:
            t.append(False)
    
    mat1_mat2()
    mat3_mat4()
    mat5_mat6()
    mat7_mat8()

    return all(t)