http://www.jsoftware.com/help/dictionary/d502.htm

Cap as the left tine of a fork does, as you suggest, make the middle verb work as a monad.  Every other time cap is invoked as a verb it signals an error.


Now let's get this right: (footnote *2)

A  B   C  D    E  F G  H      I        J K  L  M  N  O  P  Q
[: <"2 [: |."2 ] {~ [: /:~"1 ([: |. [) $ [: ?~ [: */ [: |. [

If fixed width font not available:

A [:
B <"2
C [:
D |."2
E ]
F {~
G [:
H /:~"1
I ([:|.[)
J $
K [:
L ?~
M [:
N */
O [:
P |.
Q [


The train begins with cap.  We hope the train is a fork because as an hook cap A would be called as the left verb of an hook, which would raise an error.   A through Q inclusively are 17 verbs, an odd number, thus the train is overall a fork.  We know that verb B is the monad "box at rank 2" rather than "less than applied in a clever way".  To me, box at rank 2 on the left means "make the display pretty".

Now let's work from right to left, working in groups of, I'll call it condensed 3, because j treats the right most 3 verbs of a train as a fork and as if it were parenthesized as a single verb.

OPQ: a fork
Q is a dyad (when two arguments are supplied to the train, which they are).  Since it is rightmost on the train Q gets the arguments to the train.
P is a monad because cap O blocks the left hand argument.

MN(OPQ)
N is a monad because of cap M.
N, formed from two words, is the single verb "insert multiply"
N is "insert multiply", and not "product table" because of the cap M.
N inserts multiply into the result of executing OPQ.
Since multiplication commutes, the reversal P isn't useful.
M does not raise an error.  It is the left hand tine of a fork.

KL(MN(OPQ))
K caps L
L is a monad meaning "shuffle the integers i. y"
L is formed from two words, verb and adverb, and the monadic definition of ~ is reflex which evaluates ? as y deal y .

Review:
K though Q deal a deck having size the product of the left hand vector.

IJ(K-Q)
I is a fork evaluated as a dyad.  And being the left-hand tine of a fork it receives the original arguments to the entire train.  Fork I does the same thing as OPQ, reversing the left hand vector x . J, evaluated as a dyad, reshapes the deck.  Additionally we know that the product of the shape is the same size as the deck.  All the numbers are used exactly one time.

GH(I-Q)
H, although called as a monad, invokes dyadic sort due to reflexive adverb ~ .  The sorting takes place at rank 1 because the conjunction tells me so.  Off track, /:"1~ ought to perform faster than /:~"1 because reflex applies just once.

EF(G-Q)
E is a dyad, the left tine of a fork, given the original arguments to the train. F evaluates as the dyad "from".  The adverb in F is the dyadic form, passive, which swaps the arguments.  The result of the G-Q train is an index vector into the list on the right side of the train, its y argument.

Review:
We've now learned much.  E through Q essentially operates like x $ y , with some sort of randomization of y .  There's a new constraint that there must be enough items in y, at least as many as the product of the shape vector x.  And for some still mysterious reason the shape vector is reversed.

CD(E-Q)
D reverses the items, but is fed the rank 2 chunks.  This leads us to a second proposal.  Could the sort H be changed to descending sort and removing CD?  H could be \:"1~ .


Test using fixed seed deal:

   f =: [: <"2 [: |."2 ] {~ [: /:~"1 ([: |. [) $ [: ?.~ [: */ [: |. [

   g =: [: <"2         ] {~ [: \:"1~ ([: |. [) $ [: ?.~ [: */       [

   (13,*:2) (f-:g) deck
1



To which I'd apply the "left hook"* and express the algorithm as

   h =: [: <"2 ({~ [: \:"1~ |. $ [: ?.~ */)~

   (13,*:2) (h-:g)deck
1



   f
[: <"2 [: |."2 ] {~ [: /:~"1 ([: |. [) $ [: ?~ [: */ [: |. [
   g
[: <"2 ] {~ [: \:"1~ ([: |. [) $ [: ?~ [: */ [
   h
[: <"2 ({~ ([: \:"1~ |. $ [: ?~ */))~


   F=:52$'23456789TJQKA'
   S=:(13#'cdhs')
   deck=:S,.F

   (13,*:2) h deck
┌──┬──┬──┬──┐
│sK│sA│sJ│hQ│
│s4│sQ│sT│h8│
│hA│s8│s9│h6│
│hT│s6│s7│h4│
│h2│s5│s3│h3│
│dT│hK│s2│dA│
│d5│hJ│h9│dK│
│d4│h7│h5│dQ│
│d2│dJ│d8│d7│
│cQ│d9│d6│c9│
│cT│cA│d3│c8│
│c3│cK│cJ│c7│
│c2│c6│c5│c4│
└──┴──┴──┴──┘

The result are neatly sorted bridge hands.  Thank you!


* As I see it, sentences with "same" may as well be explicit code.  Hooks can eliminate many cases of ][ .
*2 Set up for errors!


On 10/10/2018 08:00 AM, programming-requ...@forums.jsoftware.com wrote:
Date: Wed, 10 Oct 2018 02:07:38 +0000
From: Linda Alvord<lindaalvor...@outlook.com>
To:"programm...@jsoftware.com"  <programm...@jsoftware.com>
Subject: Re: [Jprogramming] Using rank to avoid looping - reference?
Message-ID:
        
<bn6pr06mb3137aef292e3fd9416c94ee9b5...@bn6pr06mb3137.namprd06.prod.outlook.com>
        
Content-Type: text/plain; charset="utf-8"

Some of these patterns are making it seasier for me to translate from tacit to 
explicit.

    F=:52$'23456789TJQKA'       
    S=:(13#5 4 3 6){a.
    deck=:S,.F
shuf=: 13 :'<"2|."2 y {~ /:~"1 (|.x)$?~*/|.x'
    shuf
[: <"2 [: |."2 ] {~ [: /:~"1 ([: |. [) $ [: ?~ [: */ [: |. [
;:'[: <"2 [: |."2 ] {~ [: /:~"1 ([: |. [) $ [: ?~ [: */ [: |. ['
┌──┬─┬─┬─┬──┬──┬─┬─┬─┬─┬─┬──┬──┬─┬─┬─┬─┬──┬──┬─┬─┬─┬──┬─┬─┬──┬─┬─┬──┬──┬─┐
│[:│<│"│2│[:│|.│"│2│]│{│~│[:│/:│~│"│1│(│[:│|.│[│)│$│[:│?│~│[:│*│/│[:│|.│[│
└──┴─┴─┴─┴──┴──┴─┴─┴─┴─┴─┴──┴──┴─┴─┴─┴─┴──┴──┴─┴─┴─┴──┴─┴─┴──┴─┴─┴──┴──┴─┘
    13 4 shuf deck
┌──┬──┬──┬──┐
│A│T│K│6│
│Q│5│J│4│
│3│J│9│A│
│2│7│8│4│
│Q│6│7│T│
│9│2│K│9│
│8│A│T│4│
│5│K│Q│2│
│3│J│3│A│
│8│J│Q│K│
│7│T│7│9│
│6│8│5│4│
│5│6│2│3│
└──┴──┴──┴──┘
    NB. right to left: [: |. and [: <"2 are monadic
    NB.                [: * / , [:?~ , [:/:~ are dy adic
    NB.                $ and {~ are dyadic
Linda


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

Reply via email to