Class PE0017

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Hashtable<java.lang.Integer,​java.lang.Integer> Cache
      Local cache for all found lengths.
      private java.util.Hashtable<java.lang.Integer,​java.lang.String> SpokenNumbers
      Stores the words for some basic numbers.
    • Constructor Summary

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

      Modifier and Type Method Description
      private int getLetterCount​(int num)
      Calculates the number of letters in the written version of the given number.
      void prepare()
      During preparation of this problem a list of words for number from 1 to 19, 20, 30, 40 ... 90, 100, and 1000 is created.
      java.lang.String solve()
      Runs a loop from 1 to 1000 to get the number of letters in the written version for every number.
      • Methods inherited from class java.lang.Object

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

      • Cache

        private java.util.Hashtable<java.lang.Integer,​java.lang.Integer> Cache
        Local cache for all found lengths.
      • SpokenNumbers

        private java.util.Hashtable<java.lang.Integer,​java.lang.String> SpokenNumbers
        Stores the words for some basic numbers.
    • Constructor Detail

      • PE0017

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

      • prepare

        public void prepare()
        During preparation of this problem a list of words for number from 1 to 19, 20, 30, 40 ... 90, 100, and 1000 is created.
        Specified by:
        prepare in interface Solvable
        Overrides:
        prepare in class Problem
      • solve

        public java.lang.String solve()
        Runs a loop from 1 to 1000 to get the number of letters in the written version for every number. The result for a number is stored on the local Cache to make the work a little quicker.
        Returns:
        the sum of all letters for every number from 1 to 1000
        See Also:
        getLetterCount(int)
      • getLetterCount

        private int getLetterCount​(int num)
        Calculates the number of letters in the written version of the given number. If a number is already stored on the local Cache this count is used.
        Parameters:
        num - the number to count the letters
        Returns:
        the number of letters