Josephus Problem in Javascript (original) (raw)
Sample Programs in Every Language
A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Published on 08 October 2021 (Updated: 08 October 2021)
Welcome to the Josephus Problem in Javascript page! Here, you'll find the source code for this program as well as a description of how the program works.
Current Solution
const josephus = (n, k) => {
if (n == 1) return 1;
else return ((josephus(n - 1, k) + k - 1) % n) + 1;
};
const usage =
"Usage: please input the total number of people and number of people to skip.";
const n = parseInt(process.argv[2]);
const k = parseInt(process.argv[3]);
if (!n || !k || typeof n !== "number" || typeof k !== "number") {
return console.log(usage);
}
console.log(josephus(n, k));
Josephus Problem in Javascript was written by:
- Matteo Planchet
If you see anything you'd like to change or update, please consider contributing.
How to Implement the Solution
No 'How to Implement the Solution' section available. Please consider contributing.
How to Run the Solution
No 'How to Run the Solution' section available. Please consider contributing.