본문 바로가기
Algorithm(CodeTree, Python)/완전탐색3

[코드트리 기준을 새로 설정하여 완전탐색] A, B, C, D 찾기 2 Python

by kurooru 2023. 1. 3.
# num_list 입력
num_list = list(map(int, input().split()))

# 함수들
# is_possible(a, b, c, d)
def is_possible(a, b, c, d):

    # temp_list
    temp_list = [a, b, c, d, a+b, b+c, c+d, d+a, a+c, b+d, a+b+c, a+b+d, a+c+d, b+c+d, a+b+c+d]

    # temp_list 정렬
    temp_list.sort()

    # 반환
    return temp_list == num_list

# 설계
# num_list 정렬
num_list.sort()

# 완전 탐색 시작
for i in range(1, 41):
    for j in range(i, 41):
        for k in range(j, 41):
            for h in range(k, 41):
                # 조건을 만족하면
                if is_possible(i,j,k,h):
                    # 출력
                    print(i,j,k,h)