2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.

What is the sum of the digits of the number 2^1000?

Project Euler Problem 16

Let’s write a general purpose solver for this problem:

function parseARGS()
        if isempty(ARGS)
                base::BigInt = 2;
                power::BigInt = 1000;
        else
                base = tryparse(BigInt, ARGS[1])
                power = tryparse(BigInt, ARGS[2])
        end
        return base,power
end


function main()
        base,power = parseARGS();
        sumOfDigits = sum(digits(base^power));
        println(sumOfDigits);
end

main()
$ julia ProjectEuler0016.jl 2 15
26

$ julia ProjectEuler0016.jl 2 100
115

$ julia ProjectEuler0016.jl 2 1000
1366

$ julia ProjectEuler0016.jl 2 10000
13561

$ julia ProjectEuler0016.jl 3 10
27

$ julia ProjectEuler0016.jl 5 10
40

Well, that was easy ;).