for a description of langford strings,
https://www.reddit.com/r/dailyprogrammer/comments/3efbfh/20150724_challenge_224_hard_langford_strings/
a cool utility to solve this is a data interleaver
mixes =: ([: >@:(( 0 <@#~ # every@{.@,)-.~ , )@:(<"1) ] ( ( ~.@:, (] #~
*./@e.~) +/"3@:,:)"1 1"1 2) [ {.~"1 0 {:@$@{.@] ([ -@- i.@>:@-) #@[)
NB. not needed but also provides reverses of interleaves.
langf =: (|."1 ~.@:, ])@:mixes
1 0 1 mixes ,: 0 4 0 4 0 0 4 0
0 4 0 4 0 1 4 1
0 4 1 4 1 0 4 0
1 4 1 4 0 0 4 0
returns all of the ways to overlap one list onto another. Including if the
right argument is a list of lists.
2 0 0 2 mixes 1 0 1 mixes 4 0 0 0 0 4 mixes ,: 0 0 0 0 0 0 0 0
4 0 1 2 1 4 2 0
4 1 0 1 2 4 0 2
2 4 0 2 0 1 4 1
0 4 0 1 2 1 4 2
2 4 1 2 1 0 4 0
1 4 1 0 2 0 4 2
2 0 4 2 1 0 1 4
0 2 4 1 2 1 0 4
mixes ((&.>)/)(>@:) 4 0 0 0 0 4 ; 3 0 0 0 3 ; 2 0 0 2 ; 1 0 1 ; ,:0 0 0 0 0 0 0
0
2 3 4 2 1 3 1 4
4 1 3 1 2 4 3 2
There's a small bug in the filter part as it checks that the colwise sum is one
of the unique values in either left or right list. The 2nd row below is bad
because 4 is a valid "total".
1 0 1 mixes ,: 0 4 0 3 0 0 4 0
0 4 0 3 0 1 4 1
0 4 0 4 0 1 4 0
0 4 1 3 1 0 4 0
1 4 1 3 0 0 4 0
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm