This solution is outdated. To rescore this solution, sign in.
-
1 Comment
John D'Errico
on 30 Jun 2016
While the obvious solution is y = sum(1:2^x), that will fail miserably for x = 50. So the alternative is a looping solution, that generates the sum more intelligently. Here, the looping is done simply using recursion. In fact, we can even compute the exact sum for x =100, a problem that would take the brute force solution the lifetime of the universe.
sum_int(sym(100))
ans =
803469022129495137770981046171215126561215611592144769253376
This done in fractions of a second, even for symbolic inputs.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!