A shorter and clearer constructive method, but unfortunately not faster (I
get a time of ~3s for 12356630 values).

gennames=. [: }.@; (digits {~ [: Base&#.^:_1 [: i. Base&^)&.>@i.

A faster method for generating lists in bases is given below:
NB. x is list of atoms to use ((#x) is base); y length of words
basegen=.4 :'x&([: ,/ ,"0 1/)^:y ,.x'

so
gennames2=.[: ; (<digits) basegen&.> i.

which takes about .4s for input 5 (12356630 names).

Marshall


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Henry Rich
Sent: Thursday, December 16, 2010 7:29 PM
To: Programming forum
Subject: Re: [Jprogramming] increasing-width base conversion (e.g. Excel
column labels)

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

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to