

package ca.marvinp.projecteuler.solutions;

import ca.marvinp.projecteuler.misc.Timer;
import ca.marvinp.projecteuler.misc.Constants;
import java.math.BigInteger;



public class P16 {

  private Timer timer;
  private String answer;


  public P16() {
    int exponent = 1000;
    BigInteger base = BigInteger.valueOf(2);

    timer = new Timer();
    timer.start();

    BigInteger value = base.pow(exponent);
    String sVal = value.toString();

    BigInteger sum = BigInteger.ZERO;
    for (int i=0;i<sVal.length();i++) {
      int s = Integer.parseInt(Character.toString(sVal.charAt(i)));
      sum = sum.add(BigInteger.valueOf(s));
    }

    timer.stop();
    answer = sum.toString();
  }



  public String getAnswer() {
    StringBuilder sb = new StringBuilder();
    sb.append("Answer: The sum is: ");
    sb.append(answer +""+ Constants.NEWLINE);
    sb.append(timer.getElapsedTime());
    return sb.toString();
  }


  public String getQuestion() {
    StringBuilder sb = new StringBuilder();
    sb.append("URL: https://projecteuler.net/problem=16" + Constants.NEWLINE);
    sb.append("What is the sum of the digits of the number 2^1000 ?");
    return sb.toString();
  }

}

