Popular recipes tagged "mathematical"http://code.activestate.com/recipes/tags/mathematical/popular/2011-02-02T12:50:58-08:00ActiveState Code Recipesinterleave bits (aka morton-ize aka z-order curve) (Python) 2011-02-02T12:50:58-08:00Romain Dartigueshttp://code.activestate.com/recipes/users/4167472/http://code.activestate.com/recipes/577558-interleave-bits-aka-morton-ize-aka-z-order-curve/ <p style="color: grey"> Python recipe 577558 by <a href="/recipes/users/4167472/">Romain Dartigues</a> (<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/bits/">bits</a>, <a href="/recipes/tags/manipulation/">manipulation</a>, <a href="/recipes/tags/mathematical/">mathematical</a>, <a href="/recipes/tags/mathematics/">mathematics</a>). </p> <p>This recipe let you encode in a single number two or three numbers.</p> <p>Note: this is only an adaptation of the recipes from <strong>Sean Eron Anderson</strong> and <strong>Fabian “ryg” Giesen</strong>; all credits goes to the respective authors.</p> <ul> <li><a href="http://graphics.stanford.edu/%7Eseander/bithacks.html#InterleaveBMN" rel="nofollow">http://graphics.stanford.edu/~seander/bithacks.html#InterleaveBMN</a></li> <li><a href="http://fgiesen.wordpress.com/2009/12/13/decoding-morton-codes/" rel="nofollow">http://fgiesen.wordpress.com/2009/12/13/decoding-morton-codes/</a></li> </ul> Martin Gardner's "The Monkey and the Coconuts" Problem (Python) 2010-07-26T16:32:08-07:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/577335-martin-gardners-the-monkey-and-the-coconuts-proble/ <p style="color: grey"> Python recipe 577335 by <a href="/recipes/users/4076953/">Jack Trainor</a> (<a href="/recipes/tags/martingardner/">martingardner</a>, <a href="/recipes/tags/mathematical/">mathematical</a>, <a href="/recipes/tags/puzzle/">puzzle</a>). </p> <p>Five sailors arrive at a deserted island that has only coconuts and one monkey. The sailors collect all the coconuts into one big pile and agree to divide up the coconuts into equal shares the next morning. However during the night each sailor wakes up one at a time afraid to trust the others and decides to take his share secretly. So each sailor takes 1/5 of the coconuts and hides it. Each time there is one coconut left over and the sailor gives that to the monkey. In the morning they divide what is left of the pile into equal shares and there is still one coconut left for the monkey.</p> <p>How many coconuts were in the original pile?</p>