Differences between revisions 1 and 6 (spanning 5 versions)
Revision 1 as of 2007-07-20 17:39:45
Size: 728
Editor: dhcp18
Comment:
Revision 6 as of 2008-11-15 14:00:41
Size: 776
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 15: Line 15:
should return ["aa","ab","ac","ba","bb","bc","ca","cb","cc"] should return {{{ ["aa","ab","ac","ba","bb","bc","ca","cb","cc"] }}}
Line 19: Line 19:
["111","113", ... ,"997","999"] {{{ ["111","113", ... ,"997","999"] }}}
Line 25: Line 25:
{{{
Line 28: Line 29:
}}}
----
CategoryAdvocacy

This probably shouldn't be the first example, but it's a nice one:

===

My requirement was

I want a list of all ordered permutations of a given length of a set of tokens. Each token is a single character, and for convenience, they are passed as a string in ascending ASCII order.

For example

permute("abc",2)

should return  ["aa","ab","ac","ba","bb","bc","ca","cb","cc"] 

and permute("13579",3) should return a list of 125 elements

 ["111","113", ... ,"997","999"] 

===

Ask the experienced coder to code this up in the language of his or her choice. Then show them this (contributed by castironpi):

 def p(a,b):
        if not b: return ['']
        return [i+j for i in a for j in p(a,b-1)]


CategoryAdvocacy

EasyAsPy (last edited 2014-04-17 06:10:58 by DaleAthanasias)

Unable to edit the page? See the FrontPage for instructions.