Class PE0008

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int[] counts
      The storage for the different step counts.
      private short[] digits
      The 1000 digits.
      private long[] products
      The storage for the different products.
      private int window
      The number of adjacent digits to find.
    • Constructor Summary

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

      Modifier and Type Method Description
      void prepare()
      Prepares the solving process by setting the wanted window size (13), initializing the storages and reading the 1000 digits from a file.
      private void resetStorages()
      Resets the local storages counts and products by setting all their values back to standard.
      java.lang.String solve()
      Solves this problem by running over every of the 1000 digits and multiplying it into the products array.
      • Methods inherited from class java.lang.Object

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

      • digits

        private short[] digits
        The 1000 digits.
      • window

        private int window
        The number of adjacent digits to find.
      • counts

        private int[] counts
        The storage for the different step counts.
      • products

        private long[] products
        The storage for the different products.
    • Constructor Detail

      • PE0008

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

      • prepare

        public void prepare()
        Prepares the solving process by setting the wanted window size (13), initializing the storages and reading the 1000 digits from a file.
        Specified by:
        prepare in interface Solvable
        Overrides:
        prepare in class Problem
        See Also:
        IO.readDigits(String, int)
      • solve

        public java.lang.String solve()
        Solves this problem by running over every of the 1000 digits and multiplying it into the products array. If the counts array at the same place is incremented and equal to the window size, a candidate to the maximum is found. If a zero is found both local storages are reseted.
        Returns:
        the largest product of adjacent digits
        See Also:
        resetStorages()
      • resetStorages

        private void resetStorages()
        Resets the local storages counts and products by setting all their values back to standard.