Re: Steve Summit C Notes {Anticipating the next one}



On Mar 18, 8:50 pm, Ben Pfaff <b...@xxxxxxxxxxxxxxx> wrote:
Richard Heathfield <r...@xxxxxxxxxxxxxxx> writes:
Old Wolf said:
There is a simpler way to compute the sequence of Fibonacci numbers !

usernnnnn's solution looked pretty simple to me. What way did you have
in mind that is simpler? If it involves recursion or iteration, you'll
have your work cut out justifying that "simpler" claim.

If you want the sequence, then recursion or iteration might
really be simpler.

If you just want one value at a specified place in the sequence,
then it's easier to use the closed form.
--
"In My Egotistical Opinion, most people's C programs should be indented six
feet downward and covered with dirt." -- Blair P. Houghton

In all of my replies, I tried to make the examples something that were
generally useful. That is why the solutions use function calls and
are not simply inlined main() routines (except the even/odd thing
which was totally trivial and not worth the bother).

In other words, it does not simply solve the problem at hand for a
given value, but solves the problem in a general sense. (AKA
'reusable').

That is the chief distraction I see from most of the other solutions.
They solve the exact given instance of the problem but not the general
case, so the only utility of the code presented is to solve the single
problem posed -- and not having usages for future problems of a
similar nature. I think that is a very bad way to code. I think it
even worse to teach it to a beginner. But you have to start
somewhere.

IMO-YMMV.

.



Relevant Pages

  • Re: Recursion help.
    ... iteration or like nested loops or something. ... a sequence of 2, and it should have a sequence of 1. ... You're not using recursion at all in your code. ...
    (comp.lang.ruby)
  • Re: Steve Summit C Notes {Anticipating the next one}
    ... in mind that is simpler? ... then recursion or iteration might ... If you just want one value at a specified place in the sequence, ...
    (comp.lang.c)
  • Short koan-like code snippets (was: coerce for arbitrary types)
    ... (defun bfs6 (test children pending) ... The algorithm seems to be a tail-recursive expression of what ... I don't like using tail recursion to emulate iteration, ...
    (comp.lang.lisp)
  • Re: Simple recursive functions in Lisp
    ... (labels ((rev (lst acc) ... becomes a loop variable. ... to the naive car/cdr recursion). ... Another way to express Graham's algorithm is iteration. ...
    (comp.lang.lisp)
  • Re: Software bugs arent inevitable
    ... I suggested that for a given algorithm implemented ... iteration should always be faster by a small factor. ... > recursive function can run out of stack space while the heap still has ... Which is why, in the part you snipped, I said that recursion (unlike ...
    (comp.lang.python)