Speed
Peter M. Brigham
pmbrig at gmail.com
Tue Aug 26 10:19:32 EDT 2014
On Aug 26, 2014, at 9:42 AM, Beat Cornaz wrote:
> Works like a charm, Geoff. Great way of tackling the thing, very original.
>
> function P2 N,B
> -- N is the depth to permute
> -- B is the ASCII value to start from
> -- so P2(1,49) returns 21 cr 12
> -- P2(2,53) returns 675 cr 765 cr 756 cr 576 cr 657 cr 567
> if N = 0 then return numToChar(B) & cr
> put P2(N - 1,B) into T
> add B to N
> repeat with i = B to N - 1
> put T into T2
> replace numToChar(i) with numToChar(N) in T2
> replace cr with numToChar(i) & cr in T2
> put T2 after R
> end repeat
> replace cr with numToChar(N) & cr in T
> return R & T
> end P2
>
> If I input B =97 I get the permutations in abcd etc. which I often use, so really great
> If I input B= 48 I get the permutations in numbers 01234 etc. which I also often use.
> Beyond 9 I can easily make items and replace the ascii chars with 10, 11 etc.
>
> The DUPLICATES :
> I've been working on it to try to include this functionality into your script, but no dice yet. It is not really obvious at first sight.
> I'll continue to work on it though. If you or anyone has a bright idea, I'd love to hear it.
I don't know but it seems that the way to do this would be to work on permuting the character positions rather than the characters themselves. Perhaps using an array, charAtLoc[n], applying Geoff's algorithm to 1 though n, then replacing each number with charAtLoc[n] afterwards. I suspect it would be lots slower, though.
-- Peter
Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig
More information about the use-livecode
mailing list