Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Executable-library/Java/executable-library-2.java
Normal file
20
Task/Executable-library/Java/executable-library-2.java
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class ExecutableLibrary {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Map<Integer,Integer> lengthMap = new HashMap<>();
|
||||
IntStream.range(1, 100_000)
|
||||
.map(n -> HailstoneSequence.hailstoneSequence(n).size())
|
||||
.forEach(len -> lengthMap.merge(len, 1, (v1, v2) -> v1 + v2));
|
||||
int mostOften = lengthMap.values()
|
||||
.stream()
|
||||
.mapToInt(x -> x)
|
||||
.max().orElse(-1);
|
||||
|
||||
System.out.printf("The most frequent hailstone length for n < 100,000 is %d.%n", mostOften);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue