Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!weretis.net!feeder1.news.weretis.net!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'nested': 0.07; 'counting': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'wrote': 0.14; 'dimension': 0.16; 'loops': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'rule.': 0.16; 'rules.': 0.16; 'subject:array': 0.16; 'subject:bit': 0.16; 'variants': 0.16; 'variable': 0.18; 'fit': 0.20; 'rules': 0.22; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'tried': 0.27; 'array': 0.29; 'robert': 0.30; 'are:': 0.33; 'problem': 0.35; 'subject:with': 0.35; 'but': 0.35; 'there': 0.35; 'returning': 0.36; 'possible': 0.36; 'hi,': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'matter': 0.61; 'sum': 0.64; 'results': 0.69; 'legal': 0.71; 'received:myvzw.com': 0.84; 'subject::': 0.85 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re:generating 2D bit array variants with specific algorythm Date: Fri, 7 Nov 2014 14:34:11 -0500 (EST) Organization: news.gmane.org References: <0e6787f9-88d6-423a-8410-7578fa83d61c@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: 184.sub-70-208-162.myvzw.com X-Newsreader: PiaoHong.Usenet.Client.VIP:1.63 X-Archive: encrypt X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415388864 news.xs4all.nl 2935 [2001:888:2000:d::a6]:57667 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80379 Robert Voigtländer Wrote in message: > Hi, > > I need to generate all variants of a 2D array with variable dimension sizes which fit a specific rule. (up to 200*1000) > > The rules are: > - Values are only 0 or 1 > - the sum of each line bust be 1 > - only valid results must be generated (generating all and only returning the valid results takes to long; that's what I tried already) > > So for a 2x2 array these would be the valid results: > > 10 > 01 > > 01 > 10 > > 10 > 10 > > 01 > 01 > > > Must be possible with nested loops and a counter per line. But I don't get it. If the matrix is m by n, then there are 2**n possibilities for each row. But only n of them are legal by your rules. So your problem is just a matter of counting in base n, all the possible m digit numbers. -- DaveA