Re: Towers of Hanoi



"H." <hbe123@xxxxxxxxx> writes:

> Since both can be used in this problem (either a base case of 0 or a
> base case of 1), is one preferred over the other? If so, why?

When you're getting an understanding of the problem I think a base case
of 1 works better, because thinking about moving a 0-size tower out of
the way won't help you with the recursion.

Once you understand the problem and write a solution with the base case
of 1, changing the base case to 0 might make it more concise or
elegant. I don't know; I haven't solved it myself.

--

http://ourdoings.com/ Easily organize and disseminate news and
photos for your family or group.
.



Relevant Pages

  • Re: calculating fibonacci[was: encryption]
    ... "Elegant" is a bit of an over statement - it is elegant given the ... recursion, using a functional language, and the criterion of ... being created with the proviso that the compiler can be counted ... fib n = hack n 1 1 ...
    (comp.programming)
  • Re: newbie question : summing elements in a list
    ... > I am beginner at lisp and I can do it in the classical way with do... ... I mention this because it's a subjective judgment that 'do' is not elegant. ... but please understand that 'recursion' and 'elegance' are not synonymous, ... Recursive solutions can use stack and you can run out of stack. ...
    (comp.lang.lisp)
  • Re: is there a more concise or efficient way to code this fn ?
    ... > Your code is fine and no less concise than any recursive version I can ... > (you have written it correctly to take advantage of tail recursion, ... > Common Lisp doesn't guarantee that a compiler will cooperate). ... Where fold-right is predefined in my environment as... ...
    (comp.lang.lisp)
  • Re: FIbonacci
    ... > Peteris Krumins wrote: ... prev2 is Fand prev is F. ... using continuation-passing style and tail recursion, ...
    (comp.lang.c)
  • Re: Is there a better way to chose a slice of a list?
    ... I am just looking for a less verbose, more elegant, way to print a slice ... Pretty concise and elegant. ... depending on the enumerated type itself naturally. ...
    (comp.lang.python)