;: – sequential machine to read 50 states into 50 row x 13 char box array
> opens boxed array to table
i=.("1#])50 50#: i.*:50 - builds a 1225 x 2 array of numbers 0 1
0 2
.
.
46 47
46 48
46 49
47 48
47 49
48 49
array i has no double numbers – no double state names
i has no transposed copies of pairs (i.e. 47, 46) – no transposed state names
[ – yield left ~ a line continuation (reversed lines)
i{st – cartesian product between array i and array st
,“2 – rank 2 append across elements
(3d array => 2d array of doubleword states)
/:~“1 – rank 1 sort characters for each doubleword state
<"1 - rank 1 box for each char sorted doubleword a
in array i applied to each collection of array i
having identical keys
> – open boxed array to table
2=#& – if 2 = tally bond (tally currying)
#] – yield the left argument tally
AnonymousJ - 2007-11-03 12:41:55
Implementation in J
st=:>;:‘alabama alaska arizona arkansas california colorado connecticut delaware florida georgia hawaii idaho illinois indiana iowa kansas kentucky louisiana maine maryland massachusetts michigan minnesota mississippi missouri montana nebraska nevada newhampshire newjersey newmexico newyork northcarolina northdakota ohio oklahoma oregon pennsylvania rhodeisland southcarolina southdakota tennessee texas utah vermont virginia washington westvirginia wisconsin wyoming’
((2=#&>)#])a
——-
|32 40|
|33 39|
——-
32 40 { st
northcarolina
southdakota
30 39 { st
newmexico
southcarolina
Timed run
10(6!:2) ’((2=#&>)#])a (Ctrl+D exits)
notes
——-
j601 Release
Modified solution from a post at the following link
http://www.jsoftware.com/pipermail/chat/2007-April/000468.html
;: – sequential machine to read 50 states into 50 row x 13 char box array
> opens boxed array to table
i=.("1#])50 50#: i.*:50 - builds a 1225 x 2 array of numbers 0 1
0 2
.
.
46 47
46 48
46 49
47 48
47 49
48 49
array i has no double numbers – no double state names
i has no transposed copies of pairs (i.e. 47, 46) – no transposed state names
[ – yield left ~ a line continuation (reversed lines)
i{st – cartesian product between array i and array st
,“2 – rank 2 append across elements
(3d array => 2d array of doubleword states)
/:~“1 – rank 1 sort characters for each doubleword state
<"1 - rank 1 box for each char sorted doubleword a in array i applied to each collection of array i
having identical keys
> – open boxed array to table
2=#& – if 2 = tally bond (tally currying)
#] – yield the left argument tally
AnonymousJ - Sat 03 Nov 2007 12:46:56
Malformed post. There should be a less than symbol right after i=.(, in place of the <
((2=#&>)#])a
AnonymousJ - Sat 03 Nov 2007 12:54:45
One more time, quotes and double quotes needed retyping
st=:>;:'alabama alaska arizona arkansas california colorado connecticut delaware florida georgia hawaii idaho illinois indiana iowa kansas kentucky louisiana maine maryland massachusetts michigan minnesota mississippi missouri montana nebraska nevada newhampshire newjersey newmexico newyork northcarolina northdakota ohio oklahoma oregon pennsylvania rhodeisland southcarolina southdakota tennessee texas utah vermont virginia washington westvirginia wisconsin wyoming'
((2=#&>)#])a</.i[a=.<"1/:~"1,"2 i{st[i=.(</"1#])50 50#:i.*:50