Defining a new base-type in Python based off Hexavigesimal

Alec Taylor alec.taylor6 at gmail.com
Wed Nov 30 14:00:38 EST 2011


Excellent, I'll see if I can implement that.

I was thinking more base data-type, but that seems impossible in python.

17 iterations (rarghh!)

But yeah, I'll try that, thanks.

On Thu, Dec 1, 2011 at 5:38 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> On Wed, Nov 30, 2011 at 9:26 AM, Alec Taylor <alec.taylor6 at gmail.com> wrote:
>> On Thu, Dec 1, 2011 at 3:18 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
>>> On Wed, Nov 30, 2011 at 8:19 AM, Alec Taylor <alec.taylor6 at 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.
>
> Okay, that's much clearer.  If you don't actually care about the
> ordinal value of each element, only about incrementing them, then I
> suggest implementing increment as follows:
>
> 1. Convert the string to an int using the regular base-26 conversion
> with the int() built-in.
> 2. In a loop, add 1 to the value.
> 3. Convert the value back to a string using the same base-26
> conversion.  I don't know of a built-in that does this, so you'll need
> to write your own, which isn't too difficult.
> 4. Check whether the new string meets all your constraints.  If it
> does, return it.  If not, go back to 2. and try again with the next
> integer.
>
> At most it will take 17 iterations to find a valid value, but most of
> the time the first value tried will be valid.
>
> I assume you're already aware that with 3 digits you'll only have
> 12480 possible unique IDs using this scheme?  It just doesn't seem
> like very many to me.
>
> Cheers,
> Ian



More information about the Python-list mailing list