Skip to content

Conversation

kastyan-kg
Copy link
Contributor

prime numbers generation optimization suggestion

@kastyan-kg kastyan-kg changed the base branch from main to completed October 11, 2021 15:55
@@ -25,8 +28,8 @@ private PrimeNumbers() {
* @return an infinite int stream of prime numbers
*/
public static IntStream stream() {
return IntStream.iterate(2, i -> i + 1)
.filter(PrimeNumbers::isPrime);
return Stream.iterate(TWO, BigInteger::nextProbablePrime)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kastyan-kg that's a good option. 👍 However, this exercise is about Stream API, iteration, and ranges. So I would still encourage people to implement isPrime manually. What do you think about that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough ;) just was thinking how to do this faster

@tboychuk
Copy link
Contributor

Thanks!

@tboychuk tboychuk closed this Oct 13, 2021
@tboychuk tboychuk deleted the completed-fun-prime-update branch October 13, 2021 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants