import itertools

def solve_all(numbers, goal=24, expr=[], solutions=None):
    if solutions is None:
        solutions = []
    if expr == []:
        expr = [str(n) for n in numbers]
    if len(numbers) == 1:
        if numbers[0] == goal:
            solutions.append(''.join(expr))  # Add the solution to the list
        return
    if len(numbers) == 2:
        answers, answer_exps = combinetwo(numbers[0], numbers[1])
        for i, answer in enumerate(answers):
            if answer == goal:
                solutions.append(remove_redundant_brackets(''.join(convert_expr_to_string(expr[0], expr[1], answer_exps[i]))))
        return

    pairs = set(itertools.combinations(numbers, 2))
    for pair in pairs:
        possible_values, possible_expr = combinetwo(pair)
        for counter, value in enumerate(possible_values):
            expression = possible_expr[counter]
            a_index = numbers.index(pair[0])
            b_index = numbers.index(pair[1])
            if a_index == b_index:
                b_index = numbers.index(pair[1], a_index + 1)

            expr_string = convert_expr_to_string(expr[a_index], expr[b_index], expression)
            newlist = numbers[:]
            newexpr = expr[:]

            # replace the two numbers with the combined result
            newlist.pop(b_index)
            newlist.pop(a_index)
            newlist.append(value)

            # order matters
            newexpr.pop(b_index)
            newexpr.pop(a_index)
            newexpr.append(expr_string)
            solve_all(newlist, goal, newexpr, solutions)

    return solutions

def convert_expr_to_string(a, b, expr):
    temp = [a, b]
    result = '(' + str(temp[expr[0]]) + ')' + str(expr[1]) + '(' + str(temp[expr[2]]) + ')'
    return result

def combinetwo(a, b):
    result = [a + b, a * b]
    expr = [(0, '+', 1), (0, '', 1)]
    if b > a:
        result.append(b-a)
        expr.append((1, '-', 0))
    else:
        result.append(a-b)
        expr.append((0, '-', 1))
    if b != 0:
        result.append(a / b)
        expr.append((0, '/', 1))
    if a != 0:
        result.append(b / a)
        expr.append((1, '/', 0))
    return result, expr

def remove_redundant_brackets(expr):
    stack = []
    indices = []
    for i, ch in enumerate(expr):
        if ch == '(':
            stack.append(i)
        elif ch == ')':
            last_bracket_index = stack.pop()
            enclosed = expr[last_bracket_index + 1:i]
            if enclosed.isdigit():
                indices.append(i)
                indices.append(last_bracket_index)
    return "".join([char for idx, char in enumerate(expr) if idx not in indices])

# Example usage:
solutions = solve_all([2, 3, 4, 5])
for solution in solutions:
    print(solution)     I get the following error when executing the code above, what to do? ---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-1ae7a74792e3> in <cell line: 83>()
     81 
     82 # Example usage:
---> 83 solutions = solve_all([2, 3, 4, 5])
     84 for solution in solutions:
     85     print(solution)

<ipython-input-7-1ae7a74792e3> in solve_all(numbers, goal, expr, solutions)
     19     pairs = set(itertools.combinations(numbers, 2))
     20     for pair in pairs:
---> 21         possible_values, possible_expr = combinetwo(pair)
     22         for counter, value in enumerate(possible_values):
     23             expression = possible_expr[counter]

TypeError: combinetwo() missing 1 required positional argument: 'b'