Ambrus wrote:
> round =: p:@:(i.>./)@:(_&q:)"0

Raul wrote:
> I would have done something like:
>    roundest=: p:@(i. >./)@(+/)@:q:~&_

Let us recall that composite numbers can also serve as bases (e.g. 2*5).
The "roundest base" may indeed be composite number, so we have to consider
all the divisors of the inputs, not just the prime factors.  So, using the
Roger's divisors function [1]:

           div  =:  /:~ @: , @: > @: (*/&.>/) @: ((^ i.@>:)&.>/) @: (__&q:)
           rb   =:  [: >./@:(; #~ (= >./)@:(+/)@:e.) div&.>  
        
           rb 10 100 10000
        10
           rb 10 * 10 100 10000
        100
           rb 16b10 16b100000000 16b10000  
        16
           
>  Six trailing zeros [using base 3], where a base of 2 would give four
trailing zeros.

This is on the right track.  The verb (rb) above is still too strict:

           rb  90 10 54 6
        2

Because its criterion is "the most common divisor", not "the divisor which
will maximize the # of trailing zeros".  But I'm not sure how to modify it
to achieve the latter.  It has all the information it needs, the candidate
divisors and their relative frequencies, but what weighting function would
one use to maximize trailing zeros?

-Dan       

[1]  http://www.jsoftware.com/jwiki/Essays/Divisors 

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

Reply via email to