• Как решить задачку по перебору неизвестных переменных при известном ответе в Python?

    @m_rob Автор вопроса
    Решение, которое удалось получить:

    def program_solver(inputlist: list):
        """
        Solves mathematical issue.
        :param inputlist:list, a list of integers
        :return: int, the first number of the modified list
        """
        chunk_of_numbers = []
        temp_list = inputlist[:]
        for a in temp_list:
            chunk_of_numbers.append(int(a))
            if len(chunk_of_numbers) == 4:
                if chunk_of_numbers[0] == 1:
                    sum_of_the_chunk = temp_list[chunk_of_numbers[1]] + temp_list[chunk_of_numbers[2]]
                    temp_list[chunk_of_numbers[3]] = sum_of_the_chunk
                    chunk_of_numbers.clear()
                elif chunk_of_numbers[0] == 2:
                    mult_of_the_chunk = temp_list[chunk_of_numbers[1]] * temp_list[chunk_of_numbers[2]]
                    temp_list[chunk_of_numbers[3]] = mult_of_the_chunk
                    chunk_of_numbers.clear()
                elif chunk_of_numbers[0] == 99:
                    result = temp_list[0]
                    return result
    
    
    inputlist = [
                 1, 15, 30, 3, 1, 1, 2, 3, 1, 3, 4, 3, 1, 5, 0, 3, 2, 6, 1, 19, 2, 19, 9, 23, 1, 23, 5, 27, 2, 6, 27, 31, 1,
                 31, 5, 35, 1, 35, 5, 39, 2, 39, 6, 43, 2, 43, 10, 47, 1, 47, 6, 51, 1, 51, 6, 55, 2, 55, 6, 59, 1, 10, 59,
                 63, 1, 5, 63, 67, 2, 10, 67, 71, 1, 6, 71, 75, 1, 5, 75, 79, 1, 10, 79, 83, 2, 83, 10, 87, 1, 87, 9, 91, 1,
                 91, 10, 95, 2, 6, 95, 99, 1, 5, 99, 103, 1, 103, 13, 107, 1, 107, 10, 111, 2, 9, 111, 115, 1, 115, 6, 119,
                 2, 13, 119, 123, 1, 123, 6, 127, 1, 5, 127, 131, 2, 6, 131, 135, 2, 6, 135, 139, 1, 139, 5, 143, 1, 143,
                 10, 147, 1, 147, 2, 151, 1, 151, 13, 0, 99, 2, 0, 14, 0
                 ]
    
    
    desire_result = 7156875
    number_range = range(1, 100)
    n = 0
    program_check = 0
    
    for x in number_range:
        inputlist[1] = x
        for y in number_range:
            inputlist[2] = y
            program_check = program_solver(inputlist)
            print(program_check)
            if program_check == desire_result:
                print(f"x = {x}, y = {y}")
                break
        if program_check == desire_result:
            break
    Ответ написан
    Комментировать