{"id":23262937,"url":"https://github.com/rebelhere/josephus-problem","last_synced_at":"2025-06-20T11:07:22.670Z","repository":{"id":259979132,"uuid":"879395289","full_name":"Rebelhere/Josephus-Problem","owner":"Rebelhere","description":"This program solves the Josephus Problem using a circular Queue in C++ and visualizes it with SFML. Participants are sequentially eliminated every K-th position until only one survivor remains, displayed with graphical updates and sound effects. The program provides an interactive view of the elimination process and the final winner.","archived":false,"fork":false,"pushed_at":"2024-10-28T20:51:57.000Z","size":12188,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-06T06:22:20.904Z","etag":null,"topics":["cpp","data-structures","josephus-problem","oop","queue","sfml"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Rebelhere.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-27T19:36:35.000Z","updated_at":"2024-11-19T18:20:35.000Z","dependencies_parsed_at":"2024-10-28T22:47:09.620Z","dependency_job_id":null,"html_url":"https://github.com/Rebelhere/Josephus-Problem","commit_stats":null,"previous_names":["rebelhere/josephus-problem"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Rebelhere/Josephus-Problem","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rebelhere%2FJosephus-Problem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rebelhere%2FJosephus-Problem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rebelhere%2FJosephus-Problem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rebelhere%2FJosephus-Problem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Rebelhere","download_url":"https://codeload.github.com/Rebelhere/Josephus-Problem/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rebelhere%2FJosephus-Problem/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260933193,"owners_count":23084949,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","data-structures","josephus-problem","oop","queue","sfml"],"created_at":"2024-12-19T14:13:27.646Z","updated_at":"2025-06-20T11:07:17.658Z","avatar_url":"https://github.com/Rebelhere.png","language":"C++","readme":"\n# Josephus Problem Solver with Graphical Visualization\n\nThis project provides a graphical simulation of the Josephus problem using C++ and SFML for visual rendering. In the Josephus problem, people stand in a circle and are eliminated at regular intervals until only one survivor remains. This program visualizes each elimination step and highlights the final survivor with a graphical user interface (GUI).\n\n## Problem Statement\n\nThe Josephus problem is a classic counting problem where:\n1. **N** people stand in a circle, waiting to be eliminated.\n2. Counting starts at a randomly selected person and proceeds clockwise.\n3. Every **k-th** person is eliminated until only one person remains, who is declared the survivor.\n\n### Features\n\n- **Graphical Visualization**: Using SFML, each person is represented as a sprite that visually shows the elimination process.\n- **Sound Effects**: Each elimination and victory display includes sound effects for an engaging experience.\n- **User Input**: The program accepts the number of people (**N**) and the step count (**K**) as input from the user.\n- **Customizable Radius**: The circle size adjusts based on the number of people to maintain readability.\n\n## Getting Started\n\n### Prerequisites\n\n- **C++11** or newer.\n- **SFML Library**: You need to install SFML (Simple and Fast Multimedia Library) for graphics, window handling, and audio.\n  \n  To install SFML, use:\n  ```bash\n  sudo apt-get install libsfml-dev  # For Debian/Ubuntu\n  brew install sfml                 # For macOS\n  ```\n\n### Installation\n\n1. Clone the repository:\n\n    ```bash\n    git clone \u003chttps://github.com/Rebelhere/Josephs-Problem\u003e\n    cd JosephusProblemSolver\n    ```\n\n2. Ensure you have the necessary assets in the same directory as the executable:\n    - `1.mp3`: Background music during the simulation.\n    - `2.mp3`: Sound effect for each elimination.\n    - `3.mp3`: Sound effect for the winner display.\n    - `alive.png`: Image to represent alive participants.\n    - `dead.png`: Image to represent eliminated participants.\n    - `winner.jpg`: Image to represent the final survivor.\n    - `1.ttf`: Font file for displaying text.\n\n### Building the Project\n\nCompile the code with SFML:\n\n```bash\ng++ josephus.cpp -o josephus -lsfml-graphics -lsfml-window -lsfml-audio -lsfml-system\n```\n\nRun the program:\n\n```bash\n./josephus\n```\n\n## Usage\n\n1. **Start the program** and enter values for:\n   - **N**: The number of people in the circle.\n   - **K**: The interval for elimination (every k-th person will be removed).\n2. The graphical window will open, displaying the participants in a circle.\n3. The elimination process will start, with each elimination shown in the GUI and accompanied by a sound.\n4. Once only one participant remains, they will be highlighted as the survivor with a congratulatory message and sound effect.\n\n## Code Overview\n\n### Key Files and Functions\n\n- **Queue Class**: Custom queue implementation used to manage the circle of participants.\n  - `Enqueue(T val)`: Adds a participant to the queue.\n  - `Dequeue()`: Removes a participant from the queue.\n  - `kill()`: Executes the elimination process by removing every k-th person.\n  - `josephproblem(RenderWindow\u0026 window)`: Manages the Josephus process and updates the GUI.\n\n- **printwindow**: Displays the current state of the circle, marking each person as either alive or dead.\n\n- **printwinner**: Displays the winning participant after all others are eliminated.\n\n### Graphics and Audio\n\n- **Sprites**: The program uses `alive.png` and `dead.png` for participants. The survivor is shown with `winner.jpg`.\n- **Sound Effects**: \n  - Elimination events play the sound from `2.mp3`.\n  - Background music plays from `1.mp3`.\n  - Winner announcement plays `3.mp3`.\n\n## Example\n\nFor **N = 7** and **K = 3**:\n- The program displays a circle of 7 participants.\n- Each 3rd person is eliminated in clockwise order until only one remains.\n- The GUI updates in real-time, showing the elimination sequence and final winner.\n\n## Future Enhancements\n\n- **Adjustable Parameters**: Add user controls for adjusting speed and volume.\n- **Different Elimination Animations**: Introduce more visual effects for eliminations.\n\n## Contributing\n\nFeel free to open issues or submit pull requests for improvements or bug fixes.\n\n## Collaboration Guidelines\n\nWe welcome contributions from the open-source community. If you'd like to collaborate on this project, please adhere to the following guidelines:\n1. Fork the repository.\n2. Create a new branch for your feature or bug fix.\n3. Implement your changes and commit them with descriptive messages.\n4. Push your branch to your fork and submit a pull request.\n\n### Feel free to reach out if you have any questions or suggestions !\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frebelhere%2Fjosephus-problem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frebelhere%2Fjosephus-problem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frebelhere%2Fjosephus-problem/lists"}