left brain and right brain permutations

Discussion in 'Python' started by pataphor, Jun 14, 2009.

  1. pataphor

    pataphor Guest

    left brain:

    Generate permutations by index, see previous newsgroup posts. Code not
    now available here.

    They are very pragmatic and practical, can start right away, and can be
    efficiently spread over many independent computing cores.

    right brain:

    from itertools import izip, chain
    from math import factorial

    def expand(i,n):
    for _ in xrange(i+1):
    yield i+1
    for _ in xrange(n-i):
    yield i

    def firstrow(n):
    for i in xrange(n+1):
    for _ in xrange(factorial(n)):
    yield i

    def otherrow(x,n):
    return chain(*izip(*(expand(i,n) for i in x)))

    def nextperm(L,n):
    yield firstrow(n)
    for x in L:
    yield otherrow(x,n)

    def perm(n):
    L = [[0]]
    for i in xrange(1,n):
    L = nextperm(L,i)
    return izip(*L)


    They are very hard to understand but can yield deep insights, once one
    gets into them they hint at hidden regularities and symmetries, maybe
    even parallel worlds. Unfortunately they are very impractical because
    they generate their future out of previous results. Until someone
    invents a quantum computer. From that point on though they leave every
    left brain piece of code behind as if that old code would stand still on
    its spot.

    So, its not like I don't understand the functional mind, believe me, I
    would like nothing more than to go that way, but until quantum computing
    is there this stuff won't be able to compete.

    (Background, ignore this post, it is just for future reference, comments
    are still welcome though)

    P.
     
    pataphor, Jun 14, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QmlzaG95?=
    Replies:
    0
    Views:
    1,060
    =?Utf-8?B?QmlzaG95?=
    Dec 28, 2006
  2. =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=

    Help on table align on left of page vs left hanging indent

    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=, Jul 10, 2007, in forum: XML
    Replies:
    2
    Views:
    1,050
    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=
    Jul 16, 2007
  3. pc
    Replies:
    2
    Views:
    1,394
    crisgoogle
    Jun 8, 2011
  4. lawrence
    Replies:
    13
    Views:
    342
    Thomas 'PointedEars' Lahn
    Sep 4, 2004
  5. Oran
    Replies:
    2
    Views:
    610
Loading...

Share This Page