001package net.n1da.dev.euler;
002
003import net.n1da.dev.euler.core.*;
004import net.n1da.dev.euler.helper.*;
005
006/**
007 * Solution for problem 13
008 * "<strong>Large sum</strong>"
009 * completed on Fri, 24 Apr 2015, 20:39.
010 * 
011 * @author <a href="mailto:nico@danneberg.de">Nico Danneberg</a>
012 * @since 24.04.2015 20:28:55
013 * 
014 * @see <a href="https://projecteuler.net/problem=13" target="_blank">Problem @ Project Euler</a>
015 * @see <a href="http://n1da.net/specials/projekt-euler/problem-13-grosse-summe/" target="_top">Solution @ Ni-Da-Net</a>
016 */
017public class PE0013 extends Problem {
018
019        /**
020         * Stores the given 100 50-digit numbers.
021         */
022        private LargeNumber[] numbers;
023        
024        /**
025         * A simple constructor to set {@link Problem#number number}
026         * and {@link Problem#title title}.
027         */
028        public PE0013() {
029                super( 13, "Large sum" );
030        }
031
032        /**
033         * Just reads in the {@link #numbers} from the given file.
034         * 
035         * @see IO#readLargeNumbers(String, int)
036         */
037        @Override
038        public void prepare() {
039                super.prepare();
040                numbers = IO.readLargeNumbers( "data-files/100x50digits.txt", 100 );
041        }
042        
043        /**
044         * Just adds one {@link LargeNumber} to the next and finally returns
045         * the sum of all {@link #numbers}.
046         * 
047         * @return the complete sum of the 100 50-digits numbers
048         * @see LargeNumber
049         */
050        @Override
051        public String solve() {
052                LargeNumber sum = new LargeNumber();
053                
054                for( LargeNumber cur : numbers )
055                        sum = sum.add( cur );
056                
057                return sum.toString().substring( 0, 10 );
058        }
059}