Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Alpha base-26 to base-10...

by Aristotle (Chancellor)
on Jul 01, 2003 at 00:06 UTC ( #270365=note: print w/ replies, xml ) Need Help??


in reply to Alpha base-26 to base-10...

use strict; use warnings; use List::Util qw(sum); use constant OFFS => 1 - ord 'a'; use constant BASE => ord("z") - ord("a") + 1; sub alphabetic_to_base10 { local $_ = reverse shift; my $fac = 1; sum map +( (OFFS+ord $_)*$fac, $fac*=BASE )[0], /./g; } printf "$_: %d\n", alphabetic_to_base10($_) for qw[a z aa az ba zz aaa + zba]; __END__ a: 1 z: 26 aa: 27 az: 52 ba: 53 zz: 702 aaa: 703 zba: 17629
Update: OFFS has to be 1 - ord 'a', not - ord 'a', of course.

Makeshifts last the longest.


Comment on Re: Alpha base-26 to base-10...
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://270365]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2014-10-01 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (391 votes), past polls