> -----Original Message-----
> From: programming-boun...@forums.jsoftware.com [mailto:programming-
> boun...@forums.jsoftware.com] On Behalf Of Martin Saurer
> Sent: Friday, March 7, 2014 2:12 PM
> To: programm...@jsoftware.com
> Subject: Re: [Jprogramming] J in 5 minutes
> 
> Hello all Jers,
> My two cents (or 15 minutes) to show what J can do.

> https://www.youtube.com/watch?v=VSJpJt3c11c

Quite nice!
There are some things I find slightly misleading, but before I list them, I
acknowledge the fact that some might be conscious choices to avoid possible
confusion in an unprepared audience. This said...
About Euler problem 1.
Why use "E." and not the simpler "="? I can see that "=" can be "misleading"
(to quote myself), but "=" is so common in J that one might as well get used
to it from the beginning.
So, my first suggestion would be to recast the solution as:
   +/ (i.1000) * (0 = 3|i.1000) +. (0 = 5|i.1000)
Then, the similarity of the expressions in the brackets screams to me to be
re-factored as:
   0 = 3 5|/i.1000
to get to:
   +/ (i.1000) * +./0 = 3 5|/i.1000

Here I can see, even more than before, that this is overloading the meaning
of "/". Still, in Euler 20 you go for an explicit rank, which you could use
here to remove the ambiguity on the last "/".

    +/ (i.1000) * +./0 = 3 5|"0 _ ] i.1000

The cost for the beginner is the introduction of the bizzare "]" (which can
be replaced safely with a + here):
   +/ (i.1000) * +./0 = 3 5|"0 _ + i.1000

and an early exposure to a reduction of a multidimensional array (the +./).
Pros and cons...


About Euler problem 20.
If I had to write the code I'd definitely not  go for the ,"0 and the
execute. Instead I would:

    +/'0123456789' i. ": !100x
648
which I find more idiomatic. 

Or I would even go as far as using the inverse of 10 base. In other words,
I'd show that:

    10 #.^:_1 ]  134898
1 3 4 8 9 8
leads naturally to 
   +/ 10 #.^:_1  !100x
648

My 1c worth....

All the best,
-- 
Stefano

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

Reply via email to