Not quite as terse (but a useful pattern when working in bases other than 10):
+/10#.inv!100x 648 Thanks, -- Raul On Wed, May 28, 2014 at 11:30 AM, Roger Hui <[email protected]>wrote: > +/ "."0 ": !100x > 648 > > > > On Wed, May 28, 2014 at 8:26 AM, Jon Hough <[email protected]> wrote: > > > Project Euler Question 20 is: > > n! means n (n 1) ... 3 2 1 > > For example, 10! = 10 9 ... 3 2 1 = 3628800, > > > > and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 > = > > 27. > > Find the sum of the digits in the number 100! > > http://projecteuler.net/problem=20 > > > > My solution: > > NB. create the base to split number > > > > > > base =. 200 $ 10 > > > > > > NB. sum all > > > > > > +/ @: (base & #: )@: ! 100x > > > > I get the correct answer with this, but I am wondering if there is a > > terser or more elegant way to get the solution? > > In particular I am not too happy about having to explicitly define the > > base. Is there a better way to convert numbers to arrays of their digits? > > > > > > Regards. > > > > ---------------------------------------------------------------------- > > 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
