Given the number x, y must be the summation of all integers from 1 to 2^x. For instance if x=2 then y must be 1+2+3+4=10.
Carl Gauss's approach seems to be efficient for our brains but not for matlab
There are TWO problems with the way this problem is stated. Find them both!
Just go with your gut on this one.
John D'Errico wrote up some great commentary on this problem and how to go about solving it. http://blogs.mathworks.com/community/2016/07/21/numerical-analyst-john-derrico-takes-a-stroll-through-cody/
try to put to numbers in a range and sum them up
Additional test cases have been added.
Good one :)
very nice
easy easy
Gauss approves
fun solving :)
fun problem =/
Very nice problem for kids and adults alike.
Celentano's solution is efficacious.
That was fun :)
nice
(^-^)V
any math formula?
:)
This user (mohamed elbesealy) appears to have gamed the system, with fraudulent "likes" of this unremarkable solution submitted by 'sock-puppet' accounts. —DIV
hint:
sum of sequential series
1+2+.....n= n(n+1)/2
Of course, this solution use the formula from Carl Friedrich Gauss for the sum of the integers from 0 to n.
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.
try: y=sum(1:2^x). It will lead to shorter solution.
not sure why this is wrong.
Upper limit must be 2^n, according to the problem's title & Test Suite. (Not clear from the problem statement, though!)
I can't figure this out after 10+ tries. Someone please help? http://www.followthesteps.net/sky-contact-phone-number/
Colon notation is key.
How this solution is possible?
Ha ha !
This solution can accept arrays of integers as x input
This solution accepts arrays, avoids the explicite creation of 1:2^n and calculates the expensive power once only.
A good example of a solution that does well on Cody's size measure, but which I wouldn't use for serious purposes.
277 Solvers
432 Solvers
Basics: 'Find the eigenvalues of given matrix
237 Solvers
329 Solvers
371 Solvers