Partition function P: Difference between revisions
Content added Content deleted
(→{{header|Python}}: Timings) |
(→{{header|Python}}: Mathloger video prime generator) |
||
Line 281: | Line 281: | ||
Out[2]: 193655306161707661080005073394486091998480950338405932486880600467114423441282418165863 |
Out[2]: 193655306161707661080005073394486091998480950338405932486880600467114423441282418165863 |
||
</pre> |
</pre> |
||
===Python: Mathloger video prime generator=== |
|||
Add the following code after that above |
|||
<lang python>def par_primes(): |
|||
"Prime number generator from the partition machine" |
|||
p = [1] |
|||
p_m = plus_minus() |
|||
mods = [] |
|||
n = 0 |
|||
while True: |
|||
n += 1 |
|||
next_plus_minus = next(p_m) |
|||
if next_plus_minus: |
|||
mods.append(next_plus_minus) |
|||
p.append(sum(p[offset] * sign for offset, sign in mods)) |
|||
if p[0] + 1 == p[-1]: |
|||
yield p[0] |
|||
p[0] += 1 |
|||
yield p |
|||
print("\nPrimes:", list(islice(par_primes(), 15)))</lang> |
|||
{{Out}} |
|||
<pre>Primes: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]</pre> |
|||
=={{header|REXX}}== |
=={{header|REXX}}== |