|
| 1 | +function solution(answers) { |
| 2 | + var answer = []; |
| 3 | + |
| 4 | + // 1번: 1, 2, 3, 4, 5, |
| 5 | + // 6, 7, 8, 9, 10 |
| 6 | + // 2번: 2, 1, 2, 3, 2, 4, 2, 5 |
| 7 | + // a[0] = p2[0] 0 % 7 = 0 |
| 8 | + // a[1] = p2[1] 1 % 7 = 1 |
| 9 | + // a[8] = p2[0] 8 % 7 = 1 - 1 |
| 10 | + // 3번: 3, 3, 1, 1, 2, 2, 4, 4, 5, 5 |
| 11 | + // a[0] = p3[0] = 0 & 9 = 0 |
| 12 | + // a[1] = p3[1] = 1 % 9 = 1 |
| 13 | + |
| 14 | + // a[10] = p3[0] 10 % 9 - 1 |
| 15 | + // a[11] = p3[1] 11 % 9 = 2 - 1 = 1 |
| 16 | + // a[12] = p3[2] 12 % 9 = 3 - 1 = 2 |
| 17 | + |
| 18 | + const p2 = [2, 1, 2, 3, 2, 4, 2, 5]; |
| 19 | + const p3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]; |
| 20 | + |
| 21 | + const corrects = [0, 0, 0]; |
| 22 | + |
| 23 | + answers.forEach((ans, idx) => { |
| 24 | + if (ans === (idx % 5) + 1) { |
| 25 | + corrects[0] = corrects[0] + 1; |
| 26 | + } |
| 27 | + |
| 28 | + if (ans === p2[idx % 8]) { |
| 29 | + corrects[1] = corrects[1] + 1; |
| 30 | + } |
| 31 | + |
| 32 | + if (ans === p3[idx % 10]) { |
| 33 | + corrects[2] = corrects[2] + 1; |
| 34 | + } |
| 35 | + }); |
| 36 | + |
| 37 | + const max = Math.max(...corrects); |
| 38 | + |
| 39 | + corrects.forEach((c, i) => { |
| 40 | + if (c === max) { |
| 41 | + answer.push(i + 1); |
| 42 | + } |
| 43 | + }); |
| 44 | + |
| 45 | + return answer; |
| 46 | +} |
| 47 | + |
| 48 | +function solution2(answers) { |
| 49 | + let answer = []; |
| 50 | + |
| 51 | + const num1 = [1, 2, 3, 4, 5]; |
| 52 | + const num2 = [2, 1, 2, 3, 2, 4, 2, 5]; |
| 53 | + const num3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]; |
| 54 | + |
| 55 | + const score = new Map(); |
| 56 | + score.set(1, 0); |
| 57 | + score.set(2, 0); |
| 58 | + score.set(3, 0); |
| 59 | + |
| 60 | + answers.forEach((ans, idx) => { |
| 61 | + if (num1[idx % 5] === ans) { |
| 62 | + score.set(1, score.get(1) + 1); |
| 63 | + } |
| 64 | + |
| 65 | + if (num2[idx % 8] === ans) { |
| 66 | + score.set(2, score.get(2) + 1); |
| 67 | + } |
| 68 | + |
| 69 | + if (num3[idx % 10] === ans) { |
| 70 | + score.set(3, score.get(3) + 1); |
| 71 | + } |
| 72 | + }); |
| 73 | + |
| 74 | + const max = Math.max(...score.values()); |
| 75 | + |
| 76 | + for (const [key, value] of score.entries()) { |
| 77 | + if (value === max) { |
| 78 | + answer.push(key); |
| 79 | + } |
| 80 | + } |
| 81 | + return answer; |
| 82 | +} |
0 commit comments