Javascript
const test3 = (input) => {
let idx = 0, idx2 = 0, output = 0;
let list = [], list2 = [];
while(idx < input) {
list.push(++idx);
};
idx = -1;
do {
idx2 = 5;
do {
idx = ++idx > input - 1 ? 0 : idx;
idx2 = list[idx] != -1 ? --idx2 : idx2;
} while(idx2 != 0);
list2.push(list[idx]);
list[idx] = -1;
} while(list2.length != input);
output = list2.pop();
console.warn(`input ${input}, output ${output}`);
}
test3(6)
test3(11)