Re: Binary System Problem
- To: mathgroup at smc.vnet.net
- Subject: [mg18679] Re: [mg18621] Binary System Problem
- From: Robert Pratt <rpratt at math.unc.edu>
- Date: Thu, 15 Jul 1999 01:45:59 -0400
- Sender: owner-wri-mathgroup at wolfram.com
Needs["DiscreteMath`Combinatorica`"] toBinary[lis_List,n_]:=Table[If[MemberQ[lis,i],1,0],{i,1,n}] frieder[n_,k_]:=Map[toBinary[#,n]&,KSubsets[Range[n],k]] frieder[5,4] {{1,1,1,1,0},{1,1,1,0,1},{1,1,0,1,1},{1,0,1,1,1},{0,1,1,1,1}} You can go back and forth between the lists of binary digits and the decimal numbers as follows. Map[FromDigits[#,2]&,frieder[5,4]] {30,29,27,23,15} Map[IntegerDigits[#,2]&,%] {{1,1,1,1,0},{1,1,1,0,1},{1,1,0,1,1},{1,0,1,1,1},{1,1,1,1}} Rob Pratt Department of Mathematics The University of North Carolina at Chapel Hill CB# 3250, 331 Phillips Hall Chapel Hill, NC 27599-3250 rpratt at math.unc.edu http://www.math.unc.edu/Grads/rpratt/ On Tue, 13 Jul 1999, Frieder Schweigert wrote: > Hi, > > does anybody know an algorithm or generating system for > those binary numbers with a fix amount of '1's, > for example (four times '1'): > > 1111 > 10111 > 11011 > 11101 > 11110 >