Sailors, coconuts and a monkey problem: Difference between revisions

Line 963:
Finally, each sailor takes 14913080
</pre>
 
=={{header|Lua}}==
{{trans|C}}
<lang lua>function valid(n,nuts)
local k = n
local i = 0
while k ~= 0 do
if (nuts % n) ~= 1 then
return false
end
k = k - 1
nuts = nuts - 1 - math.floor(nuts / n)
end
return nuts ~= 0 and (nuts % n == 0)
end
 
for n=2, 9 do
local x = 0
while not valid(n, x) do
x = x + 1
end
print(n..": "..x)
end</lang>
{{out}}
<pre>2: 11
3: 25
4: 765
5: 3121
6: 233275
7: 823537
8: 117440505
9: 387420481</pre>
 
=={{header|Modula-2}}==
1,452

edits