« first day (1893 days earlier)      last day (769 days later) » 

3:21 AM
The following will also work
)wsid newname
)save
 
 
10 hours later…
1:45 PM
Hi, I'm having a go at this golfing question: https://codegolf.stackexchange.com/questions/239999/group-elements-by-their-displacement
Here's my solution, which seems to work:
{dist←|⍵-⍳⍴⍵ ⋄ dist ⊆⍥((⊂⍋dist)∘⌷) ⍵}t
The repeated dist makes me think there's an opportunity to shorten things with a fork or operator, but I can't quite manage to get there. Any suggestions welcome!
 
I don't think so. You'd want {(|⍵-⍳⍴⍵) ⊆{(⍺ ⍵⍵ ⍺) ⍺⍺ (⍺ ⍵⍵ ⍵)}(⌷⍨∘(⊂⍋)⍨) ⍵} which can't be expressed neatly afaik
{(|⍵-⍳⍴⍵) (⊆/⊂⍤⊣(⌷⍨∘(⊂⍋)⍨)¨,⍥⊂) ⍵} is an option but it isn't pretty
(⊃ ⊢(⊆/⊂⍤⊣⌷⍨∘(⊂⍋)⍨¨,⍥⊂)⍨∘|⊢-⍳⍤⍴)
 
2:03 PM
how about ⋄f←⊢∘⊂⌸|∘(⊢-⍳∘≢)⋄f 2, 5, 3, 1, 4, 6
 
@KamilaSzewczyk
┌───┬───┬───┐
│1 5│2 4│3 6│
└───┴───┴───┘
 
2:18 PM
@FawnLocke Thank you! I'm going to have to spend a little while puzzling that out but it does seem to be what I was after!
@KamilaSzewczyk I think that does something slightly different, I don't get the same answer when I apply it to the test case.
(I've realised that my solution fails if the distance between an element an its index is 0, because then it's dropped by ⊆. But it can be fixed by adding 1 to all elements of dist.)
Thanks both for your help, have a good day!
 
You too :)
 
@andycraig the order can be different
 

« first day (1893 days earlier)      last day (769 days later) »