1

I have a problem in APL which involves getting values and scoring them like a poker game. So I used

      CHARS⍸CAR3
 5 29 30  8 29 23  5
34 34 33  2 34  3 34
 6 10 10 15  6 15 15

Which is an integer representation of characters in "deck" of cards I then used

{⍺,⍴⍵}⌸(HAND3[1;]) 

That returns the frequency of each letters index, for example the letter S appears 2 times denoted by the 29 occurring in the second row. I can't figure out how to do this for each row of my matrix which is 3 sets of 3x7 matrices the function only returns the first row

 5 2
29 2
30 1
 8 1
23 1

When I tried to do it for each row, it returns the frequency of all the characters and doesn't do it for each set separately. In short I need it to do the function separately for each Hand of Cards.

Adám
  • 6,573
  • 20
  • 37
cphoenix
  • 19
  • 4

1 Answers1

1

processes the major cells of its argument, which for a vector is the elements, and for a matrix is the rows. So to make process each row of the HANDS3 matrix separately, "split" (monadic ) the matrix into three vectors, and then apply {⍺,⍴⍵}⌸ to each (¨), as follows:

      HANDS3
 5 29 30  8 29 23 55
34 34 33  2 34  3 34
 6 10 10 15  6 15 15
      ↓HANDS3
┌──────────────────┬──────────────────┬──────────────────┐
│5 29 30 8 29 23 55│34 34 33 2 34 3 34│6 10 10 15 6 15 15│
└──────────────────┴──────────────────┴──────────────────┘
      {⍺,⍴⍵}⌸¨↓HANDS3
┌────┬────┬────┐
│ 5 1│34 4│ 6 2│
│29 2│33 1│10 2│
│30 1│ 2 1│15 3│
│ 8 1│ 3 1│    │
│23 1│    │    │
│55 1│    │    │
└────┴────┴────┘

Try it online!

Adám
  • 6,573
  • 20
  • 37
  • I see, the precedence in APL and it's rules elude me. How do you determine when to use the concat/lamenate versus the "each" function?Thank you by the way – cphoenix Mar 12 '18 at 07:51
  • @cphoenix Concatenate (`,[N]`) is used to extend arrays while keeping their rank. Laminate `,[N-0.5]` is used to extend arrays by increasing their rank (but otherwise keeping their shape). Each (`¨`) is an *operator*, which applies its operand function to each element of its argument or to each pair of elements of its arguments. – Adám Mar 12 '18 at 08:52