Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #24310

Re: Java 8 Streams and Eratosthenes

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.albasani.net!.POSTED!not-for-mail
From Sebastian <news@seyweiler.dyndns.org>
Newsgroups comp.lang.java.programmer
Subject Re: Java 8 Streams and Eratosthenes
Date Wed, 05 Jun 2013 21:32:25 +0200
Organization albasani.net
Lines 46
Message-ID <koo3o1$vg4$1@news.albasani.net> (permalink)
References <kolnme$g3e$1@news.albasani.net> <kom07e$lcs$1@dont-email.me> <komo7f$4ao$1@news.albasani.net> <konpmn$24r$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 8bit
X-Trace news.albasani.net 3IUhlRXSJY0OFYpoptCIn6rCmvF0+7pd8xnWZmth35U0o30/f4Bgl4xzodYpTVeSW22c7sdZsY2hrqhWrDepIw==
NNTP-Posting-Date Wed, 5 Jun 2013 19:32:17 +0000 (UTC)
Injection-Info news.albasani.net; logging-data="m5s9nYuXOqY74791cROY3XxfYvbSXa+wK5UwSkKZlgGwjDqVS++RVguNv6C6xMJMngmGABp6h/LRH/ggrVqTvd6c1m03z+fZZA9w71/tlk3viNUGkf75e0VuU239RsMK"; mail-complaints-to="abuse@albasani.net"
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9
In-Reply-To <konpmn$24r$1@dont-email.me>
Cancel-Lock sha1:MA4H0Q+drMBVKC9WqbHqDoiGAiY=
Xref csiph.com comp.lang.java.programmer:24310

Show key headers only | View raw


Am 05.06.2013 18:45, schrieb markspace:
> 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.
>
>
Well, yes, the algorithm doesn't work like that - it's not really a 
sieve, it's a version of trial division (cf. the Melissa E. O’Neil:
reference in one of my other posts) which checks the primality of x by
testing its divisibility by each of the primes less than x. There is
no actual crossing off or sieving out going on.

If you're interested in Java 8 stream filters, just get NetBeans or
IntelliJ Idea plus the JDK from http://jdk8.java.net/lambda/
and start experimenting.

-- Sebastian

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Java 8 Streams and Eratosthenes Sebastian <news@seyweiler.dyndns.org> - 2013-06-04 23:54 +0200
  Re: Java 8 Streams and Eratosthenes Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-06-04 19:35 -0300
    Re: Java 8 Streams and Eratosthenes Sebastian <news@seyweiler.dyndns.org> - 2013-06-05 09:03 +0200
      Re: Java 8 Streams and Eratosthenes Sebastian <news@seyweiler.dyndns.org> - 2013-06-05 09:44 +0200
        Re: Java 8 Streams and Eratosthenes Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-06-05 17:43 -0300
          Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) Sebastian <news@seyweiler.dyndns.org> - 2013-06-10 01:27 +0200
            Re: Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-06-09 22:28 -0300
              Re: Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) Sebastian <news@seyweiler.dyndns.org> - 2013-06-10 19:43 +0200
                Re: Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) markspace <markspace@nospam.nospam> - 2013-06-10 13:18 -0700
                Re: Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) Sebastian <news@seyweiler.dyndns.org> - 2013-06-11 23:27 +0200
                Re: Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) Sebastian <news@seyweiler.dyndns.org> - 2013-06-12 10:32 +0200
                Re: Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) Sebastian <news@seyweiler.dyndns.org> - 2013-06-12 14:37 +0200
                Re: Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) markspace <markspace@nospam.nospam> - 2013-06-12 12:05 -0700
                Re: Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) Sebastian <news@seyweiler.dyndns.org> - 2013-06-12 22:53 +0200
                Re: Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) markspace <markspace@nospam.nospam> - 2013-06-15 15:18 -0700
                Re: Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) Sebastian <news@seyweiler.dyndns.org> - 2013-06-16 22:52 +0200
                Re: Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-06-16 21:56 -0300
                Re: Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) Sebastian <news@seyweiler.dyndns.org> - 2013-06-18 23:18 +0200
  Re: Java 8 Streams and Eratosthenes markspace <markspace@nospam.nospam> - 2013-06-04 17:24 -0700
    Re: Java 8 Streams and Eratosthenes Sebastian <news@seyweiler.dyndns.org> - 2013-06-05 09:09 +0200
      Re: Java 8 Streams and Eratosthenes markspace <markspace@nospam.nospam> - 2013-06-05 09:45 -0700
        Re: Java 8 Streams and Eratosthenes Sebastian <news@seyweiler.dyndns.org> - 2013-06-05 21:32 +0200
    Re: Java 8 Streams and Eratosthenes Sebastian <news@seyweiler.dyndns.org> - 2013-06-05 09:47 +0200

csiph-web