Skip to main content
added 7 characters in body
Source Link

Authors: AlvordBossCerovskiCyrEllerHuiLambertMillerQuintanaSchottSherlockTaylorTherriaultAlvordBossCerovskiCyrEllerHuiLambertMcCormickMillerQuintanaSchottSherlockTaylorTherriault

Finally, the leftmost token " |: " transposes the result of the preceding verbs to its right.

Explanation provided by Devon McCormick. Thank you Devon.

Authors: AlvordBossCerovskiCyrEllerHuiLambertMillerQuintanaSchottSherlockTaylorTherriault

Finally, the leftmost token " |: " transposes the result of the preceding verbs to its right.

Authors: AlvordBossCerovskiCyrEllerHuiLambertMcCormickMillerQuintanaSchottSherlockTaylorTherriault

Finally, the leftmost token " |: " transposes the result of the preceding verbs to its right.

Explanation provided by Devon McCormick. Thank you Devon.

Explanation

J phrases are executed starting on the right, passing the on-going result to the left as it gets evaluated. Since it's interactive, we can look at pieces of the solution in isolation to better understand them.

The middle part generates the upper and lower case alphabet in Unicode:

   u:,2#65 97+/i.26
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz

The " u: " verb converts its numeric right argument to Unicode characters. The numeric argument is generated from the ASCII values for the upper- and lower-case characters by adding the numbers for "A" and "a" each to the values from 0 to 25 generated by "i.26":

   65 97+/i.26
65 66 67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122

The right-hand portion,

   ((>:@i.}.[)])"0

looks up ( i. ) the position of the right argument ( ] ) in the left ( [ ) - which is the vector of letters above - and drops ( }. ) one more ( >: ) than that number. The ' "0 ' applies this phrase to 0-dimensional (scalar) arguments.

   ('123H999' (>:@i.}.[)])"0 'H'
999

The " 25 {. " phrase takes the first 25 elements of the vector on the right.

The penultimate phrase " 1j1 # " on the left replicates its right argument according the number on the left. A simple number does a simple replication:

   2 # 'ABCD'
AABBCCDD

However, a complex number - indicated by the " j " between the real and imaginary portions - inserts a fill element according to the imaginary part. Here we indicate one fill element by the one to the right of the " j ".

   2j1 # 'ABCD'
AA BB CC DD 

As with most J primitives, the replicate verb ( # ) works on numeric arrays in an analagous fashion to how it works on character arrays. As shown here,

   1j1 # 1 2 3
1 0 2 0 3 0

we see that the default numeric fill element is zero whereas for characters it is the space character.

Finally, the leftmost token " |: " transposes the result of the preceding verbs to its right.

Explanation

J phrases are executed starting on the right, passing the on-going result to the left as it gets evaluated. Since it's interactive, we can look at pieces of the solution in isolation to better understand them.

The middle part generates the upper and lower case alphabet in Unicode:

   u:,2#65 97+/i.26
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz

The " u: " verb converts its numeric right argument to Unicode characters. The numeric argument is generated from the ASCII values for the upper- and lower-case characters by adding the numbers for "A" and "a" each to the values from 0 to 25 generated by "i.26":

   65 97+/i.26
65 66 67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122

The right-hand portion,

   ((>:@i.}.[)])"0

looks up ( i. ) the position of the right argument ( ] ) in the left ( [ ) - which is the vector of letters above - and drops ( }. ) one more ( >: ) than that number. The ' "0 ' applies this phrase to 0-dimensional (scalar) arguments.

   ('123H999' (>:@i.}.[)])"0 'H'
999

The " 25 {. " phrase takes the first 25 elements of the vector on the right.

The penultimate phrase " 1j1 # " on the left replicates its right argument according the number on the left. A simple number does a simple replication:

   2 # 'ABCD'
AABBCCDD

However, a complex number - indicated by the " j " between the real and imaginary portions - inserts a fill element according to the imaginary part. Here we indicate one fill element by the one to the right of the " j ".

   2j1 # 'ABCD'
AA BB CC DD 

As with most J primitives, the replicate verb ( # ) works on numeric arrays in an analagous fashion to how it works on character arrays. As shown here,

   1j1 # 1 2 3
1 0 2 0 3 0

we see that the default numeric fill element is zero whereas for characters it is the space character.

Finally, the leftmost token " |: " transposes the result of the preceding verbs to its right.

added 1 characters in body
Source Link

J 43

|:1j1#(25{.(u:,2#65 97+/i.26)(>:@i.}.[)])"0

Examples:

|:1j1#(25{.(u:,2#65 97+/i.26)(>:@i.}.[)])"0 's'

t u v w x y z a b c d e f g h i j k l m n o p q r

|:1j1#(25{.(u:,2#65 97+/i.26)(>:@i.}.[)])"0 's.'

t
u
v
w
x
y
z
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r

|:1j1#(25{.(u:,2#65 97+/i.26)(>:@i.}.[)])"0 '['

This solution evolved on the J programming forum: http://jsoftware.com/pipermail/programming/2012-August/029072.htmhttp://jsoftware.com/pipermail/programming/2012-August/029072.html

Authors: AlvordBossCerovskiCyrEllerHuiLambertMillerQuintanaSchottSherlockTaylorTherriault

J 43

|:1j1#(25{.(u:,2#65 97+/i.26)(>:@i.}.[)])"0

Examples:

|:1j1#(25{.(u:,2#65 97+/i.26)(>:@i.}.[)])"0 's'

t u v w x y z a b c d e f g h i j k l m n o p q r

|:1j1#(25{.(u:,2#65 97+/i.26)(>:@i.}.[)])"0 's.'

t
u
v
w
x
y
z
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r

|:1j1#(25{.(u:,2#65 97+/i.26)(>:@i.}.[)])"0 '['

This solution evolved on the J programming forum: http://jsoftware.com/pipermail/programming/2012-August/029072.htm

Authors: AlvordBossCerovskiCyrEllerHuiLambertMillerQuintanaSchottSherlockTaylorTherriault

J 43

|:1j1#(25{.(u:,2#65 97+/i.26)(>:@i.}.[)])"0

Examples:

|:1j1#(25{.(u:,2#65 97+/i.26)(>:@i.}.[)])"0 's'

t u v w x y z a b c d e f g h i j k l m n o p q r

|:1j1#(25{.(u:,2#65 97+/i.26)(>:@i.}.[)])"0 's.'

t
u
v
w
x
y
z
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r

|:1j1#(25{.(u:,2#65 97+/i.26)(>:@i.}.[)])"0 '['

This solution evolved on the J programming forum: http://jsoftware.com/pipermail/programming/2012-August/029072.html

Authors: AlvordBossCerovskiCyrEllerHuiLambertMillerQuintanaSchottSherlockTaylorTherriault

deleted 40 characters in body
Source Link
Loading
Source Link
Loading