代码:高尔夫预告牌2022事件的一部分。有关详细信息,请参阅链接的元帖子。
芬是个魔术师精灵。他可以在一组数字上施法术,以产生另一个数字或数列。
他的发明之一是威克咒语。他非常喜欢这个魔法,以至于他把它投射到了每一个看得见的阵列上。现在他需要帮助逆转自己的魔法..。
逆转芬的威克咒语。概括地说,Wick咒语的工作原理如下:
A的正整数n数组,i处的每个项替换为最后一个j元素之和,其中j == 2 ** (trailing zeros of i in binary)。例如,如果输入数组为A = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1],
Wick(A) = [
1, # 1
3, # 1+2
3, # 3
10, # 1+2+3+4
5, # 5
11, # 5+6
7, # 7
36, # 1+2+3+4+5+6+7+8
9, # 9
10, # 9+1
]在这个任务中,您需要反转它,因此如果将Wick(A) = [1, 3, 3, 10, 5, 11, 7, 36, 9, 10]作为输入,您的程序应该输出A = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1]。
适用标准的密码-高尔夫规则。以字节为单位的最短代码获胜。
[] -> []
[999] -> [999]
[3,4,4] -> [3,1,4]
[3,4,4,9,5,14,2,31] -> [3,1,4,1,5,9,2,6]发布于 2022-12-08 00:07:51
发布于 2022-12-08 00:10:51
₌LGɾ↔'ẏD›⋏ṡİṠ?⁼数学?巧妙的倒置方法?不不可能是我!
输入的时间超过4或5,或者有一个金额比较大的地方(比如32)。
建立在我的昨天的回答之上
₌LGɾ↔'ẏD›⋏ṡİṠ?⁼
Gɾ # From the range [1, max(input)] - already making inputs with large numbers take a while
₌L ↔ # Get all combinations with repetition of length(input) - meaning that only short lists with small numbers will be solved quickly
' # Keep only the combinations where:
ẏD›⋏ṡİṠ # Applying the solution to yesterday's challenge
?⁼ # is equal to the input - only returns a single listhttps://codegolf.stackexchange.com/questions/255305
复制相似问题