Alec Taylor wrote: > On Thu, Dec 1, 2011 at 3:18 AM, Ian Kelly <[email protected]> wrote: >> On Wed, Nov 30, 2011 at 8:19 AM, Alec Taylor <[email protected]> >> 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') -- http://mail.python.org/mailman/listinfo/python-list
