Zarr Bin Hobeish relates this story.
Two travellers sat together on the way to their destination to have a meal. One had five loaves of bread. The other had three. A third traveller was passing by and at the request of the two joined in the meal.
The travellers cut each of the loaf of bread in three equal parts. Each of the travellers ate eight broken pieces of the loaf.
At the time of leaving the third traveller took out eight dirhams and gave to the first two men who had offered him the meal, and went away. On receiving the money the two travellers started quarrelling as to who should have how much of the money.
The five-loaf-man demanded five dirharns. The three-loaf-man insisted on dividing the money in two equal parts.
The dispute was brought to Imam Ali lbn Abi Talib (the Caliph of the time in Arabia) to be decided.
Imam Ali (a) requested the three-loaf-man to accept three dirhams. The man refused and said that he would take only four dirhams. At this Imam Ali (a) returned, “You can have only one dirham. You had eight loaves between yourselves. each loaf was broken in three parts. Therefore, you had 24 equal parts. Your three loaves made nine parts out of which you have eaten eight portions, leaving just one to the third traveller. Your friend had five loaves which divided into three made fifteen pieces. He ate eight pieces and gave seven pieces to the guest. As such the guest shared one part from your loaves and seven from those of your friend. So you should get one dirham and your friend should receive seven dirhams.