To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 5042
5041  |  5043
Subject: 
Re: A recursion question/test...
Newsgroups: 
lugnet.robotics
Date: 
Wed, 12 May 1999 21:05:25 GMT
Viewed: 
1001 times
  
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:
  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 (...) (26 years ago, 12-May-99, to lugnet.robotics)

4 Messages in This Thread:



Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    
Active threads in Robotics

 
Verified and Trusted Team of Hackers
19 hours ago
Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR