Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-03 Thread Larry Hudson via Python-list
On 08/02/2015 01:58 PM, Joonas Liik wrote: I have this feeling that you would get a lot more useful anwsers if you were to describe your actual problem in stead of what you think the solution is. There might be other, better solutions but since we know so little about what you are doing we will l

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-03 Thread Mark Lawrence
On 02/08/2015 21:58, Joonas Liik wrote: I have this feeling that you would get a lot more useful anwsers if you were to describe your actual problem in stead of what you think the solution is. There might be other, better solutions but since we know so little about what you are doing we will like

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-03 Thread Joonas Liik
I have this feeling that you would get a lot more useful anwsers if you were to describe your actual problem in stead of what you think the solution is. There might be other, better solutions but since we know so little about what you are doing we will likely never find them by just guessing.. --

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-02 Thread Larry Hudson via Python-list
On 08/01/2015 01:34 PM, Lukas Barth wrote: Hi! I have a list of numbers that I treat as "circular", i.e. [1,2,3] and [2,3,1] should be the same. Now I want to rotate these to a well defined status, so that I can can compare them. If all elements are unique, the solution is easy: find the mini

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-02 Thread Tim Chase
On 2015-08-01 13:34, Lukas Barth wrote: > I have a list of numbers that I treat as "circular", i.e. [1,2,3] > and [2,3,1] should be the same. Now I want to rotate these to a > well defined status, so that I can can compare them. > > If all elements are unique, the solution is easy: find the minimu

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-02 Thread pavlovevidence
On Saturday, August 1, 2015 at 1:34:44 PM UTC-7, Lukas Barth wrote: > Hi! > > I have a list of numbers that I treat as "circular", i.e. [1,2,3] and [2,3,1] > should be the same. Now I want to rotate these to a well defined status, so > that I can can compare them. > > If all elements are unique

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-02 Thread Steven D'Aprano
On Sun, 2 Aug 2015 08:51 am, Lukas Barth wrote: > On Saturday, August 1, 2015 at 11:37:48 PM UTC+2, Emile van Sebille wrote: >> Well, it looks to me that I don't know what a 'canonical rotation' is -- > > That's because it is not defined. ;) > > I need a way to rotate one of these lists in a way

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Marko Rauhamaa
Lukas Barth : > On Saturday, August 1, 2015 at 10:57:19 PM UTC+2, Marko Rauhamaa wrote: >> >> def circularly_equal(l1, l2): >> length = len(l1) >> if length != len(l2): >> return False >> twice = l1 + l1 >

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Paul Rubin
Paul Rubin writes: > H([b-a, c-b, d-c, a-d]) > where H is your favorite hash function on a list of that element type. I wrote that up unclearly. H is supposed to be a hash on one element, and then you combine H(b-a), H(c-b), etc. in a commutative way, such as by adding them. Still not sure if

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Paul Rubin
Lukas Barth writes: >> [Concatenated Hashes] > Also, that still doesn't compute that one "canonical ordering"... It was intended to get rid of the need. What is the actual application? How does this sound? To circularly hash [a,b,c,d] use: H([b-a, c-b, d-c, a-d]) where H is your favorite h

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Cameron Simpson
On 01Aug2015 15:55, Lukas Barth wrote: On Sunday, August 2, 2015 at 12:32:25 AM UTC+2, Cameron Simpson wrote: Fine. This also eliminates any solution which just computes a hash. Exactly. Might I suggest instead simply starting with the leftmost element in the first list; call this elem0. T

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread wolfram.hinderer--- via Python-list
Am Samstag, 1. August 2015 22:34:44 UTC+2 schrieb Lukas Barth: > Hi! > > I have a list of numbers that I treat as "circular", i.e. [1,2,3] and [2,3,1] > should be the same. Now I want to rotate these to a well defined status, so > that I can can compare them. > > If all elements are unique, the

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Josh English
On Saturday, August 1, 2015 at 3:52:25 PM UTC-7, Lukas Barth wrote: > On Saturday, August 1, 2015 at 11:37:48 PM UTC+2, Emile van Sebille wrote: > > Well, it looks to me that I don't know what a 'canonical rotation' is -- > > That's because it is not defined. ;) > > I need a way to rotate one of

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Lukas Barth
On Sunday, August 2, 2015 at 1:05:32 AM UTC+2, Oscar Benjamin wrote: > Do you really need the canonical rotation or just a hash that is invariant > under rotations? Having that canonical rotation would make the code simpler and faster, probably, but a rotationally invariant hash is a good start.

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Oscar Benjamin
On Sun, 2 Aug 2015 00:05 Oscar Benjamin wrote: On Sat, 1 Aug 2015 22:06 Lukas Barth wrote: Nice idea! But I actually really need those "canonic rotations", since I'm hashing them somewhere. Do you really need the canonical rotation or just a hash that is invariant under rotations? I don't

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Oscar Benjamin
On Sat, 1 Aug 2015 22:06 Lukas Barth wrote: Nice idea! But I actually really need those "canonic rotations", since I'm hashing them somewhere. Do you really need the canonical rotation or just a hash that is invariant under rotations? I don't know of a solution to the former that is better

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Lukas Barth
On Sunday, August 2, 2015 at 12:32:25 AM UTC+2, Cameron Simpson wrote: > Fine. This also eliminates any solution which just computes a hash. Exactly. > Might I suggest instead simply starting with the leftmost element in the > first > list; call this elem0. Then walk the second list from 0 to

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Joel Goldstick
On Sat, Aug 1, 2015 at 6:51 PM, Lukas Barth wrote: > On Saturday, August 1, 2015 at 11:37:48 PM UTC+2, Emile van Sebille wrote: >> Well, it looks to me that I don't know what a 'canonical rotation' is -- > > That's because it is not defined. ;) > > I need a way to rotate one of these lists in a wa

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Lukas Barth
On Saturday, August 1, 2015 at 11:43:28 PM UTC+2, Paul Rubin wrote: > How large are these lists supposed to be? Potentially large. Not so large though that iterating them (multiple times) should be a problem. > [Concatenated Hashes] > > If the lists are very large that doesn't sound so great d

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Lukas Barth
On Saturday, August 1, 2015 at 11:37:48 PM UTC+2, Emile van Sebille wrote: > Well, it looks to me that I don't know what a 'canonical rotation' is -- That's because it is not defined. ;) I need a way to rotate one of these lists in a way so that it will produce the same output every time, regar

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Cameron Simpson
On 01Aug2015 14:24, Lukas Barth wrote: Perhaps I should clarify a bit: - I definitely need a "canonical rotation" - just a comparison result is not enough Fine. This also eliminates any solution which just computes a hash. - It does not matter what that rotation is. Starting with the smalle

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Paul Rubin
Lukas Barth writes: > - It does not matter what that rotation is. Starting with the smallest > element was just an idea by me, any rotation that can easily produced > will do. How large are these lists supposed to be? If they're (say) 5 elements, you could make the hash code consist of the conca

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Emile van Sebille
On 8/1/2015 2:24 PM, Lukas Barth wrote: Perhaps I should clarify a bit: - I definitely need a "canonical rotation" - just a comparison result is not enough Well, it looks to me that I don't know what a 'canonical rotation' is -- there's no wikipedia article and googling yields all sorts of

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Emile van Sebille
On 8/1/2015 2:12 PM, Lukas Barth wrote: On Saturday, August 1, 2015 at 10:51:03 PM UTC+2, Emile van Sebille wrote: Is the problem to determine if one list of circular numbers 'matches' another one despite rotation status? If so, I'd do something like: Well.. no. I actually really need this "c

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Lukas Barth
Perhaps I should clarify a bit: - I definitely need a "canonical rotation" - just a comparison result is not enough - It does not matter what that rotation is. Starting with the smallest element was just an idea by me, any rotation that can easily produced will do. -- https://mail.python.org/m

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Lukas Barth
On Saturday, August 1, 2015 at 10:51:03 PM UTC+2, Emile van Sebille wrote: > Is the problem to determine if one list of circular numbers 'matches' > another one despite rotation status? If so, I'd do something like: Well.. no. I actually really need this "canonical" rotation, since I'm hashing

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Lukas Barth
On Saturday, August 1, 2015 at 10:57:19 PM UTC+2, Marko Rauhamaa wrote: > > def circularly_equal(l1, l2): > length = len(l1) > if length != len(l2): > return False > twice = l1 + l1 > for i in range(len

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Marko Rauhamaa
Lukas Barth : > I have a list of numbers that I treat as "circular", i.e. [1,2,3] and > [2,3,1] should be the same. Now I want to rotate these to a well defined > status, so that I can can compare them. > > If all elements are unique, the solution is easy: find the minimum > element, find its inde

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Emile van Sebille
On 8/1/2015 1:34 PM, Lukas Barth wrote: Hi! I have a list of numbers that I treat as "circular", i.e. [1,2,3] and [2,3,1] should be the same. Now I want to rotate these to a well defined status, so that I can can compare them. If all elements are unique, the solution is easy: find the minimum

Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Lukas Barth
Hi! I have a list of numbers that I treat as "circular", i.e. [1,2,3] and [2,3,1] should be the same. Now I want to rotate these to a well defined status, so that I can can compare them. If all elements are unique, the solution is easy: find the minimum element, find its index, then use mylist