[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Show all permutations of N coins ... without using recursion?


Subject: Re: [xsl] Show all permutations of N coins ... without using recursion?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Sun, 01 Sep 2013 11:41:43 +0100

On 31/08/2013 17:18, Costello, Roger L. wrote:
Jacob Mal} wrote:

  You just iterate from 1 to 2^N, each step gives
you one output sequence, you just have to convert
it to the desired format.

Thank you very much!


I did as you suggested and it works great.

The below stylesheet shows the permutations of N coins, implemented in two ways: (1) using recursion, and (2) using iteration.

By the way, I recently learned about the xsl:iterate instruction. Wow! Such a useful instruction. How have I lived without it all these years.

Of course you're really using a different _syntax_ for a recursive function rather than not using recursion. As noted on the spec xsl:iterate is essentially a syntactic wrapper around a tail recursive function. It may not be implemented that way, but functions that you write as tail recursive may not be implemented via recursion either.


David


-- google plus: https:/profiles.google.com/d.p.carlisle


Current Thread