Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'column': 0.07; 'initialize': 0.07; 'nested': 0.07; 'none,': 0.07; 'character,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; '"*"': 0.16; '"0"': 0.16; '>the': 0.16; 'abg': 0.16; 'dimension': 0.16; 'increment': 0.16; 'left,': 0.16; 'loops': 0.16; 'mandate': 0.16; 'message-id:@4ax.com': 0.16; 'oernx': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'rule.': 0.16; 'subject:array': 0.16; 'subject:bit': 0.16; 'variants': 0.16; 'width,': 0.16; 'variable': 0.18; 'fit': 0.20; 'example': 0.22; 'rules': 0.22; 'url:home': 0.24; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'tried': 0.27; 'array': 0.29; 'character': 0.29; 'reaches': 0.30; 'robert': 0.30; 'easier': 0.31; 'that.': 0.31; 'are:': 0.33; 'fri,': 0.33; 'actual': 0.34; 'skip:_ 10': 0.34; 'there,': 0.34; 'subject:with': 0.35; 'one,': 0.35; 'but': 0.35; 'there': 0.35; 'returning': 0.36; 'next': 0.36; 'possible': 0.36; 'should': 0.36; 'list': 0.37; 'implement': 0.38; 'nov': 0.38; 'needed': 0.38; 'to:addr:python-list': 0.38; 'skip:- 10': 0.38; 'does': 0.39; 'generating': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'around.': 0.60; 'first': 0.61; 'back': 0.62; 'real': 0.63; 'maximum': 0.63; 'sum': 0.64; 'more': 0.64; 'line,': 0.68; 'results': 0.69; 'repeat': 0.74; 'received:108': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: generating 2D bit array variants with specific algorythm Date: Fri, 07 Nov 2014 15:41:21 -0500 Organization: IISS Elusive Unicorn References: <0e6787f9-88d6-423a-8410-7578fa83d61c@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: adsl-108-73-118-182.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES 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: 88 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415392889 news.xs4all.nl 2954 [2001:888:2000:d::a6]:37372 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80381 On Fri, 7 Nov 2014 07:39:27 -0800 (PST), Robert Voigtländer declaimed the following: >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 This criteria means that there can be only ONE 1 per line, and there must be ONE 1 per line >- only valid results must be generated (generating all and only returning the valid results takes to long; that's what I tried already) Given the rephrased criteria -- then ALL results are valid as you should never even consider generating a line that has none, or more than one, 1 in it. Initialize each line as aLine = "0" * (width - 1) + "1" > >Must be possible with nested loops and a counter per line. But I don't get it. > From there, you just need to rotate by one character the first line... When the 1 rotates off the left, you have to rotate the next line by one character, and go back to the start... repeat as needed until the last line has rotated around. Of course, this is perhaps the harder way to implement it... Might be easier to just keep a list of the current 1 position on each line, increment it until it reaches the maximum width, then carry to the next line... And only produce the actual data as output... -=-=-=-=-=-=-=- pynff MrebBar(bowrpg): qrs __vavg__(frys, jvqgu=2, urvtug=2): frys._zngevk = [ 0 sbe y va enatr(urvtug) ] frys._jvqgu = jvqgu frys._urvtug = urvtug qrs qvfcynl(frys): cevag "*" * frys._jvqgu sbe y va enatr(frys._urvtug): ya = ["0"] * frys._jvqgu ya[frys._zngevk[y]] = "1" cevag "".wbva(ya) cevag "*" * frys._jvqgu qrs arkg(frys): sbe ya va enatr(frys._urvtug): pneel = frys._ebgngr(ya) vs abg pneel: oernx vs ya == frys._urvtug - 1: erghea Gehr #pneel ba ynfg yvar, qbar erghea Snyfr qrs _ebgngr(frys, ya): frys._zngevk[ya] += 1 pneel = Snyfr vs frys._zngevk[ya] == frys._jvqgu: frys._zngevk[ya] = 0 pneel = Gehr erghea pneel vs __anzr__ == "__znva__": qrsnhyg = MrebBar() qrsnhyg.qvfcynl() juvyr Gehr: vs qrsnhyg.arkg(): oernx qrsnhyg.qvfcynl() bgure = MrebBar(4, 6) bgure.qvfcynl() juvyr Gehr: vs bgure.arkg(): oernx bgure.qvfcynl() -=-=-=-=-=-=-=-=- Now -- if the real criteria is that the sum of each row AND the sum of each column must be 1, that is a more difficult problem; but your example 2x2 does not seem to mandate that. -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/