Last active
August 29, 2015 13:55
-
-
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?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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