[futurebasic] Re: [FB] converting integers to letter triplets

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 2005 : Group Archive : Group : All Groups

From: Jay Reeve <jayreeve@...>
Date: Sat, 11 Jun 2005 21:41:31 -0500
Michael,

Here's a method a bit less brutish. It let's you set your zero base 
(i.e. what number will "AAA" represent), but it must be the same going 
both directions.

local fn numToTriplet$(num as long, zeroBase as long)
dim as str15 triplet
dim as long  i, div

num       -= zeroBase
long if num < 0 or num > 17575
stop str$(num + zeroBase) + "is out of range."
exit fn
end if
div        = 676
triplet[0] = 3

for i = 1 to 3
triplet[i] = 65 + num \\ div
num        = num mod div
div        = div \\ 26
next

end fn = triplet

local fn tripletToNum(triplet as str255, zeroBase as long)
dim as long i, num

long if triplet < "AAA" or triplet > "ZZZ"
stop """" + triplet + """ is out of range."
exit fn
end if
num = 0

for i = 1 to 3
num  = num * 26 + triplet[i] - 65
next

end fn = num + zeroBase

  e-e
  =J= a  y
   "

On Saturday, June 11, 2005, at 02:59  PM, Michael Evans wrote:

> Hello all...
>
> The integers:
> 	1 to 17576 can be transformed into the triplets AAA to ZZZ
> 	2 to 17577 can similarly be transformed into the triplets AAA to ZZZ
>
> The brute force, tedious and laborious, way of doing this: