Created
January 25, 2016 04:27
-
-
Save arnabmitra/31f3efcdf017b1541db2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.stream.IntStream; | |
import java.util.stream.Stream; | |
/** | |
* Created by amitra on 1/24/16. | |
*/ | |
public class Sample { | |
public static boolean isPrime(int n) | |
{ | |
return n >1 && IntStream.range(2,n).noneMatch(i -> n % i ==0); | |
} | |
public static Double sumOfPrimeFunctional(int number,int sequence) | |
{ | |
return Stream | |
.iterate(number,e -> e+1) | |
.filter(x -> isPrime(x)) | |
.limit(sequence) | |
.map(Math::sqrt) | |
.reduce(0.0,Double::sum); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment