From: Seebs Date: 2010-02-14T04:15:05+09:00 Subject: Re: Generating all possible combinations of a 5 digit pattern. On 2010-02-13, Zach Bartels wrote: > I think I can work out the program itself. But I am looking for a > quick and easy way to generate every possible 5 digit combination of > the letters " C" and "N" so I have the database I need to compare > each 5 frame segment. That sounds like five bits. Consider, then, using bit operations. Imagine that you have numbers from 0 to 31. Each number must have a unique pattern of bits, and a total of five bits. So... 0 00000 CCCCC 1 00001 CCCCN 2 00010 CCCNC 3 00011 CCCNN ... 31 11111 NNNNN The question is, how do we turn a number into a set of binary digits? One way would be: def letter(val, pos) (val & (2 << pos)) ? 'N' : 'C' end So that: letter(16, 0) => 'C' letter(16, 1) => 'C' letter(16, 2) => 'C' letter(16, 3) => 'C' letter(16, 4) => 'N' So 16 => NCCCC. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!