Package net.n1da.dev.euler
Class PE0024
- java.lang.Object
-
- net.n1da.dev.euler.core.Problem
-
- net.n1da.dev.euler.PE0024
-
- All Implemented Interfaces:
Solvable
public class PE0024 extends Problem
Solution for problem 24 "Lexicographic permutations" completed on Mon, 29 Jun 2015, 19:46.- Since:
- 14.04.2015 05:23:47
- Author:
- Nico Danneberg
- See Also:
- Problem @ Project Euler, Solution @ Ni-Da-Net
-
-
Field Summary
Fields Modifier and Type Field Description private int[]
factorials
Memory for all necessary permutations.private java.lang.String
line
Stores the line of chars to permute.private int
place
Stores which permutation is wanted.
-
Method Summary
Modifier and Type Method Description void
prepare()
java.lang.String
solve()
This method solves the given problem by running over thefactorials
array to find the right positions to swap the characters.private java.lang.String
swapChar(java.lang.String text, int oPos, int nPos)
Swaps the character at given old to the new position.-
Methods inherited from class net.n1da.dev.euler.core.Problem
finish, getResult, getRuntime, toString
-
-
-
-
Method Detail
-
prepare
public void prepare()
Prepares the solution of this problem by setting theline
andplace
. Additionally thefactorials
array is filled matching the length of the characterline
.
-
solve
public java.lang.String solve()
This method solves the given problem by running over thefactorials
array to find the right positions to swap the characters.- Returns:
- the one millions permutation of the given characters
- See Also:
swapChar(String, int, int)
-
swapChar
private java.lang.String swapChar(java.lang.String text, int oPos, int nPos)
Swaps the character at given old to the new position. All chars following are moved to the right (or left).- Parameters:
text
- the line of characters to be changedoPos
- the old position of the charnPos
- the new position of the char- Returns:
- the changed line of characters
-
-