Package net.n1da.dev.euler
Class PE0037
- java.lang.Object
-
- net.n1da.dev.euler.core.Problem
-
- net.n1da.dev.euler.PE0037
-
- All Implemented Interfaces:
Solvable
public class PE0037 extends Problem
Solution for problem 37 "Truncatable primes" completed on Mon, 14 Mar 2016, 20:06.- Since:
- 12.03.2016 07:38:47
- Author:
- Nico Danneberg
- See Also:
- Problem @ Project Euler, Solution @ Ni-Da-Net
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.ArrayList<java.lang.Integer>
candidates
List of all primes less that 1,000,000.
-
Method Summary
Modifier and Type Method Description void
prepare()
Just initializes the attributes and stores all primes less than 1,000,000 incandidates
if the do not start with 4, 6, or 8, and do not end with 0, 2, 4, 6, or 8.java.lang.String
solve()
Every candidate is proved by methodtest(int)
.private boolean
test(int num)
Truncates the given number from both sides and tests if the both new numbers are primes (are stored incandidates
).-
Methods inherited from class net.n1da.dev.euler.core.Problem
finish, getResult, getRuntime, toString
-
-
-
-
Method Detail
-
prepare
public void prepare()
Just initializes the attributes and stores all primes less than 1,000,000 incandidates
if the do not start with 4, 6, or 8, and do not end with 0, 2, 4, 6, or 8.
-
solve
public java.lang.String solve()
Every candidate is proved by methodtest(int)
. If it returns true and the number is greater zero it is summed to the searched result.- Returns:
- the sum of all primes that are tested true
-
test
private boolean test(int num)
Truncates the given number from both sides and tests if the both new numbers are primes (are stored incandidates
).- Parameters:
num
- the number to be tested- Returns:
- true if, and only if the number can be truncated from left and right and all resulting numbers are primes
-
-