代码:高尔夫预告牌2022事件的一部分。有关详细信息,请参阅链接的元帖子。
在他的中年危机中,圣诞老人冲动地购买了一款Sleigh™作为今年的礼物。唯一的问题是,这种雪橇有一个特殊设计的无限现在躯干与刚性的边,而不是一个现在的袋子与灵活的。这意味着圣诞老人必须把礼物包装得最好,这样才有尽可能少的空空间。
挑战
编写一个以正整数列表(表示呈现宽度)为输入的程序,并输出正整数列表(表示礼物行),其中每一行遵循以下两条规则:
如果不可能实现这些规则,程序必须返回任何常量值。可能有多个有效的解决方案;您的程序可以输出其中的任何一个。
Input: [5, 1, 2, 6, 4, 3, 3]
Possible output: [[6], [5, 1], [2, 4], [3, 3]]
Visualization:
vvvvvv
+++++=
xx----
___ooo
Input: [9, 4, 2, 4, 5, 3]
Possible output: [[9], [4, 5], [3, 4, 2]]
Visualization:
+++++++++
vvvv=====
xxxoooo--我不知道是否有任何可能输出的输入;在我看来并不是这样,但是如果你能证明有或没有,请留下评论!(我并不是用不同的单行礼物排序来计算细微的差异。)
发布于 2022-12-17 16:57:06
发布于 2022-12-16 19:45:59
发布于 2022-12-16 21:27:49
如果没有结果,则返回undefined。
n
à f@̶XxÃà æ@eXÔc nn\nà f@̶XxÃà æ@eXÔc n :Implicit input of array U
n :Sort
\n :Reassign to U
à :Combinations
f :Filter by
@ :Passing each X through the following function
Ì : Last element of U
¶ : Is equal to
Xx : X reduced by addition
à :End filter
à :Combinations (in descending order of length)
æ :First element to return true
@ :When passed through the following function as X
e : U is equal to
XÔ : Reverse X (mutates the original)
c : Flatten
n : Sorthttps://codegolf.stackexchange.com/questions/255591
复制相似问题