Skip to content

Instantly share code, notes, and snippets.

@bsimpson
Created June 11, 2014 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bsimpson/1fabe407f6c2ccf2e07e to your computer and use it in GitHub Desktop.
Save bsimpson/1fabe407f6c2ccf2e07e to your computer and use it in GitHub Desktop.
A hungry bloke staggering through the desert finds two Bedouins, and asks if he can share bread with them.
The tall Bedouin has 5 loaves, the short Bedouin has 3 loaves of bread.
They welcome the visitor, and the three of them consume the 8 loaves of bread.
The stranger thanks the Bedouins for their hospitality, and leaves them with 8 gold coins.
The tall Bedouin takes 5 coins, leaving three.
But the short Bedouin says they both shared their bread, and therefore should split the 8 coins four and four.
Question:
Which if either of the two Bedouins is right?
@rstawarz
Copy link

each_consumed = 8.0 / 3

tall_gave = 5 - each_consumed
short_gave = 3 - each_consumed

total_given = tall_gave + short_gave

tall_percent = tall_gave / total_given

tall_receives = tall_percent * 8
short_receives = (1 - tall_percent) * 8

puts "The Tall bedouin should receive #{tall_receives.to_i} gold coins"
puts "The short bedouin should receive #{short_receives.to_i} gold coin"

The Tall bedouin should receive 7 gold coins
The short bedouin should receive 1 gold coin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment