Popular recipes by Giannis Fysakis http://code.activestate.com/recipes/users/4174072/2011-08-13T23:17:27-07:00ActiveState Code RecipesJosephus problem (Python)
2011-08-13T23:17:27-07:00Giannis Fysakishttp://code.activestate.com/recipes/users/4174072/http://code.activestate.com/recipes/577840-josephus-problem/
<p style="color: grey">
Python
recipe 577840
by <a href="/recipes/users/4174072/">Giannis Fysakis</a>
.
</p>
<p>In computer science and mathematics, the Josephus problem (or Josephus permutation) is a theoretical problem related to a certain counting-out game.</p>
<p>There are people standing in a circle waiting to be executed. After the first person is executed, certain number of people are skipped and one person is executed. Then again, people are skipped and a person is executed. The elimination proceeds around the circle (which is becoming smaller and smaller as the executed people are removed), until only the last person remains, who is given freedom.</p>
<p>The task is to choose the place in the initial circle so that you are the last one remaining and so survive.
If 2 are the number of people that are skipped</p>
Find Prime Numbers in python (Python)
2010-06-12T08:22:40-07:00Giannis Fysakishttp://code.activestate.com/recipes/users/4174072/http://code.activestate.com/recipes/577259-find-prime-numbers-in-python/
<p style="color: grey">
Python
recipe 577259
by <a href="/recipes/users/4174072/">Giannis Fysakis</a>
(<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/primality_testing/">primality_testing</a>, <a href="/recipes/tags/prime/">prime</a>, <a href="/recipes/tags/primes/">primes</a>, <a href="/recipes/tags/prime_generator/">prime_generator</a>, <a href="/recipes/tags/prime_number/">prime_number</a>).
Revision 2.
</p>
<p>The algorithm is based on the idea <br />
that the next larger prime after one prime is the sum of the two smaller previous minus three prime numbers back.
For the first five prime numbers 2,3,5,7,11 this pattern is not true also it is not true if the number is a composite number (including of course if the number's square root is integer). </p>
<p>Example
trying to find the tenth prime</p>
<p>so lets play with numbers 17(minus 3 from Next,position 7), 19(minus 2 from Next,position 8), 23(minus 1 from Next,position 9) and number Next at position 10 :</p>
<p>hmmm ... if we add 19 and 23 we get 42, but 42 minus 17 equals 25 which isn't a prime :(</p>
<p>In order to correct this we assume that 25 is the next prime number ( temporary holding the tenth position)
finally to get the real Next prime number we take 23 + 25 = 48 , we subtract 19 and we get 29 which finally it takes the tenth position ( because it deserves it :P)</p>
Flatten a list (Python)
2010-06-18T03:45:20-07:00Giannis Fysakishttp://code.activestate.com/recipes/users/4174072/http://code.activestate.com/recipes/577250-flatten-a-list/
<p style="color: grey">
Python
recipe 577250
by <a href="/recipes/users/4174072/">Giannis Fysakis</a>
(<a href="/recipes/tags/flatten/">flatten</a>, <a href="/recipes/tags/list/">list</a>).
Revision 3.
</p>
<p>Flatten a list </p>