Re: [Tutor] Automatic generation of an "all possible combinations" array

2007-06-15 Thread Hugh M
Ah, in the case of looking for all n-digit bit-strings that contain exactly m-1's, the recursive solution is even nicer. Here's how I think of it: Base Case(s): - if you want 0 1's (m==0) then return all 0's. - if you want all 1's (n==m) then return all 1's. Otherwise Recursive Case: - return th

Re: [Tutor] Automatic generation of an "all possible combinations" array

2007-06-15 Thread Alan Gauld
"Luke Paireepinart" <[EMAIL PROTECTED]> wrote > You could also do this by iterating in base-16 instead of base-10... I was going to suggest the same but using octal which has the same property but fewer values to map. :-) > hexmap = > {"0":"","1":"0001","2":"0010","3":"0011","4":"0100","5"

Re: [Tutor] Automatic generation of an "all possible combinations" array

2007-06-15 Thread Luke Paireepinart
Andy Cheesman wrote: > The code works great, Thanks for the speedy response. The only problem > which I can see is that the code scales very bad with the size of n. > You could also do this by iterating in base-16 instead of base-10... given a string of hex, like "59FDE", there is a direct corre

Re: [Tutor] Automatic generation of an "all possible combinations" array

2007-06-15 Thread Andy Cheesman
The code works great, Thanks for the speedy response. The only problem which I can see is that the code scales very bad with the size of n. So, as I want a small subsection of the data (i.e lines where there are only 4 1s, number in the code below) for a system where n is large(>20). The idea is

Re: [Tutor] Automatic generation of an "all possible combinations" array

2007-06-14 Thread Vishnu Mohan
Another simplest way of doing it is >>> from random import * from sys import * def bin_list(n): bin_val = 0 if n >= 0: bin_val = 2**n - 1 list = [] while bin_val >= 0: list.append([((bin_val >> y) & 1) for y in range(n-1,-1,-1)]) bin_val -= 1 shuffle(

Re: [Tutor] Automatic generation of an "all possible combinations" array

2007-06-14 Thread Hugh M
The 2**n different lists that you are seeking have a direct association to the binary representation of the integers 0 through (2**n)-1. You can use this fact and the "repeated division method" for converting numbers between different bases to generate these lists and form the desired list of list

[Tutor] Automatic generation of an "all possible combinations" array

2007-06-14 Thread Andy Cheesman
Hi people I am trying to generate an array of all possible combinations of 1, and zeros (see example data) for a rather nice Kinetic mote Carlo program which I am writing python. So far, I've been working out for combinations for 4 or less species by hand as it is quick! but I am looking to automa