From: Sam Roberts Date: 2010-02-14T12:02:51+09:00 Subject: Re: Generating all possible combinations of a 5 digit pattern. >>On 2/13/2010 7:05 PM, Zach Bartels wrote: >> >>> I saw a very basic one or two line  example where a range of 3 letters >>> was given, equal to abc (I forgot how it was written)  and it pretty >>> much spat out  all the combos of those 3 letters. You have only two letters, C and N. That is like have only two digits, 0 and 1. How many 5 digit combinations of 0 and 1 are there? 2**5. So, count from 0 to 2**5-1, write the number in binary, then convert 0 to C and 1 to N: irb(main):010:0> (0..(2**5-1)).map{|n| ("%05b" % n).tr("01", "CN") } => ["CCCCC", "CCCCN", "CCCNC", "CCCNN", "CCNCC", "CCNCN", "CCNNC", "CCNNN", "CNCCC", "CNCCN", "CNCNC", "CNCNN", "CNNCC", "CNNCN", "CNNNC", "CNNNN", "NCCCC", "NCCCN", "NCCNC", "NCCNN", "NCNCC", "NCNCN", "NCNNC", "NCNNN", "NNCCC", "NNCCN", "NNCNC", "NNCNN", "NNNCC", "NNNCN", "NNNNC", "NNNNN"] Cheers, Sam