Jump to content

Search the Community

Showing results for tags 'josephus'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Location


WWW


Interests

Found 1 result

  1. function josephus(array, count) { // Return store const store = []; // Counter for each time the element should be spliced let counter = 0; // Array index position let index = 0; while (array.length > 0) { // This is because 'array' is treated like a circular array index = index % array.length; if (++counter === count) { // Remove the element from the array and push onto the store. // The first element is used, hence [0] store.push(array.splice(index, 1)[0]); // Reset the counter counter = 0; // Move back one index value index--; } index++; } return store; } // Example console.log(josephus([1, 2, 3, 4, 5, 6, 7], 3)); console.log(josephus([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 1));More information about the problem can be found here >> https://en.wikipedia.org/wiki/Josephus_problem
×
×
  • Create New...