Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > left brain and right brain permutations

Thread Tools

left brain and right brain permutations

Posts: n/a
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)

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How does .rjust() work and why it places characters relative toprevious one, not to first character - placed most to left - or to left sideof screen? crispy Python 6 08-20-2012 12:45 PM
Dynamic Menu Items is not right aligned with Right to Left documen =?Utf-8?B?QmlzaG95?= ASP .Net 0 12-28-2006 11:39 AM
Align javascript alert message to right AND / OR make the direction as RIGHT-TO-LEFT Oran Javascript 2 12-03-2004 04:34 PM
Tool to right click image in windows explorer and rotate image right or left 90 degrees siliconpi Digital Photography 2 11-29-2004 12:56 PM
Left panel on left hand side of desktop on windows xp wish to get rid of Bun Mui Computer Support 1 09-14-2004 03:40 AM