Package net.n1da.dev.euler
Class PE0014
- java.lang.Object
-
- net.n1da.dev.euler.core.Problem
-
- net.n1da.dev.euler.PE0014
-
- All Implemented Interfaces:
Solvable
public class PE0014 extends Problem
Solution for problem 14 "Longest Collatz sequence" completed on Tue, 28 Apr 2015, 19:52.- Since:
- 25.04.2015 12:45:21
- Author:
- Nico Danneberg
- See Also:
- Problem @ Project Euler, Solution @ Ni-Da-Net
-
-
Method Summary
Modifier and Type Method Description private int
getCount(long num)
Retrieves the count of elements in the Collatz series with the given number as starting element.void
prepare()
Thecache
is created with 1.000.000 cells and initialized at the first three places: [0]=0, [1]=1, [2]=2.java.lang.String
solve()
Runs a loop from 2 to 1.000.000 to find the maximum number of elements in a Collatz series for every loop turn.-
Methods inherited from class net.n1da.dev.euler.core.Problem
finish, getResult, getRuntime, toString
-
-
-
-
Method Detail
-
prepare
public void prepare()
Thecache
is created with 1.000.000 cells and initialized at the first three places: [0]=0, [1]=1, [2]=2.
-
solve
public java.lang.String solve()
Runs a loop from 2 to 1.000.000 to find the maximum number of elements in a Collatz series for every loop turn.- Returns:
- the starting number for the maximum elements
- See Also:
getCount(long)
-
getCount
private int getCount(long num)
Retrieves the count of elements in the Collatz series with the given number as starting element. All elements found on the way to the final count are added onto thecache
.- Parameters:
num
- the starting number- Returns:
- the count of elements in the Collatz series
-
-