Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.01; 'else:': 0.03; 'subject:Python': 0.05; 'subject:based': 0.07; 'suggestions,': 0.07; 'python': 0.08; 'ids': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'am,': 0.12; 'def': 0.13; '...,': 0.16; 'a1,': 0.16; 'b1,': 0.16; 'numbering': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'url:pastebin': 0.16; 'wed,': 0.17; 'wrote:': 0.18; '>>>': 0.18; 'this?': 0.19; 'maybe': 0.21; 'dec': 0.22; 'concise': 0.23; 'from:addr:web.de': 0.23; 'defined': 0.24; 'structure': 0.26; 'import': 0.27; 'pass': 0.29; 'yield': 0.29; 'nov': 0.29; 'class': 0.29; 'definition': 0.30; '(unless': 0.30; 'kelly': 0.30; 'least': 0.30; 'thanks': 0.31; 'thu,': 0.32; 'implement': 0.32; 'header:X -Complaints-To:1': 0.33; 'to:addr:python-list': 0.34; 'certain': 0.34; 'anything': 0.34; 'ordered': 0.34; 'suggestions': 0.35; '...': 0.36; 'element': 0.37; 'skip:" 10': 0.37; 'received:org': 0.38; 'put': 0.38; 'correctly': 0.39; 'i.e.': 0.39; 'url:org': 0.39; 'appreciated.': 0.39; 'why': 0.39; 'to:addr:python.org': 0.40; 'more': 0.61; '2011': 0.61; 'your': 0.61; 'taylor': 0.67; 'url:png': 0.71; 'ultra': 0.73; '30,': 0.74; 'advantages.': 0.84; 'definition:': 0.84; 'digits?': 0.84; 'evening,': 0.84; 'latex': 0.84; 'preclude': 0.84; 'so:': 0.84; 'url:tinypic': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Defining a new base-type in Python based off Hexavigesimal Date: Wed, 30 Nov 2011 20:05:50 +0100 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084a1cd.dip.t-dialin.net X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 79 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1322679955 news.xs4all.nl 6975 [2001:888:2000:d::a6]:60965 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:16447 Alec Taylor wrote: > On Thu, Dec 1, 2011 at 3:18 AM, Ian Kelly wrote: >> On Wed, Nov 30, 2011 at 8:19 AM, Alec Taylor >> 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')