フルナビゲーションシミュレーション試験

1722 ワード

def solution(answers):
    answer = []

    stu1 = [1,2,3,4,5]
    stu2 = [2,1,2,3,2,4,2,5]
    stu3 = [3,3,1,1,2,2,4,4,5,5]
    i = 0   
    cnt1 = 0
    cnt2 = 0
    cnt3 = 0

    while i < len(answers):      
        for x in stu1 :
            if i < len(answers) :
                if answers[i] == x :
                    cnt1 += 1
                i += 1
    i = 0
    while i < len(answers):      
        for x in stu2 :
            if i < len(answers) :
                if answers[i] == x :
                    cnt2 += 1
                i += 1

    i = 0
    while i < len(answers):      
        for x in stu3 :
            if i < len(answers) :
                if answers[i] == x :
                    cnt3 += 1
                i += 1                

    c_list = [cnt1,cnt2,cnt3]
    max_v = max(c_list)
    for i,v in enumerate(c_list) :
        if v == max_v :
            answer.append(i+1)

    print(answer)
    print(c_list.index(max(c_list)))

    return answer
各学生の繰り返しデジタルモードを利用して、
正解と学生モードのインデックスを比較すると、
1回の答えをスキャンすると、3人の学生の答えを比較することができます.
def solution(answers):
    pattern1 = [1,2,3,4,5]
    pattern2 = [2,1,2,3,2,4,2,5]
    pattern3 = [3,3,1,1,2,2,4,4,5,5]
    score = [0, 0, 0]
    result = []

    for idx, answer in enumerate(answers):
        if answer == pattern1[idx%len(pattern1)]:
            score[0] += 1
        if answer == pattern2[idx%len(pattern2)]:
            score[1] += 1
        if answer == pattern3[idx%len(pattern3)]:
            score[2] += 1

    for idx, s in enumerate(score):
        if s == max(score):
            result.append(idx+1)

    return result