[Jprogramming] Project Euler 16, J vs Haskell
Skip Cave
skip at caveconsulting.com
Wed May 28 18:32:09 UTC 2014
Is this terse enough for you?
a =. 2^1000x
+/".,' ',.~a
1366
Skip
Skip Cave
Cave Consulting LLC
On Wed, May 28, 2014 at 1:02 PM, Devon McCormick <devonmcc at gmail.com> wrote:
> In general, I've noticed that Haskell is often J's closest rival in terms
> of terseness. However, based on my admittedly slight acquaintance with
> Haskell, it does not seem as general or as well-thought-out notationally as
> J is but this latter point is true of almost all other languages.
>
>
> On Wed, May 28, 2014 at 11:35 AM, Jon Hough <jghough at outlook.com> 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
> >
>
>
>
> --
> Devon McCormick, CFA
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
More information about the Programming
mailing list