Some J translations of some of the flat array programming techniques discussed in this article series: -
- Part 1: https://saltysylvi.github.io/blog/flat1.html
- Part 2: https://saltysylvi.github.io/blog/flat2.html
Reverse words
s =. 'here are some words'
p =. +/\ 0, 2 ~:/\ ' ' = s
echo s {~ |. \: p
NB. ==> ereh era emos sdrow
Mesh
x =. 'abcd'
y =. 'XYZ'
g =. 0 0 1 0 1 1 0
echo (/: /: g) { x, y
NB. ==> abXcYZd
Expand
Expand =: {{ (/: /: x) { (- # x) {. y }}
Expand =: /:@/:@[ { ] {.~ -@#@[
echo 1 0 0 1 0 1 Expand 97 98 99
NB. ==> 97 0 0 98 0 99
Partitioned reverse
p =. 1 0 0 0 1 0 1 0 0
b =. 'abcdijxyz'
Pr =: {{ y {~ |. \: +/\ x }}
echo p Pr b
NB. ==> dcbajizyx
Partitioned plus-fold
b =. 1 2 3 4 100 200 9 10 11
Ppf =: {{ 2 -~/\ 0, (1 |. x) # +/\ y }}
echo p Ppf b
NB. ==> 10 300 30