Talk:Sailors, coconuts and a monkey problem: Difference between revisions

m
forced a TOC (for now).
No edit summary
m (forced a TOC (for now).)
 
(11 intermediate revisions by 3 users not shown)
Line 1:
__TOC__
 
== J ==
 
I smiled at that end comment, but there may be an issue with the choice of an end value to search over. It seems that unlike testing incrementing values you have to put a ceiling on the range searched for.
 
Line 6 ⟶ 9:
 
I do have to put in a ceiling - that gives me bound search time and protects me from "infinite loop" bugs while I'm playing with the code. But if a given value doesn't give me good results, it's trivial for me to multiply it by 10 and try again. I guess what I'm saying is that for this problem, this approach saved time for me. (But I guess you basically said this already, in your second paragraph.) --[[User:Rdm|Rdm]] ([[User talk:Rdm|talk]]) 11:55, 3 May 2015 (UTC)
 
 
== Analysis ==
 
Let the solution be described by:
<pre>
 
n6 g6
n5 g5
Line 17 ⟶ 21:
n2 g2
n1 g1
</pre>
 
where n is the number of coconuts at each stage and g is the number of coconuts in each pile.
 
note that g1 is n1/5 and g2*4, which implies that n1 is divisible by 20. It is simple to calculate the entire table given n1. It is obvious that n1 is of the form X + (4*5)*2*(2*)*(2*2)*(2*2*2*2) or 5120. X is divisible by 20 and less than 5120. Which implies that J's maximum value is justified if over generous. By examination X must be a member of the series 20 + 40*z. Let us look at that:
<pre>
 
20 26 33.5 42.875
60 76 96 121
Line 34 ⟶ 38:
420 526 658.5 824.125
460 576 721 902.25
</pre>
 
By examining the 4th column we can see that when the step is 320 ((4*5)*2*(2*)*(2*2) X is 60. So X must be a member of the series 60 + 320*z. Let us look at that:
<pre>
 
60 76 96 121 152.25 191.3125
380 476 596 746 933.5 1167.875
Line 86 ⟶ 90:
15100 18876 23596 29496 36871 46089.75
15420 19276 24096 30121 37652.25 47066.3125
</pre>
 
Examination of the final column we see that for the step of 5120 "(4*5)*2*(2*)*(2*2)*(2*2*2*2)" X is 1020.
 
--[[User:Nigel Galloway|Nigel Galloway]] ([[User talk:Nigel Galloway|talk]]) 09:44, 5 May 2015 (UTC)
 
 
==Haskell version==
 
Testing the Haskell version here with GHC 7.8.4 and finding that ''pure'' is out of scope.
 
Perhaps add '''Control.Applicative''' to the imports ? [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 19:04, 28 October 2015 (UTC)