jc.jang

프로그래머스 - 모의고사 본문

개발/코딩인터뷰완전분석

프로그래머스 - 모의고사

jangstory 2019. 9. 11. 00:04

문제

풀이

answers = [1, 2, 3, 4, 5]
# answers = [1, 3, 2, 4, 2]
result = [1]
# result = [1, 2, 3]


def test_simple():
    assert solution(answers) == result


def solution(answers):
    abandoner_a = [1, 2, 3, 4, 5]
    abandoner_b = [2, 1, 2, 3, 2, 4, 2, 5]
    abandoner_c = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]

    score = [0, 0, 0]
    
    for i in range(len(answers)):
        if abandoner_a[i%5] == answers[i]:
            score[0] += 1
        if abandoner_b[i%8] == answers[i]:
            score[1] += 1
        if abandoner_c[i%10] == answers[i]:
            score[2] += 1
    
    answer = list()
    
    for index, value in enumerate(score):
        if max(score) == value:
            answer.append(index+1)

    return answer
  •  
Comments