Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #16447 > unrolled thread
| Started by | Peter Otten <__peter__@web.de> |
|---|---|
| First post | 2011-11-30 20:05 +0100 |
| Last post | 2011-11-30 20:05 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Defining a new base-type in Python based off Hexavigesimal Peter Otten <__peter__@web.de> - 2011-11-30 20:05 +0100
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2011-11-30 20:05 +0100 |
| Subject | Re: Defining a new base-type in Python based off Hexavigesimal |
| Message-ID | <mailman.3169.1322679955.27778.python-list@python.org> |
Alec Taylor wrote:
> On Thu, Dec 1, 2011 at 3:18 AM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
>> On Wed, Nov 30, 2011 at 8:19 AM, Alec Taylor <alec.taylor6@gmail.com>
>> wrote:
>>> Good evening,
>>>
>>> I have defined a new numbering structure for certain mathematical
>>> advantages.
>>>
>>> How do I implement this in Python, or would I be better off writing
>>> this in C or C++?
>>>
>>> Ultra concise definition: http://i42.tinypic.com/af7w4h.png
>>> LaTeX source: http://pastebin.tlhiv.org/Kf6jPRkI
>>>
>>> Thanks for all suggestions,
>>
>> So if I am understanding your definition correctly your hexavigesimals
>> are ordered like this?
>>
>> 0, 1, ..., 9, A, B, ..., P,
>>
>> 0A, 0B, ..., 0P,
>> 1A, 1B, ..., 1P,
>> ...,
>> 9A, 9B, ..., 9P,
>>
>> A0, A1, ..., A9,
>> B0, B1, ..., B9,
>> ...,
>> P0, P1, ..., P9
>>
>> And that's it, since your constraints preclude anything with more than 2
>> digits?
>
> To put it simply:
>
> I want a hexavigesimal of length n where each element contains at
> least one letter {A, B, ..., P} and one number {0, 1, 2, ... }.
> (unless n is less than 2, in which case only one of those constraints
> need to be met)
>
> and I want addition only for incrementing the element.
>
> Why do I want all this I hear you ask? - For use as a
> unique-identifier. I want a unique-ID of size 3. (3 positions, i.e.
> P0A)
>
> Any suggestions on how to implement this in python would be appreciated.
Maybe you don't need a class if you produce the ids with a generator like
so:
>>> from itertools import product
>>> def hxv(n):
... letters = "ABCDEFGHIJKLMNOP"
... digits = "0123456789"
... both = digits + letters
... if n == 1:
... for x in both:
... yield x
... else:
... for x in product(*[both]*n):
... s = "".join(x)
... if not s.isdigit() and not s.isalpha():
... yield s
...
>>> ids = hxv(3)
>>> next(ids)
'00A'
>>> next(ids)
'00B'
>>> for i, x in enumerate(hxv(3)): pass
...
>>> i, x
(12479, 'PP9')
Back to top | Article view | comp.lang.python
csiph-web