Jon, a brief note on your point re readability … you can always break J down as 
follows if you require;

   +/ "."0 ": !100x             NB. From Roger
648

   sum=:+/
   digits=:"."0 ":
   factorial=:!
   sum digits factorial 100x
648

.../Rob (is it really very much different to Haskell when transliterated as 
such ?)



On 28/05/2014, at 11:43 PM, Roger Hui <[email protected]> wrote:

>   - Suppose you want the digits to a base different from 10?
>   - Suppose you want the "digits" to a different base?  (e.g. convert
>   seconds to hours, minutes, seconds.)
>   - Suppose you want to insert a function other than plus (+/ is sum, */
>   is product, >./ is maximum, (+%)/ is continued fraction, ...)
>   - etc.
> 
> 
> 
> 
> On Wed, May 28, 2014 at 8:35 AM, Jon Hough <[email protected]> wrote:
> 
>> Project Euler 16 is defined:
>> 215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.What is
>> the sum of the digits of the number 21000?
>> http://projecteuler.net/problem=16
>> 
>> 
>> My J solution:NB. create base
>> base =. 302 $ 10
>> 
>> digitsum =. +/ @:(base & #:)"1@: (1000x &(^~))   digitsum 2
>> As a J beginner, clearly my code is not as terse or as elegant as it could
>> be. But browsing the solution forums I found this Haskell solution:
>> sum $ digits 10 $ 2^1000
>> 
>> I don't know Haskell but the above code pretty much speaks for itself.
>> Clearly the solution is terse, simple and easy to understand.Comparing
>> Haskell to J, it seems one of J's strong points, terseness and rapid
>> program developing, doesn't hold up to Haskell so much as it does against
>> C-style languages.
>> So my question is, what advantages does J hold over Haskell, in terms of
>> speed, terseness etc?
>> 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

Reply via email to