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

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

From: Michael Evans <michaelevans_01@...>
Date: Sat, 11 Jun 2005 23:01:56 -0400
Steve:

Well, in my case, I need to recursively extract jpeg files from many 
folders with many subfolders and perform some normalization on 
descriptive metadata found internally in the jpeg files. Then I place 
the massaged jpeg files in a series of newly created and named output 
folders. Each output folder can contain no more than 496 jpeg files.

My client, for reasons that are not entirely clear to me, wishes the 
names of the sequentially numbered output folders to start with the 
triplets AAA, AAB, AAC...etc. rather than the easier, if not trivial 
triplets 001, 002, 003, etc.

The AppleScript below does give one necessary clue, namely that the 
mapping of decimal integers to triplets, for example 2 = AAA, 3 = AAB, 
4 = AAC and so on, involves the conversion of a decimal number to a 
26-based number. A further wrinkle is that A = STR$(65), not STR$(0) 
and Z = STR$(90), not STR$(25) which complicates matters further....

Whereupon, things get very misty and I reach for the 500mg Tylenol...

Thanks Adam for a start....


On Jun 11, 2005, at 09:37 PM, Steve Crossman wrote:

> Ok, my curiosity is up and I didn't google search this. But what is 
> the purpose of this function.  Saving bytes ? Some form of encryption?
>
>
> ~ steve
> On Jun 11, 2005, at 6:24 PM, Adam Bell wrote:
>
>> This works for me; Sorry it's an AppleScript, but you can see how it 
>> goes;
>>
>> set triplet to "UGK"
>> set digits to {}
>> repeat with k from 1 to 3
>>     set digits to digits & ((ASCII number of character k of triplet) 
>> - 65)
>> end repeat
>> set answer to 676 * (item 1 of digits) + 26 * (item 2 of digits) + 
>> (item 3 of digits) + 1
>>
>> == 13687
>>
>>
>>> 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:
>>> ----------------------------------
>>> clear local
>>> local fn tripLetsFromNums$(myNum as long)
>>> dim tripLets AS STR15
>>>
>>> select aFolderNum
>>> case 1
>>> tripLets =  "000"
>>> case 2
>>> tripLets =  "AAA"
>>> case 3
>>> tripLets =  "AAB"
>>> case 4
>>> tripLets =  "AAC"
>>> //and on and on ad nauseam until ZZZ is reached.
>>> end select
>>> end fn = tripLets
>>> ---------------------------
>>>
>>> Now, using the fact that the letters A to Z are represented by the 
>>> ASCII values 65 to 90 (Str$(65) = "A"  to Str$(90) = "Z") can a more 
>>> elegant and faster mathematical method be used to calculate 
>>> tripLets?
>>>
>>> What would the analagous reverse process (fn 
>>> numsFromTripLets&(tripLets AS STR15)) look like?
>>>
>>> The math/logic eludes me....
>>>
>>> Cheers,
>>>
>>> ----------------------------
>>> Michael Evans
>>> [SFSG] [HBPW]
>>> ----------------------------
>>>
>>> --
>>>
>>
>> --
>> To unsubscribe, send ANY message to: 
>> futurebasic-unsubscribe@...
>
> --
>
>
Cheers,

----------------------------
Michael Evans
[SFSG] [HBPW]
----------------------------