There's this (adapted from my new "Array Thinking" page on the J wiki):
   NB. String from https://wiki.c2.com/?LispShowOffExamples
   string=. '(flet ((inside-p (obj) (lambda (d) (inside-p obj (ray-point
ray d)))))'
   string,:' '-.~":'()' ([:+/\1 _1 0{~i.) string    NB. Example result
(flet ((inside-p (obj) (lambda (d) (inside-p obj (ray-point ray d)))))
1111112333333333344443344444444554455555555555555666666666666666654321
   NB. Final "1" indicates we are missing a closing paren
The one-liner is " '()' ([:+/\1 _1 0{~i.) string"; the bit preceding this
simply squishes the parentheses' counts to single, text digits so they
align character-by-character with the string (won't work if the string
presents more than 9 levels of nesting).
Also, that "LISP Show-off" page referenced might be a good source of
succinct algos amenable to translation into J.

Another one I resurrected recently is something I wrote a long time ago in
APL called "interval sum".  Given two two-column tables - "iv0" and "iv1" -
of start, stop points defining intervals, this expression returns the
(#iv0) x #iv1 table of intersections between each interval.  This is
positive for intervals that overlap, negative for disjunct intervals
(measuring the gap between them), and zero for intervals that share only
one endpoint.  So, for example:

   (iv0=. 0 5,_1 4,2 3,6 3,5 8,:6 8);iv1=. _1 0,1 3,0 5,_1 8,:9 10
+----+-----+
| 0 5|_1  0|
|_1 4| 1  3|
| 2 3| 0  5|
| 6 3|_1  8|
| 5 8| 9 10|
| 6 8|     |
+----+-----+

   iv0 (([:|: [:/:~"1 [) (([:|:[ 0}~ [:- 0{[) +/ . <./ ]0}~ [:- 0{]) [:|:
[:/:~"1 ]) iv1
 0  2  5 5 _4
 1  2  4 5 _5
_2  1  1 1 _6
_3  0  2 3 _3
_5 _2  0 3 _1
_6 _3 _1 2 _1

The following attempts to illustrate how the inner product " +/ . <./ "
works.  The trick is that we negate the 0th column of each set of intervals
(after sorting so that the starting point of the interval is less than or
equal to the ending point) so that the <./ gives us the negative of the
larger of the two starting points.  I have a marvelous proof of why this
works but the margin is too small to contain it*.

In any case, we see here the two sets of intervals as shown above but with
their initial columns negated and the result of the inner product
positioned in a way to try to make clear what is happening:
+----+-----------------+
||:iv1| 1 _1  0  1  _9 |
|iv0  | 0  3  5  8  10 |
+-----+----------------+
| 0 5 | 0  2  5  5  _4 | (0<.1)+(5<.0)=0; (0<._1)+(5<.3)=2;
(0<.0)+(5<.5)=5...
| 1 4 | 1  2  4  5  _5 | (1<.1)+(4<.0)=1; (1<._1)+(4<.3)=2;
(1<.0)+(4<.5)=4...
|_2 3 |_2  1  1  1  _6 |
|_6 3 |_3  0  2  3  _3 |
|_5 8 |_5 _2  0  3  _1 |
|_6 8 |_6 _3 _1  2  _1 |
+-----+----------------+

*Come to NYCJUG on Tuesday, April 14th to see the proof.



On Sat, Mar 14, 2020 at 3:39 PM R.E. Boss <r.e.b...@outlook.com> wrote:

> IIRC Bron (dearly missed) used to have a page on Jems (= gems in J),
> https://code.jsoftware.com/mediawiki/index.php?title=Essays/Jems&action=edit&redlink=1
> but it is non-existent.
> On https://code.jsoftware.com/wiki/User:Dan_Bron he has (links included)
>
> An Essay on Jems: J-gems. Examples will include ASCII art, ZigZag order,
> evolutes and involutes, EwartShaw's gorgeous solution 5 to the 17014...
> Puzzle (i.e. that (<:@^^:^~2x) -: <:2^127x), Arie Groeneveld's Fibonacci
> rabbit sequence (,#;._1)^:(]`1:), RE Boss' improvement to comb, Statisical
> correlation expressed as (+/@:* % *&(+/)&.:*:)&(- +/%#) (I thought I
> invented it but turns out Oleg has priority), f`g;.1~ 1, 2 ~:/\ h,
> particularly where g involves $: (see REB's use case and potential for
> generalization) and more.
>
>
> R.E. Boss
>
>
> > -----Oorspronkelijk bericht-----
> > Van: Chat <chat-boun...@forums.jsoftware.com> Namens Raul Miller
> > Verzonden: zaterdag 14 maart 2020 20:04
> > Aan: c...@jsoftware.com
> > Onderwerp: Re: [Jchat] J "like-wow"s?
> >
> > I you might convey a bit of advice: I would ask her to pace herself.
> > There's a lot of work and abstraction behind the language and absorbing
> it
> > probably means something like a half hour a day, several days a week,
> for a
> > number of years. And, some naps...
> >
> > Or, that's how I picked it up...
> >
> > Anyways, here's one that I like:
> >
> >    thru=: <. + i.@(+*)@-~
> >
> > Examples might include 10 thru 20 or 100 thru 95.
> >
> > Usually, though, you would accomplish those examples with 10+i.11 or 100-
> > i.6
> >
> > Thanks,
> >
> > --
> > Raul
> >
> > On Sat, Mar 14, 2020 at 12:16 PM 'PMA' via Chat <c...@jsoftware.com>
> > wrote:
> >
> > > Hi, J gurus --
> > >
> > > I hazarded to regale a non-programmer friend with J's (+/i.1000000).
> > > She loved this, so I've followed with a link to NuVoc, and now she
> > > loves that!
> > >
> > > So I want to ask, could y'all suggest a list of maybe a dozen favorite
> > > J one-liners, that I could send too?
> > >
> > > (Somewhere, I've still got one for APL from eons ago.)
> > >
> > > I know you're busy.  Thanks in advance.
> > >
> > > Pete
> > > ----------------------------------------------------------------------
> > > 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
>


-- 

Devon McCormick, CFA

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

Reply via email to