Really awesome, Raul... thanks
and it solves the bug at the bottom,
1 0 1 mix ,: 0 4 0 3 0 0 4 0
1 4 1 3 0 0 4 0
0 4 1 3 1 0 4 0
0 4 0 3 0 1 4 1
For those who want to follow along (I still don't get . )
3 0 0 3 (] (+"1/ ] *"1/) [ {.~"1 0 (-@}. i.@>:)&{:&$) 1 0 1 mix ,: 0 0 0 0 0 0
3 0 0 3 (] (+"1/ ] 1 - +./ .*&:*"1/) [ {.~"1 0 (-@}. i.@>:)&{:&$) 1 0 1 mix ,:
0 0 0 0 0 0
3 0 0 3 (] (+"1/ [ 1 - +./ .*&:*"1/) [ {.~"1 0 (-@}. i.@>:)&{:&$) 1 0 1 mix ,:
0 0 0 0 0 0
3 0 0 3 (] (+"1/ #~&(,/) 1 - +./ .*&:*"1/) [ {.~"1 0 (-@}. i.@>:)&{:&$) 1 0 1
mix ,: 0 0 0 0 0 0
to generate the langford strings for n =4
strbracket =: 0&{@:[ , ] , 1&{@:[
mix ((&.>)/)(>@:) ((0 <@$~ 1 , +:) ,~ [: |.@:(((2#[)strbracket 0#~])each)
>:@i.) 4
4 1 3 1 2 4 3 2
2 3 4 2 1 3 1 4
----- Original Message -----
From: Raul Miller <[email protected]>
To: Programming forum <[email protected]>
Cc:
Sent: Saturday, July 25, 2015 2:03 PM
Subject: Re: [Jprogramming] Langford strings and interleaving utility
This seems to be a bit more concise than mixes, and I think it
accomplishes the same thing:
mix=: ] (+"1/#~&(,/)1-+./ .*&:*"1/) [ {.~"1 0 (-@}. i.@>:)&{:&$
Thanks,
--
Raul
On Sat, Jul 25, 2015 at 1:29 PM, 'Pascal Jasmin' via Programming
<[email protected]> wrote:
> 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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm