Skip to content

Commit af51229

Browse files
committed
Add LICENSE and README files; update sample prisoner strategy in config.py
1 parent 4b7dbcc commit af51229

File tree

3 files changed

+85
-6
lines changed

3 files changed

+85
-6
lines changed

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 TechRedByte
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# 100 Prisoners Simulator
2+
3+
A Python simulation of the **100 prisoners problem**, where each prisoner must find their own number hidden in one of 100 boxes.
4+
This project allows you to run multiple simulations using **custom strategies**, view success rates, and manage runs through a clean working directory system.
5+
6+
If you have any questions or suggestions, feel free to open an issue or submit a pull request! It would make my day. 😊
7+
8+
---
9+
10+
## 🎯 Features
11+
- Run a predefined number of simulations automatically
12+
- Use **custom strategies** for box selection
13+
- Customize the number of prisoners and maximum box checks
14+
- Calculate and display:
15+
- Overall chance of success
16+
- Built-in directory management for saving results and configurations
17+
18+
---
19+
20+
## 🧠 About the Project
21+
I created this simulator because I wanted a way to **easily prove the math** behind the 100 prisoners problem, and to **experiment with different strategies** that people have come up with, maybe even stumble upon a new, better one. 😉
22+
23+
The 100 prisoners problem is a classic probability and logic puzzle. Each prisoner may open up to half the boxes (50) to find their number.
24+
If **all** prisoners succeed, they are freed; if even one fails, they all lose.
25+
26+
---
27+
28+
## 📺 Video explanation & best strategy
29+
30+
A clear video explanation of the 100 prisoners problem and the best strategy so far (cycle following) can be found here:
31+
[https://youtu.be/iSNsgj1OCLA?si=Bgq4OAlChz_tSI_g](https://)
32+
33+
---
34+
35+
## ⚙️ Usage
36+
1. Clone the repository
37+
2. Copy the config.py file to your working directory and configure your strategy and other parameters inside the config file
38+
3. Run the main Python file:
39+
```bash
40+
python main.py
41+
```
42+
---
43+
44+
## 📜 License
45+
46+
MIT License - feel free to contribute or share it.
47+
48+
See LICENSE.md for details.
49+
50+
---
51+
52+
## 🧩 Future Ideas
53+
- Additional statistical plots
54+
55+
- Better GUI
56+
57+
- Parallelized simulations for faster results (when Python )

config.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'''
22
This is a sample configuration file. You can modify the parameters and strategy as needed.
3-
Copy this file as config.py to each of your working directory.
3+
Copy this file as config.py to each of your working directories.
44
'''
55

66
import random
@@ -15,8 +15,9 @@
1515
def getConfig():
1616
return CONFIG
1717

18-
def prisonerStrategy(prisoner_id, prisoners, total_checks, checked_boxes):
19-
# Set strategy here
20-
# Example: Random choice strategy
21-
available_boxes = [i for i in range(len(prisoners)) if i not in checked_boxes]
22-
return random.choice(available_boxes)
18+
def prisonerStrategy(prisoner_id, prisoners, total_checks, checked_boxes): # Set strategy here
19+
# Example: Loop strategy
20+
if checked_boxes:
21+
return(next(reversed(checked_boxes.values())))
22+
else:
23+
return prisoner_id

0 commit comments

Comments
 (0)