 | | Re: recursion (was RE: Would-be hacker queries.)
|
|
Hi, Important clarification: "data stack" free recursion. This is an important significance. It's really only useful for systems with no data stack.... or alternately as an interesting conversation piece. What's usually more clever is using data (...) (28 years ago, 11-May-99, to lugnet.robotics)
|
| |
 | | Re: recursion (was RE: Would-be hacker queries.)
|
|
(...) Actually, he goes on to show that in some cases you can eliminate call stack recursion using simple transforms as well. (...) For example, JVM does this by keeping a frame stack of methods that have been executed. The interpreter main loop (...) (28 years ago, 11-May-99, to lugnet.robotics)
|
| |
 | | Re: recursion (was RE: Would-be hacker queries.)
|
|
(...) Let me say that I have not looked at the algorythm in question, yet, so forgive me if this is their solution... (...) The SmalltalkVM my last company built used much the same idea, however, one might say that it was a truely recursive (...) (28 years ago, 12-May-99, to lugnet.robotics)
|
| |
 | | Re: A recursion question/test...
|
|
(define (sum num) (if (zero? num) 0 (+ num(sum (- num 1))))) -- Richard Clemens Associate Professor Computer Science Department West Virginia Wesleyan College Buckhannon, West Virginia 26201 clemens@wvwc.edu 304.473.8421 ----- Original Message ----- (...) (28 years ago, 12-May-99, to lugnet.robotics)
|
| |
 | | 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 (...) (28 years ago, 12-May-99, to lugnet.robotics)
|
| |
 | | Re: Scheme
|
|
A simple scheme interface such as (sensor <num> <type> <mode>) or (motor <letter> <direction> <speed>) could prove a valuable addition to scheme teaching functions. Students could explore functions (i.e. just small "programs") to include the ability (...) (28 years ago, 12-May-99, to lugnet.robotics)
|
| |
 | | Re: A recursion question/test... (fwd)
|
|
(...) Make that 'numbers' into 'positive integers' and it'll make more sense perhaps. (...) It's recursive, the only number you know is n. Language is really irrelevant. I asked for an algorithm. I'll give you a hint, it consists of two sentences (...) (28 years ago, 12-May-99, to lugnet.robotics)
|
| |
 | | RE: Would-be hacker queries. (fwd)
|
|
----- Forwarded message from Joel Shafer ----- Date: Tue, 11 May 1999 11:53:27 -0500 From: Joel Shafer <joel@connect.net> Subject: RE: Would-be hacker queries. It's too bad that recursion pays the price of stack usage. Recursion is almost always a (...) (28 years ago, 12-May-99, to lugnet.robotics)
|
| |
 | | Re: Scheme (fwd)
|
|
----- Forwarded message from Rich Clemens ----- From: "Rich Clemens" <clemens@wvwc.edu> Subject: Re: Scheme Date: Tue, 11 May 1999 23:26:18 -0400 A simple scheme interface such as (sensor <num> <type> <mode>) or (motor <letter> <direction> <speed>) (...) (28 years ago, 12-May-99, to lugnet.robotics)
|
| |
 | | Re: A recursion question/test... (fwd)
|
|
----- Forwarded message from Rich Clemens ----- From: "Rich Clemens" <clemens@wvwc.edu> Subject: Re: A recursion question/test... Date: Tue, 11 May 1999 23:51:21 -0400 (define (sum num) (if (zero? num) 0 (+ num(sum (- num 1))))) ----- End of (...) (28 years ago, 12-May-99, to lugnet.robotics)
|
| |
 | | RE: cursion (was RE: Would-be hacker queries.)
|
|
I hate to be pedantic, but what you're describing is functional composition. The key to recursion is that the function calls itself. e.g. int factorial(int n) // assumes n > 0 { if (n > 1) return n * factorial( n - 1); // the recursive call, this is (...) (28 years ago, 11-May-99, to lugnet.robotics)
|
| |
 | | 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 (...) (28 years ago, 12-May-99, to lugnet.robotics)
|
| |
 | | Re: A recursion question/test...
|
|
(...) d'oh. my ($n)=@ARGV; my $result=$n; $result += $n while($n--); print $result."\n"; What a difference a compile makes... but it's still not very recursive. I'll be interested in seeing your answer. Aloha, JR - - - - - - - - - - JR Conlin (...) (28 years ago, 12-May-99, to lugnet.robotics)
|
| |
 | | Re: A recursion question/test...
|
|
Jim Choate poses the problem: (...) What other than sum(n) = n + sum(n-1) (with proper termination conditions, of course - sum(1) = 1). Ralph deal@kzoo.edu -- Did you check the web site first?: (URL) (28 years ago, 12-May-99, to lugnet.robotics)
|
| |
 | | You know, all this computer science talk doesn't really belong here.
|
|
Try lugnet.off-topic.geek. :) (...) (28 years ago, 12-May-99, to lugnet.robotics)
|
| |
 | | Re: Scheme (fwd)
|
|
On Tue, 11 May 1999, Jim Choate wrote: . . . (...) More details: In 1966, work began on LOGO at Bolt, Beranek, & Newman. The team was headed by Wally Fuerzeig and included Seymour Papert who later wrote the text which popularized LOGO: MindStorms. (...) (28 years ago, 12-May-99, to lugnet.robotics)
|
| |
 | | Re: Fishing for a tasty linkage/gearing/robotic building thread...
|
|
Me too !! Kipling Morris wrote in message ... (...) against (...) I (...) (28 years ago, 12-May-99, to lugnet.robotics)
|
| |
 | | Re: A recursion question/test... (correction)
|
|
Whoops! I typed the last two lines with the two aggregate operators interchanged! Obviously they should have read FUNCTION sum(n: natural): natural = SUM [0..n] FUNCTION fac(n: natural): natural = PRODUCT [1..n] Malcolm -- Did you check the web site (...) (28 years ago, 12-May-99, to lugnet.robotics)
|
| |
 | | Re: A recursion question/test...
|
|
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: (...) (28 years ago, 12-May-99, to lugnet.robotics)
|
| |
 | | mindstorms - motors and stuff
|
|
Just wondering - I've seen people hook up 2 motors to a port - how many is it safe to use? How much current can this thing supply? Can it drive the old-style 9V motors? (28 years ago, 12-May-99, to lugnet.robotics)
|