Skip to content

Instantly share code, notes, and snippets.

@qaisjp
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qaisjp/8697613 to your computer and use it in GitHub Desktop.
Save qaisjp/8697613 to your computer and use it in GitHub Desktop.
A digital sum is the sum of all of the digits in a number so 214123 = 2+1+4+1+2+3 = 13 - The Tower of Hanoi puzzle involves moving disks in a certain order. What is digital sum of the number of required moves to solve 500000-disk Tower of Hanoi puzzle?
package demoproject;
import java.math.BigInteger;
public class blah {
public static void main(String[] args) {
BigInteger big = BigInteger.valueOf(2).pow(500000).subtract(BigInteger.ONE);
String[] num = big.toString().split("(?!^)");
int number = 0;
for (int i = 0; i < num.length; i++) {
number += Integer.parseInt(num[i]);
//System.out.println(number);
}
System.out.println("cake:"+number); // 677568
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment