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.

Show
2 older comments

Dimitris Kaliakmanis
on 11 Feb 2012

Carl Gauss's approach seems to be efficient for our brains but not for matlab

William Smith
on 25 Sep 2012

There are TWO problems with the way this problem is stated. Find them both!

Alexander Wickstrom
on 11 Jun 2015

Just go with your gut on this one.

Ned Gulley
on 21 Jul 2016

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/

Muhammad M Sahari
on 20 Dec 2016

try to put to numbers in a range and sum them up

1 Comment

TAYALAN SIVALINGAM
on 29 Dec 2016

nice

1 player likes this solution

2 Comments

Yoshimasa Nakatani
on 25 Dec 2016

(^-^)V

Noriko Hounoki
on 3 Jan 2017

any math formula?

1 Comment

sim yoke meng
on 21 Dec 2016

:)

1 Comment

Mehdi
on 1 Sep 2016

hint:
sum of sequential series
1+2+.....n= n(n+1)/2

1 Comment

John D'Errico
on 30 Jun 2016

Of course, this solution use the formula from Carl Friedrich Gauss for the sum of the integers from 0 to n.

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.

1 Comment

ENGSADI
on 21 May 2016

try: y=sum(1:2^x). It will lead to shorter solution.

1 Comment

Michael Kobylarek
on 12 May 2016

not sure why this is wrong.

1 player likes this solution

1 Comment

lis coffey
on 14 Jul 2016

I can't figure this out after 10+ tries. Someone please help? http://www.followthesteps.net/sky-contact-phone-number/

1 player likes this solution

2 Comments

Dan W
on 10 Jul 2015

Ha!

naveen sarigala
on 23 Oct 2015

nice

1 player likes this solution

2 Comments

2 players like this solution

1 Comment

Dimitris Kaliakmanis
on 15 Oct 2013

How this solution is possible?

3 players like this solution

1 Comment

David Young
on 9 Feb 2012

A good example of a solution that does well on Cody's size measure, but which I wouldn't use for serious purposes.

**Tags**

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
17 players like this problem

17 players like this problem