Class PE0014

    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) java.util.Hashtable<java.lang.Long,​java.lang.Integer> cache
      Stores the count of terms for every starting number.
    • Constructor Summary

      Constructors 
      Constructor Description
      PE0014()
      A simple constructor to set number and title.
    • 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()
      The cache 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 java.lang.Object

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

      • cache

        java.util.Hashtable<java.lang.Long,​java.lang.Integer> cache
        Stores the count of terms for every starting number.
    • Constructor Detail

      • PE0014

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

      • prepare

        public void prepare()
        The cache is created with 1.000.000 cells and initialized at the first three places: [0]=0, [1]=1, [2]=2.
        Specified by:
        prepare in interface Solvable
        Overrides:
        prepare in class Problem
      • 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 the cache.
        Parameters:
        num - the starting number
        Returns:
        the count of elements in the Collatz series