Generating cyclic permutations / reduced Latin Squares in Python?

For the first part, the most concise way probably is a = 1, 2, 3, 4 n = len(a) ai - j for I in range(n) for j in range(n) # 1, 2, 3, 4, 4, 1, 2, 3, 3, 4, 1, 2, 2, 3, 4, 1 and for the second part ai - j for I in range(n) for j in range(n, 0, -1) # 1, 2, 3, 4, 2, 3, 4, 1, 3, 4, 1, 2, 4, 1, 2, 3 These should also be much more efficient than your code, though I did not do any timings.

Wow, didn't think you could do this using list comprehensions! Perhaps I should have thought harder. Props for not having to use any extra modules.

– ZOMGxuan Mar 15 at 15:51.

You can use collections. Deque: from collections import deque g = deque(1, 2, 3, 4) for I in range(len(g)): print list(g) #or do anything with permutation g. Rotate(1) #for right rotation #or g.

Rotate(-1) for left rotation It prints: 1, 2, 3, 4 4, 1, 2, 3 3, 4, 1, 2 2, 3, 4, 1 To change it for left rotation just replace g. Rotate(1) with g. Rotate(-1).

That rotate method is pretty cool. Never knew that dequeues could do that. Then again, I should probably have read the documentation thoroughly before asking.

– ZOMGxuan Mar 15 at 15:54 As it is double-ended queue, rotate operation is probably efficiently implemented. – Maciej Ziarko Mar 15 at 16:01 And documentations are indeed our best friends. :) – Maciej Ziarko Mar 15 at 16:04.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions