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 / 5019
5018  |  5020
Subject: 
Re: A recursion question/test...
Newsgroups: 
lugnet.robotics
Date: 
Wed, 12 May 1999 06:27:35 GMT
Original-From: 
Malcolm S Powell <msp@#avoidspam#umbra.co.uk>
Viewed: 
423 times
  
It should be pointed out that the problem of summing the first n natural
numbers is isomorphic to that of finding the factorial of n.

Compare these two functions

FUNCTION sum(n: natural): natural = IF n = 0 THEN 0 ELSE n + sum(n - 1)

FUNCTION fac(n: natural): natural = IF n = 0 THEN 1 ELSE n * fac(n - 1)

Only the initial conditions and the composition operators are different.

In a language that lets you enumerate sets and apply aggregate
operations to them both operations can be described trivially without
recursion (At least until you start trying to describe the axioms that
define numbers).

FUNCTION sum(n: natural): natural = PRODUCT [0..n]

FUNCTION fac(n: natural): natural = SUM [1..n]


Malcolm

Jim Choate wrote:

With all the discussion on understanding recursion and such for programmers
I thought I'd share a little problem I find enlightening....

Describe as simple a recursive algorithm as possible for summing the first n
numbers.

--
Did you check the web site first?: http://www.crynwr.com/lego-robotics



Message is in Reply To:
  A recursion question/test...
 
Hi, With all the discussion on understanding recursion and such for programmers I thought I'd share a little problem I find enlightening.... Describe as simple a recursive algorithm as possible for summing the first n numbers. ___...___ Three step (...) (26 years ago, 12-May-99, to lugnet.robotics)

7 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
22 hours ago
Custom Search

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