One last tweak (watch line wrap):

    conv =. ((,~ $`($:@<:)@.*)~ {&'ABCDEFGHIJKLMNOPQRSTUVWXYZ')/@(_ 26&#:)"0

Henry Rich

On 12/16/2010 7:20 PM, Henry Rich wrote:
> Having spent more time than I should have on this, I offer
>
>      numtocol =. ($`($:@<:)@....@{. , {:)@(_ 26&#:)
>      col =. ('ABCDEFGHIJKLMNOPQRSTUVWXYZ' {~ numtocol)"0
>
> Henry Rich
>
> On 12/16/2010 3:31 PM, Tracy Harms wrote:
>> I encountered the question of how to produce the alphabetic label for a
>> given column in Excel. I enjoyed analyzing the problem, and I enjoyed coding
>> a solution in J.
>>
>> I notice that I have difficulty "ironing out" the program I've written.
>> There is a need to use several calculated results more than once and I'm not
>> particularly happy with how these are structured in the program I've
>> written, especially the last half.
>>
>> What I'd particularly like is to have the "central" calculation shine
>> through more visibly. I'm thinking about
>>     (howmany # Base) #: Value
>>
>> Would anybody like to restructure this, or provide alternative solutions to
>> this problem?
>>
>> --
>> Tracy
>>
>>
>>
>> convert=: 3 : 0
>>     Base  =. # Digits=. 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
>>     offset=. [:+/ [^ [:>: i.@:]
>>     om    =. ( * 0<]) @<. @ ^. NB. order of magnitude, in chosen base (x)
>>     OM    =. Base om y
>>     Value =. ( -  Base offset"0 OM"_ ) y
>>    ((OM + _1<Value) #&.>   Base ) (Digits{~ #: )&>   Value
>> )
>>
>> NB. 'example execution
>>      convert (] , (24+]) , (700+])) i.4
>> A
>> B
>> C
>> D
>> Y
>> Z
>> AA
>> AB
>> ZY
>> ZZ
>> AAA
>> AAB
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to