Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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.
Which if either of the two Bedouins is right?

This comment has been minimized.

Copy link

rstawarz commented Jun 11, 2014

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
You can’t perform that action at this time.