left brain and right brain permutations

P

pataphor

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top