[プログラマー/python]完全ナビゲーション-シミュレーション試験



😎 私の回答(50%)

def solution(answers):
    answer = []
    student = [[1,2,3,4,5] ,[2,1,2,3,2,4,2,5] ,[3,3,1,1,2,2,4,4,5,5]]
    # dictionary로 정의했으나, 힌트를 보고 수정,.
    result = [0,0,0]

    for j in range(len(student)):
        for i in range(len(answers)):
            n = len(student[j])
            if answers[i] == student[j][i%n]:                
                result[j] += 1
                
    for idx,score in enumerate(result):
        if score == max(result):
            answer.append(idx+1)

    return answer
  • n = len(student[j]):小胞子のパターン数
  • student[j][i%n]:質問正解数に応じて、小胞子のパターンを繰り返す
  • data = [1,2]
    answers = [1,2,3,4,5,6,7,8]
    n = len(data) # 2
    print(answers[0],data[0%n]) # 1 1
    print(answers[1],data[1%n]) # 2 2          
    print(answers[2],data[2%n]) # 3 1
    print(answers[3],data[3%n]) # 4 2
    一つのコメント:繰り返しモード!!そんな方法!!!