Skip to content

Instantly share code, notes, and snippets.

@0racle
Last active April 8, 2025 12:39
Show Gist options
  • Save 0racle/b6a4e2108595d981a3791fadc5b7c2c6 to your computer and use it in GitHub Desktop.
Save 0racle/b6a4e2108595d981a3791fadc5b7c2c6 to your computer and use it in GitHub Desktop.
Flat Array Programming

Some J translations of some of the flat array programming techniques discussed in this article series: -

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment