Sailors, coconuts and a monkey problem: Difference between revisions

no edit summary
mNo edit summary
No edit summary
Line 1,273:
sailors=8 coconuts=117440505 share=5044200
sailors=9 coconuts=387420481 share=14913080
</pre>
 
=={{header|Ring}}==
<lang ring>
# Project : Sailors, coconuts and a monkey problem
# Date : 2018/02/16
# Author : Gal Zsolt (~ CalmoSoft ~)
# Email : <calmosoft@gmail.com>
 
scm(5)
scm(6)
 
func scm(sailors)
sm1 = sailors-1
if sm1 = 0
m = sailors
else
for n=sailors to 1000000000 step sailors
m = n
for j=1 to sailors
if m % sm1 != 0
m = 0
exit
ok
m = sailors*m/sm1+1
next
if m != 0
exit
ok
next
ok
see "Solution with " + sailors + " sailors: " + m + nl
for i=1 to sailors
m = m - 1
m = m / sailors
see "Sailor " + i + " takes " + m + " giving 1 to the monkey and leaving " + m*sm1 + nl
m = m * sm1
next
see "In the morning each sailor gets " + m/sailors + " nuts" + nl + nl
</lang>
Output:
<pre>
Solution with 5 sailors: 3121
Sailor 1 takes 624 giving 1 to the monkey and leaving 2496
Sailor 2 takes 499 giving 1 to the monkey and leaving 1996
Sailor 3 takes 399 giving 1 to the monkey and leaving 1596
Sailor 4 takes 319 giving 1 to the monkey and leaving 1276
Sailor 5 takes 255 giving 1 to the monkey and leaving 1020
In the morning each sailor gets 204 nuts
 
Solution with 6 sailors: 233275
Sailor 1 takes 38879 giving 1 to the monkey and leaving 194395
Sailor 2 takes 32399 giving 1 to the monkey and leaving 161995
Sailor 3 takes 26999 giving 1 to the monkey and leaving 134995
Sailor 4 takes 22499 giving 1 to the monkey and leaving 112495
Sailor 5 takes 18749 giving 1 to the monkey and leaving 93745
Sailor 6 takes 15624 giving 1 to the monkey and leaving 78120
In the morning each sailor gets 13020 nuts
</pre>
 
2,468

edits