
const fs = require('fs');
const path = process.platform === 'linux' ? '/dev/stdin' : 'Wiki\\input.txt';
const [n, k] = fs
.readFileSync(path)
.toString()
.trim()
.split(' ')
.map((it) => Number(it));
const arr = Array.from({ length: n }, (_, i) => i + 1);
const result = [];
while (result.length !== n) {
let count = 0;
while (count < k - 1) {
arr.push(arr.shift());
count += 1;
}
result.push(arr.shift());
}
console.log('<' + result.join(', ') + '>');
k번째 사람들을 n명 선택해서 빈배열 result에 넣어준다.
즉 result배열의 길이가 n이 될때까지 반복한다. 그리고 k번째 사람을 배열에 넣어줘야 하므로 arr배열을 옆으로 돌려준다.(arr.push(arr.shift()))
k번 돌렸으면 arr에서 그 사람을 빼 result배열에 넣어준다.
반복이 다 끝나고 result배열을 출력형식에 맞게 출력해주면 끝!