The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

undjask (13) [Avatar] Offline
#1
Hi,

The in text function partitionPrimes(100).get(true) and Listing 5.4 will result in the greatest prime being 101. This is due to the limit() function limiting the stream to the k first values (2 is first, 99 values remain, crawling through 99 values adding 1 to prev. end val. => 101).

I believe the intention was to list all the primes smaller or equal to n (if n is a prime it will be included). Therefore the output should stop at 97 for an input of 100.
Mario Fusco (2) [Avatar] Offline
#2
Re: Ch.5 p.129 V2 partitionPrimes()
You're right: since I stareted from 2 I should limit the Stream to n-1.
Nice catch!

Thanks,
Mario