Giter VIP home page Giter VIP logo

josephus-problem's Introduction

Josephus Problem Solver

Implementation of a solver for the Josephus problem.

The project includes two versions of the implementation:

  1. recursive - see RecursiveJosephusProblemSolver
  2. iterative - see IterativeJosephusProblemSolver

The runtime implementation can be selected by an optional argument --mode which can be either recursive or iterative (default is recursive). See Running for details.

Testing

To run the unit tests of the project simply execute:

$ sbt clean test

Running

Basic usage:

$ sbt 'run n k'

where n and k are the total number of "participants" and the exclusion increment, respectively. Example usage:

$ sbt 'run 10 4'

which produces the result:

[info] Running net.thenobody.josephus.Main 10 4
22:15:23.260 [run-main-0] INFO  net.thenobody.josephus.Main$ - Using recursive mode
22:15:23.265 [run-main-0] INFO  net.thenobody.josephus.Main$ - Result: 5

For a more verbose list of available settings run:

$ sbt 'run --help'

Specifying implementation

It is possible to explicitly set the runtime implementation of the solver by setting the --mode parameter. Available implementations are: recursive or iterative (default is recursive).

Example usage:

$ sbt 'run --mode iterative 100 13'

which produces the result:

[info] Running net.thenobody.josephus.Main --mode iterative 100 13
22:21:39.264 [run-main-0] INFO  net.thenobody.josephus.Main$ - Using iterative mode
22:21:39.273 [run-main-0] INFO  net.thenobody.josephus.Main$ - Result: 70

josephus-problem's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.