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:0:1:0:0 4,0,2,1,3
4:0:1:1:0 4,0,2,3,1
4:0:2:0:0 4,0,3,1,2
4:0:2:1:0 4,0,3,2,1
4:1:0:0:0 4,1,0,2,3
4:1:0:1:0 4,1,0,3,2
4:1:1:0:0 4,1,2,0,3
4:1:1:1:0 4,1,2,3,0
4:1:2:0:0 4,1,3,0,2
4:1:2:1:0 4,1,3,2,0
4:2:0:0:0 4,2,0,1,3
4:2:0:1:0 4,2,0,3,1
4:2:1:0:0 4,2,1,0,3
4:2:1:1:0 4,2,1,3,0
4:2:2:0:0 4,2,3,0,1
4:2:2:1:0 4,2,3,1,0
4:3:0:0:0 4,3,0,1,2
4:3:0:1:0 4,3,0,2,1
4:3:1:0:0 4,3,1,0,2
4:3:1:1:0 4,3,1,2,0
4:3:2:0:0 4,3,2,0,1
4:3:2:1:0 4,3,2,1,0
Constrains:
- No lambda functions or their helpers, including but not limited to
REDUCE
,MAP
,etc. Named functions without lambda/lambda helper functions are allowed. - No brute forcing. Need a dry, scalable solution. For eg, I might need a corresponding permutation for "5:4:0:0:0:1:0" for input#1 of
0,1,2,3,4,5,6
- Must be
ARRAYFORMULA
solution inB2
, which will fill all ofB2:B
for correspondingA2:A
(noBYROW
) - No workarounds. It maybe be a XY problem. I still need to solve
Y
, and notX
. - Should go without saying, but No scripts
- Should be able to handle 8P8(40320)factoradic numbers without issues
- Recursion allowed. Turning on Iterative calculation not allowed.
Explanation:
Indexes start from 0
instead of 1
. For Input#1
, 0,1,2
,
For A2
, 0:0:0
, for the first 0
, remove 0th element 0
. The remaining array is 1,2
. For the second 0, remove 0th element 1
from the remaining 1,2
. For the third 0
, remove 0th element 2
. The final result 0,1,2
for 0:0:0
. For 0:1:0
:
index(from input#2) | remaining input#1 | output |
---|---|---|
0 | 0,1,2 ^ ^ ^ [0],1,2 <<< Index |
0 |
1 | 1,2 ^ ^ 0,[1] <<< Index |
2 |
0 | 1 ^ [0] <<< Index |
1 |
What can be assumed:
- Input#1 will always be ascending sequence.
- Length of input#1 will be equal to length of each of input#2
What cannot be assumed:
- Number of elements will always be 3. No it may be so much more.
What have I tried?
Many things for days. The closest I got was a direct approach. But it's inefficient and most importantly, doesn't support arrays. I did it with named functions. Note the order of arguments matter. For eg, in SPLICE
, the first argument should be a arr
, then i
and then j
, exactly in that order as shown above.
SHIFT(arr)
Description:
- Removes first element in a array
Arguments:
arr
A vertical array to remove the first element eg:{1;2;3}
Formula definition:
=FILTER(arr,{0;SEQUENCE(ROWS(arr)-1)})
- Example:
=SHIFT({1;2;3})
returns {2;3}
SPLICE(arr,i,j)
Description:
- Removes a part of the array.
Arguments(in order):
arr
A vertical arrayi
Starting index to splice(inclusive)j
Ending index to splice(exclusive)
Formula definition:
=FILTER(arr,LAMBDA(seq,(seq<i)+(seq>=j))(SEQUENCE(ROWS(arr))))
- Example:
=SPLICE({1;2;3;4;5},2,4)
removes second to the fourth element. Returns{1;4;5}
FACTTOPERM(inparr,factarr)
Description:
- Returns corresponding permutation from factorial.
Arguments(in order):
inparr
Vertical input array (Eg:{0;1;2}
)factarr
Vertical Factorial array+1 (Eg:{0;1;0}+1
)
Formula definition:
=IF(ISERROR(JOIN(,inparr)),,INDEX(inparr,INDEX(factarr,1))&FACTTOPERM(SPLICE(inparr,INDEX(factarr,1),INDEX(factarr,1)+1),SHIFT(factarr)))
- Example:
=ARRAYFORMULA(FACTTOPERM({0;1;2},{0;1;0}+1))
will give 021
, because as seen in the above table, 0:1:0
corresponds to 0,2,1
.
I can use BYROW
to call it repeatedly, but it quickly hits lambda limitations. Here's how I used BYROW
to call it:
(A1)Input#2 | Output | 0,1,2 | Formula in C column |
---|---|---|---|
0:0:0 | 0,1,2 | 012 | =ARRAYFORMULA(BYROW(A2:A7,LAMBDA(row, FACTTOPERM(TRANSPOSE(SPLIT(C1,",")),TRANSPOSE(SPLIT(row,":")+1))))) |
0:1:0 | 0,2,1 | 021 | |
1:0:0 | 1,0,2 | 102 | |
1:1:0 | 1,2,0 | 120 | |
2:0:0 | 2,0,1 | 201 | |
2:1:0 | 2,1,0 | 210 |