Algorithm(알고리즘)/Greedy Algorithm

2) 세 사람의 카드게임에서 한장씩 뽑아 가장 큰 곱 출력 함수

고로케 2021. 5. 16.
반응형
  1. 세 사람의 카드게임에서 한장씩 뽑아 가장 큰 곱 출력 함수
def max_product(card_lists):
    max_result = 1

    for i in card_lists:
        max_result *= max(i)
    return max_result

# 테스트
test_cards1 = [[1, 6, 5], [4, 2, 3]]
print(max_product(test_cards1))

test_cards2 = [[9, 7, 8], [9, 2, 3], [9, 8, 1], [2, 8, 3], [1, 3, 6], [7, 7, 4]]
print(max_product(test_cards2))

test_cards3 = [[1, 2, 3], [4, 6, 1], [8, 2, 4], [3, 2, 5], [5, 2, 3], [3, 2, 1]]
print(max_product(test_cards3))

test_cards4 = [[5, 5, 5], [4, 3, 5], [1, 1, 1], [9, 8, 3], [2, 8, 4], [5, 7, 4]]
print(max_product(test_cards4))

# 결과 : 
24
244944 
10800
12600

 

반응형

댓글