Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.01; 'python.': 0.04; 'value,': 0.04; 'subject:Python': 0.05; 'subject:based': 0.07; 'suggestions,': 0.07; 'python': 0.08; '>>>>': 0.09; 'excellent,': 0.09; 'ids': 0.09; 'am,': 0.12; 'received:209.85.210.174': 0.13; 'received:mail- iy0-f174.google.com': 0.13; '...,': 0.16; 'a1,': 0.16; 'b1,': 0.16; 'does,': 0.16; 'element,': 0.16; 'from:addr:alec.taylor6': 0.16; 'from:name:alec taylor': 0.16; 'integer.': 0.16; 'numbering': 0.16; 'okay,': 0.16; 'ordinal': 0.16; 'url:pastebin': 0.16; 'cc:addr:python-list': 0.16; 'wed,': 0.17; 'wrote:': 0.18; '>>>': 0.18; 'int': 0.18; 'convert': 0.19; 'this?': 0.19; 'seems': 0.20; 'cheers,': 0.20; 'suggest': 0.20; 'dec': 0.22; "doesn't": 0.22; 'assume': 0.22; 'header:In-Reply-To:1': 0.22; 'concise': 0.23; 'loop,': 0.23; '\xa0if': 0.23; 'defined': 0.24; 'string': 0.24; 'cc:2**0': 0.24; 'structure': 0.26; 'thanks.': 0.26; 'tried': 0.27; 'message-id:@mail.gmail.com': 0.28; 'cc:addr:python.org': 0.29; 'nov': 0.29; 'definition': 0.30; 'seem': 0.30; '(unless': 0.30; 'conversion.': 0.30; 'kelly': 0.30; 'least': 0.30; 'thanks': 0.31; "i'll": 0.31; 'does': 0.32; 'implementing': 0.32; 'thu,': 0.32; 'value.': 0.32; 'implement': 0.32; "isn't": 0.33; 'actually': 0.33; 'that,': 0.33; 'it.': 0.34; 'follows:': 0.34; 'too': 0.34; 'certain': 0.34; 'anything': 0.34; 'ordered': 0.34; 'suggestions': 0.35; 'regular': 0.35; '...': 0.36; 'element': 0.37; 'own,': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'not,': 0.37; 'using': 0.38; 'received:209.85': 0.38; 'put': 0.38; 'correctly': 0.39; 'i.e.': 0.39; 'url:org': 0.39; 'appreciated.': 0.39; 'why': 0.39; 'received:209': 0.40; 'unique': 0.61; 'more': 0.61; '2011': 0.61; 'your': 0.61; 'back': 0.62; 'taylor': 0.67; 'care': 0.71; '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; 'url:tinypic': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=U1k2lanEdgMqgw+LWPe6yFlPhHdfzYX11aNBd7paykg=; b=jZa4CjGY+s2pPYPBAS4ew4sUDVxvH/GSeOH1XbtF7XYCmGNTGxvWNoLC+L1w8g+zKG iwHiZzGsnRaFQ1SIhGOZJCKu5G9X3GCSySoUPVCocZw8XctmotCkgdYtdphUWwc+vqRj IKJecYWJc1T2bBe5mQyTws1tOpgVKmBcylyvM= MIME-Version: 1.0 In-Reply-To: References: Date: Thu, 1 Dec 2011 06:00:38 +1100 Subject: Re: Defining a new base-type in Python based off Hexavigesimal From: Alec Taylor To: Ian Kelly Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: "comp.lang.python" 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: 83 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1322679641 news.xs4all.nl 6947 [2001:888:2000:d::a6]:54241 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:16446 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 wrote: > On Wed, Nov 30, 2011 at 9:26 AM, Alec Taylor wro= te: >> On Thu, Dec 1, 2011 at 3:18 AM, Ian Kelly wrote: >>> On Wed, Nov 30, 2011 at 8:19 AM, Alec Taylor w= rote: >>>> Good evening, >>>> >>>> I have defined a new numbering structure for certain mathematical adva= ntages. >>>> >>>> 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. =A0If 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. =A0I 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. =A0If it > does, return it. =A0If 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? =A0It just doesn't seem > like very many to me. > > Cheers, > Ian