-3 thanks to Nick Kennedy reminding me to golf the magic table.
⁾abp`”cṭŒ!F=¥Þ⁸ṪṪ
A full program that accepts the flattened, redacted permutation and prints the missing item.
Try it online! Or see all twenty four of each of the five choices here.
How?
Brute force...
⁾abp`”cṭŒ!F=¥Þ⁸ṪṪ - Link: list of characters, X
⁾ab - "ab"
p` - Cartesian product with itself -> ["aa","ab","ba","bb"]
”cṭ - tack 'c' character -> ["ab","ba","bb","aa",'c']
Œ! - all permutations
Þ - sort by:
¥ ⁸ - last two links as a dyad - f(Permutation, X):
F - flatten the Permutation
= - equals X (vectorised)
Ṫ - tail -> permutation with matching prefix
Ṫ - tail -> the missing pair
- implicit print
Non-brute-force 21 bytes
I quite like this non-brute force method at 21 bytes though (maybe it can be improved upon?)...
ḟ”cOḤÐoS;Ḥ$%5Qị“bbaac
A full program that accepts the flattened, redacted permutation and prints the missing item.
Try it online! Or see all twenty four of each of the five choices here.
How?
ḟ”cOḤÐoS;Ḥ$%5Qị“bbaac - Main Link: list of characters
ḟ”c - remove any 'c' character
O - cast to ordinal values ('a' -> 97, 'b' -> 98)
Ðo - apply to odd indices (first, third, ...):
Ḥ - double
S - sum
;Ḥ$ - concatenate double this value -> [sum, 2×sum]
%5 - modulo five -> [sum%5, (2×sum)%5]
Q - deduplicate
ị“bbaac - index into "bbaac"
Examples:
1. missing "c" "aaabbbba"
-> "aaabbbba"
(removed 'c'
; no change)
-> [97,97,97,98,98,98,98,97]
(cast to ordinals)
-> [194,97,194,98,196,98,194,97]
(double values at odd indices)
-> 1170
(sum those)
-> [1170, 2340]
(concatenate double itself)
-> [0, 0]
(modulo five)
-> [0]
(deduplicate)
-> "c"
(index into "bbaac" - Note that indexing is one-based and modular)
2. missing "bb" "aaacbba"
-> "aaabba"
(removed 'c'
)
-> [97,97,97,98,98,97]
(cast to ordinals)
-> [194,97,194,98,196,97]
(double values at odd indices)
-> 876
(sum those - i.e. \$1170 - (2 \times 98) - 98 = 876\$)
-> [876, 1752]
(concatenate double itself)
-> [1, 2]
(modulo five)
-> [1, 2]
(deduplicate; no change)
-> "bb"
(index into "bbaac")
"c "
instead of"c"
okay? \$\endgroup\$c
\$\endgroup\$