Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80381

Re: generating 2D bit array variants with specific algorythm

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: generating 2D bit array variants with specific algorythm
Date 2014-11-07 15:41 -0500
Organization IISS Elusive Unicorn
References <0e6787f9-88d6-423a-8410-7578fa83d61c@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.15575.1415392889.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Fri, 7 Nov 2014 07:39:27 -0800 (PST), Robert Voigtländer
<r.voigtlaender@gmail.com> 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/

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

generating 2D bit array variants with specific algorythm Robert Voigtländer <r.voigtlaender@gmail.com> - 2014-11-07 07:39 -0800
  Re: generating 2D bit array variants with specific algorythm Joel Goldstick <joel.goldstick@gmail.com> - 2014-11-07 10:51 -0500
    Re: generating 2D bit array variants with specific algorythm Robert Voigtländer <r.voigtlaender@gmail.com> - 2014-11-07 08:02 -0800
      Re: generating 2D bit array variants with specific algorythm "ast" <nomail@invalid.com> - 2014-11-07 17:40 +0100
  Re: generating 2D bit array variants with specific algorythm Peter Otten <__peter__@web.de> - 2014-11-07 17:29 +0100
  Re: generating 2D bit array variants with specific algorythm "ast" <nomail@invalid.com> - 2014-11-07 17:57 +0100
    Re: generating 2D bit array variants with specific algorythm "ast" <nomail@invalid.com> - 2014-11-07 17:58 +0100
  Re:generating 2D bit array variants with specific algorythm Dave Angel <davea@davea.name> - 2014-11-07 14:34 -0500
  Re: generating 2D bit array variants with specific algorythm Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-11-07 15:41 -0500
  Re: generating 2D bit array variants with specific algorythm Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-11-08 10:13 +1300
    Re: generating 2D bit array variants with specific algorythm sohcahtoa82@gmail.com - 2014-11-07 17:10 -0800

csiph-web