r€⁸Œp»\QṚ
オンラインでお試しください!
どうやって?
r€⁸Œp»\QṚ - Link: integer, N e.g. 4
€ - for €ach of implicit range of N (i.e. for i in [1,2,3,...N])
⁸ - with the chain's left argument, N on the right:
r - inclusive range (for i<=N this yields [i, i+1, ..., N]
- ...leaving us with a list of lists like the post-fixes of [1,2,3,....,N]
- e.g. [[1,2,3,4],[2,3,4],[3,4],[4]]
Œp - Cartesian product* of these N lists
- e.g. [[1,2,3,4],[1,2,4,4],[1,3,3,4],[1,3,4,4],[1,4,3,4],[1,4,4,4],[2,2,3,4],[2,2,4,4],[2,3,3,4],[2,3,4,4],[2,4,3,4],[2,4,4,4],[3,2,3,4],[3,2,4,4],[3,3,3,4],[3,3,4,4],[3,4,3,4],[3,4,4,4],[4,2,3,4],[4,2,4,4],[4,3,3,4],[4,3,4,4],[4,4,3,4],[4,4,4,4]]
\ - cumulative reduce with:
» - maximum (vectorises)
- e.g. [[1,2,3,4],[1,2,4,4],[1,3,4,4],[1,3,4,4],[1,4,4,4],[1,4,4,4],[2,4,4,4],[2,4,4,4],[2,4,4,4],[2,4,4,4],[2,4,4,4],[2,4,4,4],[3,4,4,4],[3,4,4,4],[3,4,4,4],[3,4,4,4],[3,4,4,4],[3,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]]
Q - de-duplicate e.g. [[1,2,3,4],[1,2,4,4],[1,3,4,4],[1,4,4,4],[2,4,4,4],[3,4,4,4],[4,4,4,4]]
Ṛ - reverse e.g. [[4,4,4,4],[3,4,4,4],[2,4,4,4],[1,4,4,4],[1,3,4,4],[1,2,4,4],[1,2,3,4]]
*上記で使用したデカルト積で何が起こっているかを別の入力で簡単に確認できます。
the Cartesian product of [[0,1,2],[3,4],[5]]
is [[0,3,5],[0,4,5],[1,3,5],[1,4,5],[2,3,5],[2,4,5]]
i
thは常に1インデックス付きであると明示的に述べたい場合があります。