Sailors, coconuts and a monkey problem: Difference between revisions

Added 11l
m (use wiki markup for links)
(Added 11l)
Line 29:
* [[oeis:A002021|A002021: Pile of coconuts problem]] The On-Line Encyclopedia of Integer Sequences. (Although some of its references may use the alternate form of the tale).
<br><br>
=={{header|11l}}==
{{trans|Python}}
 
<lang 11l>F monkey_coconuts(sailors = 5)
V nuts = sailors
L
V n0 = nuts
[(Int, Int, Int)] wakes
L(sailor) 0..sailors
V (portion, remainder) = divmod(n0, sailors)
wakes.append((n0, portion, remainder))
I portion <= 0 | remainder != (I sailor != sailors {1} E 0)
nuts++
L.break
n0 = n0 - portion - remainder
L.was_no_break
R (nuts, wakes)
 
L(sailors) [5, 6]
V (nuts, wake_stats) = monkey_coconuts(sailors)
print("\nFor #. sailors the initial nut count is #.".format(sailors, nuts))
print("On each waking, the nut count, portion taken, and monkeys share are:\n "wake_stats.map(ws -> String(ws)).join(",\n "))</lang>
 
{{out}}
<pre>
 
For 5 sailors the initial nut count is 3121
On each waking, the nut count, portion taken, and monkeys share are:
(3121, 624, 1),
(2496, 499, 1),
(1996, 399, 1),
(1596, 319, 1),
(1276, 255, 1),
(1020, 204, 0)
 
For 6 sailors the initial nut count is 233275
On each waking, the nut count, portion taken, and monkeys share are:
(233275, 38879, 1),
(194395, 32399, 1),
(161995, 26999, 1),
(134995, 22499, 1),
(112495, 18749, 1),
(93745, 15624, 1),
(78120, 13020, 0)
</pre>
 
=={{header|AutoHotkey}}==
<lang AutoHotkey>loop, 2
1,480

edits