Package net.n1da.dev.euler
Class PE0061
- java.lang.Object
-
- net.n1da.dev.euler.core.Problem
-
- net.n1da.dev.euler.PE0061
-
- All Implemented Interfaces:
Solvable
public class PE0061 extends Problem
Solution for problem 61 "Cyclical figurate numbers" completed on Thu, 21 Mar 2019, 22:49.- Since:
- 06.05.2018 08:14:33
- Author:
- Nico Danneberg
- See Also:
- Problem @ Project Euler, Solution @ Ni-Da-Net
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Vector<java.util.ArrayList<java.lang.Integer>>
mem
Memory for all Triangle, Square, Pentagonal, Hexagonal, Heptagonal, and Octagonal numbers with 4 digits.
-
Method Summary
Modifier and Type Method Description private boolean
check(int a, int b)
Checks if the given numbers follow each other.private int
find()
Starts the recursion by testing every Triangle number.private int
find(int level, int used, int first, int current)
Tries to find a number that follows the given current number.void
prepare()
All 4 digit numbers are calculated and stored in thememory attribute
.java.lang.String
solve()
This method solves the problem bei callingfind()
method as starting point of recursion.-
Methods inherited from class net.n1da.dev.euler.core.Problem
finish, getResult, getRuntime, toString
-
-
-
-
Method Detail
-
prepare
public void prepare()
All 4 digit numbers are calculated and stored in thememory attribute
.
-
solve
public java.lang.String solve()
This method solves the problem bei callingfind()
method as starting point of recursion.- Returns:
- sum of the found six cyclic numbers
-
find
private int find()
Starts the recursion by testing every Triangle number.- Returns:
- the found sum of the six cyclic numbers
-
find
private int find(int level, int used, int first, int current)
Tries to find a number that follows the given current number. If it finds such a number it calls itself recursively with a higher level. If level 6 is reached it checks if the current number can have the first number as follower.- Parameters:
level
- the current levelused
- a binary number that stores all used figurate levelsfirst
- the very first number (a Triangle)current
- the current number- Returns:
- the sum of all cyclic number to the current level
-
check
private boolean check(int a, int b)
Checks if the given numbers follow each other.- Parameters:
a
- the previous numberb
- the follower- Returns:
- true if the last two digits of a are equal to the first two digits of b
-
-