Download code

Jump to: navigation, search

Back to Sieve_of_Eratosthenes_(Python)

Download for Windows: zip

Download for UNIX: zip, tar.gz, tar.bz2

streams.py

 1 # The authors of this work have released all rights to it and placed it
 2 # in the public domain under the Creative Commons CC0 1.0 waiver
 3 # (http://creativecommons.org/publicdomain/zero/1.0/).
 4 # 
 5 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 # 
13 # Retrieved from: http://en.literateprograms.org/Sieve_of_Eratosthenes_(Python)?oldid=8411
14 
15 def streamfilter (pred, stream):
16     for i in stream:
17 	if pred(i):
18 	    yield i
19 
20 def ints(n):
21     while True:
22 	yield n
23 	n = n+1
24 


hijacker
hijacker
hijacker
hijacker

build.log

1 SyntaxError: ('invalid syntax', ('/tmp/litprog3921135/prime_sieve_streams.py', 15, 11, 'def primes:\n'))
2 


prime_sieve_streams.py

 1 # The authors of this work have released all rights to it and placed it
 2 # in the public domain under the Creative Commons CC0 1.0 waiver
 3 # (http://creativecommons.org/publicdomain/zero/1.0/).
 4 # 
 5 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 # 
13 # Retrieved from: http://en.literateprograms.org/Sieve_of_Eratosthenes_(Python)?oldid=8411
14 
15 def primes:
16     nums = ints(2)
17     while True:
18 	prime = nums.next()
19 	yield prime
20 	def curfilter(v, p=prime):
21 	    return ((v % p) != 0)
22 	nums = streamfilter (curfilter, ints)
23 


hijacker
hijacker
hijacker
hijacker