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