Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail From: markspace Newsgroups: comp.lang.java.programmer Subject: Re: Java 8 Streams and Eratosthenes Date: Wed, 05 Jun 2013 09:45:28 -0700 Organization: A noiseless patient Spider Lines: 34 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 5 Jun 2013 16:40:55 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="fba3415ba68d85d643935af2f52f0b4b"; logging-data="2203"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+JS+dhFiStpeosZV12O7owfa3RdmCIjXI=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 In-Reply-To: Cancel-Lock: sha1:ZVoT86W7PFr07Xmg6H20gHG0/4A= Xref: csiph.com comp.lang.java.programmer:24307 On 6/5/2013 12:09 AM, Sebastian wrote: >> With streams, you have to account for the fact that the previous sieve >> has already removed a lot of values. (I assume; I'm no expert on Java >> lambdas.) How do you even do that? I don't know. > > that's taken care of by the chaining of the filters. One problem with How does that actually work though? I'm not familiar with the details of filters. For example if you have a stream of integers: 1 2 3 4 5 6 7 8 9 10 11 12 13... And you sieve out all the even ones after the first: 1 2 3 5 7 9 11 13... And then you try to sieve out all the multiples of 3 after the first: 1 2 3 5 7 9 11 13 15... ^ position '6' The position of the '6' in the sieve is shifted to be the actual number 9. I don't see how the sieve is going to work like that. It gets more obviously worse as you add more filters. 1 2 3 5 7 11 13 17 ... For example sieving '4' is going to remove 17 here, and that's not right, 17 is prime.