Array permutations
Dukc
ajieskola at gmail.com
Sat Sep 11 19:57:57 UTC 2021
On Saturday, 11 September 2021 at 19:37:42 UTC, Vino wrote:
> Request your help on the below to print the below array as
> "Required output", Was able to get these values
> "[1,2],[2,3],[3,4],[4,5]" by using list.slide(2), need your
> help to get values "1,3],[1,4],[1,5],[2,4],[2,5],[3,5]"
```d
import std;
auto slideEnds(List)(List list, size_t slideLen)
{ return list.slide(slideLen).map!(window => [window.front,
window.back]);
}
void main()
{ auto list = [1,2,3,4,5];
iota(2, list.length)
.map!(slideLen => list.slideEnds(slideLen))
.joiner
.writeln;
}
```
This almost does the trick. It leaves out `[1, 5]` for some
reason I didn't bother to check though.
More information about the Digitalmars-d-learn
mailing list