Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<img src="https://img.shields.io/badge/Problem-not%20solved%20yet-yellow">

# Thirsty men problem

## The scene
Expand Down Expand Up @@ -32,10 +34,14 @@ The question : **In this context, how would your guests behave**, if you know th

To make the situation more real let's assume that **2<N<15**


## If you have questions
If you require additional information about the problem please open an issue in this repository. I'll provide the necessary clarifications

## How to propose solutions
Please fork/clone the repository, write your solution in a .txt file under the /solutions folder and then propose a [pull request](https://help.github.com/en/articles/creating-a-pull-request-from-a-fork). If the answer is correct the pull request will be accepted and you'll be added as **contributor**.

# This problem is not a simple riddle but it requires a creative mind



94 changes: 94 additions & 0 deletions solutions/Firstsolution.txt
Original file line number Diff line number Diff line change
@@ -1 +1,95 @@
Hint: I used artificial intelligence to remove all errors and present a clearer version of the original text.
(AI used only for text files and graph generation. No AI was used in the program - purely my work.)

Introduction :

Imagine a simple cup of water being shared among a group of guests. At first glance, it seems straightforward—everyone should get a fair share. But what if some guests are selfish? What if they change their minds, move seats to grab more, or prevent others from drinking? This simulation dives deep into the subtle dynamics of fairness, trust, and strategy in resource sharing.

Using this model, you’ll see how cooperation can break down, how selfish behaviors impact fairness, and how implementing ban systems can restore balance. Through detailed simulations, data, and visual graphs.

Whether you are interested in social dynamics, game theory, or just curious about fairness, this project offers a rich perspective on how rules, behavior, and enforcement shape collective outcomes. Explore how even simple rules can lead to complex and realistic social consequences.


Simulation of Water Sharing Among Guests: Behavior, Challenges, and Improvements

Initial Assumptions and Scenario

- Start with all guests as “good”: Everyone initially before pouring water.
- behavioral changes: once pouring water some guests change from good to bad when they see there are only 2 cups.
- Bad guest behaviors include:
- Drinking all water in the cup.
- Drinking more than the agreed share.
- Drinking their share but changing seats to drink more times.

Possible Dynamics and Cases

- Bad guests can switch back to good if influenced by others, and good guests can turn bad under bad influence.
- Bad guests try to exploit the system; good guests aim to share fairly.
- Guests change places only if they are bad; good guests stay put.
- We assume cups can be realistically divided among multiple guests, although this is not explicitly stated in the requirements.
- We assume there is no dictator who can monopolize all the water and the guests are truly equal.
- We assume that all guests agree to divide the water equally after pouring two cups.
- We assume guests usually do not give away their shares; they consume whatever portion they receive.

Challenges Identified

- It’s difficult to ensure everyone drinks under all these dynamics.
- The problem resembles social scenarios where a few selfish actors reduce overall fairness.
- Seat changes and bad guests decrease the percentage of guests who get to drink.

Simulation Program Overview

- Guests start as good but may randomly change to bad or the opposite happens or stay the same.
- Bad guests may drink all or exceed their expected parts or drink their expected parts of the cups and move seats randomly each turn.
- This setup produces interesting data:
- For 14 guests, about 38.5% drink in 1000 simulations.
- For 7 guests, about 54.7% drink in 1000 simulations.
- These percentages are lower than ideal and need improvement.

Implemented Improvements

- Assumed guests do not change seats in some scenarios.
- Introduced a ban system: guests who drink all or exceed their expected share or drink in his second time are banned.
- Banned guests no longer get to drink.
- Guests mutually monitor and report cheaters, enforcing fairness.
- Smart cheaters who try to cheat by drinking once and changing seats get detected in the second drink and banned immediately.
- This system increased drinking percentages significantly:

| Scenario | Percentage Drinking (14 guests)|
|----------------------------|--------------------------------|
| No ban, no seat changes | 61.9% |
| No ban, with seat changes | 38.5% |
| Ban, no seat changes | 61.1% |
| Ban, with seat changes | 43.0% |

| Scenario | Percentage Drinking (7 guests) |
|----------------------------|--------------------------------|
| No ban, no seat changes | 66.3% |
| No ban, with seat changes | 54.7% |
| Ban, no seat changes | 67.2% |
| Ban, with seat changes | 58.8% |

Reflections and Analogy to Society

- The problem mirrors societal resource sharing, where “water” is like wealth or opportunities.
- Selfish actors (“bad guests”) hoard resources, reducing fairness.
- Ban systems resemble laws or accounting controls preventing exploiters from dominating.
- A balanced ban system helps more people access resources fairly.

In the graph_visualization folder, you'll find the results of 1000 simulations with varying numbers of guests.
In the program folder, you can find the program that I wrote.
If you have any questions about my approach or implementation, please feel free to ask - I'll respond immediately.

Closing Thoughts

I enjoyed working on this simulation overnight. It provides fascinating insights into social fairness and strategic behavior through a simple water-sharing problem. I look forward to improving the model further and welcome your feedback!


Conclusion
In ideal situations, where guests cooperate and share the cup fairly, and where there are always some good participants in the group, everyone can drink as intended. However, guest behavior can change based on what others do — some may become competitive or selfish, drinking more than their share or switching seats to drink again. This dynamic creates both a theoretical and practical challenge in maintaining fairness within the shared system.

From the simulations, results show that introducing clear rules and social enforcement mechanisms greatly improves fairness. In this system, every guest plays a role in detecting cheaters. If someone drinks all the water or more than their share, others can immediately declare it. A future improvement could include fairness conditions where if a good guest notices another cheating but fails to report it, that observer is also penalized or banned. This addition would strengthen honesty and accountability within the simulation.

For smaller groups (N ≤ 14), where all guests can see each other, this detection system becomes more effective. Good participants can communicate, identify bad behavior quickly, and prevent cheaters from manipulating the system (for instance, drinking their share, changing places, and drinking again). Under these conditions, banning selfish or disruptive guests significantly increases fairness and raises the percentage of participants who successfully get to drink.

In conclusion, adding strict rules can increase the number of guests who get to drink water. However, since there is always a high probability that some guests will act selfishly and disrupt fairness, the percentage can improve but will never reach 100% — unless every guest remains good and never changes their mindset to become bad.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions solutions/program/avg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function avg(numbers) {
if (numbers.length === 0) {
return 0;
}
let sum = 0;
for (let i = 0; i < numbers.length; i++) {
sum += numbers[i];
}
return sum / numbers.length;
}

module.exports = avg ;
20 changes: 20 additions & 0 deletions solutions/program/changeMind.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function changeMind(guests, nbrGst) {
const rand = Math.random()
if (rand > 0.2 && guests[0].type === "good") {
guests[0].type = 'bad';
guests[0].mind = Math.random() < 0.5 ? "all" : "share";
} else if (rand > 0.8 && guests[0].type === "bad" ) {
guests[0].type = 'good';
delete guests[0].mind;
}

if (rand > 0.2 && guests[nbrGst - 1].type === "good") {
guests[nbrGst - 1].type = 'bad';
guests[nbrGst - 1].mind = Math.random() < 0.5 ? "all" : "share";
} else if (rand > 0.8 && guests[nbrGst - 1].type === "bad") {
guests[nbrGst - 1].type = 'good';
delete guests[nbrGst - 1].mind;
}
}

module.exports = changeMind ;
148 changes: 148 additions & 0 deletions solutions/program/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
const avg = require('./avg');
const changeMind = require('./changeMind');
const randomInt = require('./randomInt');
const shuffleBadGuest = require('./shuffleBadGuest');


function myfnc(nbrGst, simulationTime, banSys, badSwitch ) {
const simulationData = []
let simulationTotalDrink = 0

for (let i = 0; i < simulationTime; i++) {
let countGestDrink = 0
let guests = [];

for (let j = 1; j <= nbrGst; j++) {
guests.push({ id: j, type: 'good', drink: 0 });
}

let l = 0;
let r = nbrGst - 1;

while (l < nbrGst || r >= 0) {
changeMind(guests, nbrGst);

if (l < nbrGst) {
if (banSys && guests[l].banned) {

if(badSwitch){
for (let i = l ; i < nbrGst ; i++) {
if (!guests[i].banned) {
guests[i].drink += 1
l++;
break
}
}
l++;
}else{
for (let i = l ; i < nbrGst ; i++) {
if (!guests[i].banned) {
guests[i].drink += 1
l = i ;
break
}
}
l++;
}
} else if (guests[l].type === "good") {
guests[l].drink += 1;
if (guests[l].drink > 1) {
guests[l].banned = true;
l++;
} else {
l++;
}
} else if (guests[l].type === "bad") {
if (guests[l].mind === "all") {
guests[l].drink += (nbrGst - l);
if (banSys) guests[l].banned = true;
l = nbrGst;
} else {
const badDrink = randomInt(l, nbrGst - 1);
guests[l].drink += (badDrink - l + 1);
if (banSys && (badDrink - l + 1 > 1)) {
guests[l].banned = true;
}
l = badDrink + 1;
}
}
}

if (r >= 0) {
if (banSys && guests[r].banned) {

if(badSwitch){
for (let i = r ; i >= 0 ; i--) {
if (!guests[i].banned) {
guests[i].drink += 1
r--;
break
}
}
r--;
}else{
for (let i = r ; i >= 0 ; i--) {
if (!guests[i].banned) {
guests[i].drink += 1
r = i ;
break
}
}
r--;
}


} else if (guests[r].type === "good") {
guests[r].drink += 1;
if (guests[r].drink > 1) {
guests[r].banned = true;
r--;
} else {
r--;
}
} else if (guests[r].type === "bad") {
if (guests[r].mind === "all") {
guests[r].drink += (r + 1);
if (banSys) guests[r].banned = true;
r = -1;
} else {
const badDrink = randomInt(1, r);
guests[r].drink += (r - badDrink + 1);
if (banSys && (r - badDrink + 1 > 1)) {
guests[r].banned = true;
}
r = badDrink - 1;
}
}
}

if (badSwitch){
guests = shuffleBadGuest(guests);

}

}

for (let j = 0; j < nbrGst; j++) {
if (guests[j].drink > 0) {
countGestDrink++
}
}
simulationData.push((countGestDrink / nbrGst) * 100)
simulationTotalDrink += countGestDrink;
}
return (simulationTotalDrink / (simulationTime * nbrGst)) * 100;
}

let obj = { 0 : [], 1 : [],2 : [],3 : []}
for(let i = 0 ; i<10; i++){
obj[0].push(myfnc(14, 1000,false,false))
obj[1].push(myfnc(14, 1000,false,true))
obj[2].push(myfnc(14, 1000,true,false))
obj[3].push(myfnc(14, 1000,true,true))
}

console.log("no ban sys no badSwitch : ", avg(obj[0]));
console.log("no ban sys badSwitch : ", avg(obj[1]));
console.log("ban sys no badSwitch : ", avg(obj[2]));
console.log("ban sys badSwitch : ", avg(obj[3]));
5 changes: 5 additions & 0 deletions solutions/program/randomInt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function randomInt(n, m) {
return Math.floor(Math.random() * (m - n + 1)) + n;
}

module.exports = randomInt ;
21 changes: 21 additions & 0 deletions solutions/program/shuffleBadGuest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function shuffleBadGuest(array) {
const result = [];
const badElements = [];

array.forEach(item => {
if (item.type === "good") {
result.push(item);
} else {
badElements.push(item);
}
});

badElements.forEach(badElement => {
const randomPosition = Math.floor(Math.random() * (result.length + 1));
result.splice(randomPosition, 0, badElement);
});

return result;
}

module.exports = shuffleBadGuest ;