YAPC::EU 2018 Glasgow Update!
This commit is contained in:
parent
22f33d4004
commit
4e2d22a71d
1170 changed files with 15042 additions and 3047 deletions
|
|
@ -1,40 +1,37 @@
|
|||
import static java.lang.System.out;
|
||||
|
||||
import static java.util.Arrays.stream;
|
||||
import static java.util.Comparator.comparing;
|
||||
|
||||
public interface ParallelCalculations {
|
||||
public static final long[] NUMBERS = {
|
||||
12757923,
|
||||
12878611,
|
||||
12878893,
|
||||
12757923,
|
||||
15808973,
|
||||
15780709,
|
||||
197622519
|
||||
};
|
||||
public static final long[] NUMBERS = {
|
||||
12757923,
|
||||
12878611,
|
||||
12878893,
|
||||
12757923,
|
||||
15808973,
|
||||
15780709,
|
||||
197622519
|
||||
};
|
||||
|
||||
public static void main(String... arguments) {
|
||||
stream(NUMBERS)
|
||||
.unordered()
|
||||
.parallel()
|
||||
.mapToObj(ParallelCalculations::minimalPrimeFactor)
|
||||
.max(comparing(a -> a[0]))
|
||||
.ifPresent(res -> out.printf(
|
||||
"%d has the largest minimum prime factor: %d%n",
|
||||
res[1],
|
||||
res[0]
|
||||
))
|
||||
;
|
||||
}
|
||||
public static void main(String... arguments) {
|
||||
stream(NUMBERS)
|
||||
.unordered()
|
||||
.parallel()
|
||||
.mapToObj(ParallelCalculations::minimalPrimeFactor)
|
||||
.max(comparing(a -> a[0]))
|
||||
.ifPresent(res -> out.printf(
|
||||
"%d has the largest minimum prime factor: %d%n",
|
||||
res[1],
|
||||
res[0]
|
||||
));
|
||||
}
|
||||
|
||||
public static long[] minimalPrimeFactor(long n) {
|
||||
return iterate(2, i -> i + 1)
|
||||
.filter(i -> n >= i * i)
|
||||
.filter(i -> n % i == 0)
|
||||
.mapToObj(i -> new long[]{i, n})
|
||||
.findFirst()
|
||||
.orElseGet(() -> new long[]{n, n})
|
||||
;
|
||||
}
|
||||
public static long[] minimalPrimeFactor(long n) {
|
||||
for (long i = 2; n >= i * i; i++) {
|
||||
if (n % i == 0) {
|
||||
return new long[]{i, n};
|
||||
}
|
||||
}
|
||||
return new long[]{n, n};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue