Steve Graham wrote:
> I'm looking for a way to generate every possible combination of n letters out 
> of a total of m letters.
> 
> For example, if the available letters are  A, B, C and I want to generate all 
> possible 2-letter combinations, it should generate the following:
> AB
> BA
> AC
> CA
> BC
> CB
> 
> I think I've seen a trivial way of doing this in Icon/Unicon but don't 
> remember.  Any ideas?

Hi Steve,

There's a method comp(s, n) in the IPL (procs/strings.icn) that does what you 
want.  The
code is:

   procedure comb(s, i)            #: character combinations
      local j

      if i < 1 then fail
      suspend if i = 1 then !s
         else s[j := 1 to *s - i + 1] || comb(s[j + 1:0], i - 1)

   end

-Steve
-- 
Steve Wampler -- [EMAIL PROTECTED]
The gods that smiled on your birth are now laughing out loud.


-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Unicon-group mailing list
Unicon-group@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/unicon-group

Reply via email to