Subject:
|
Re: A recursion question/test...
|
Newsgroups:
|
lugnet.robotics
|
Date:
|
Wed, 12 May 1999 21:05:25 GMT
|
Viewed:
|
812 times
|
| |
![Post a public reply to this message](/news/icon-reply.gif) | |
JR Conlin <jrconlin@email.com> wrote:
> Iterative:
> my $result = $lowBoundry;
> while ($result++ <=$highBoundry);
> return $result;
If you're not going to make it recursive, why not:
$result = $n * ($n + 1) / 2;
That is effectively the sum of all numbers from 0 to n.
-Kekoa
|
|
Message is in Reply To:
![](/news/x.gif) | | Re: A recursion question/test...
|
| (...) Well, you didn't specify if the numbers existed in a list or were iterative, and you didn't specify language so: Smalltalk: ^list sum. or ^(1..n) sum. sorry.. if you'll excuse Perl... List: foreach $num (@list) {$result += $num;} return (...) (25 years ago, 12-May-99, to lugnet.robotics)
|
4 Messages in This Thread: ![Re: A recursion question/test... -lego-robotics@crynwr.com (JR Conlin) (12-May-99 to lugnet.robotics)](/news/x.gif) ![](/news/246.gif) ![Re: A recursion question/test... -Eric Lind (12-May-99 to lugnet.robotics)](/news/x.gif)
![](/news/x.gif) ![](/news/268.gif) ![You are here](/news/here.gif)
![](/news/x.gif) ![](/news/68.gif) ![Re: A recursion question/test... -lego-robotics@crynwr.com (JR Conlin) (13-May-99 to lugnet.robotics)](/news/x.gif)
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|