Class PE0024

    • 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.
    • Constructor Summary

      Constructors 
      Constructor Description
      PE0024()
      A simple constructor to set number and title.
    • Method Summary

      Modifier and Type Method Description
      void prepare()
      Prepares the solution of this problem by setting the line and place.
      java.lang.String solve()
      This method solves the given problem by running over the factorials 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 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • line

        private java.lang.String line
        Stores the line of chars to permute.
      • place

        private int place
        Stores which permutation is wanted.
      • factorials

        private int[] factorials
        Memory for all necessary permutations.
    • Constructor Detail

      • PE0024

        public PE0024()
        A simple constructor to set number and title.
    • Method Detail

      • prepare

        public void prepare()
        Prepares the solution of this problem by setting the line and place. Additionally the factorials array is filled matching the length of the character line.
        Specified by:
        prepare in interface Solvable
        Overrides:
        prepare in class Problem
      • solve

        public java.lang.String solve()
        This method solves the given problem by running over the factorials 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 changed
        oPos - the old position of the char
        nPos - the new position of the char
        Returns:
        the changed line of characters