果冻,16 14字节
感谢Dennis节省了2个字节!
ÆḌḊ,Ṗ߀€+U$FṂo
在线尝试!
逻辑说明
给定数字n:
表示形式是a + b或a × b,其中a和b是表达式。
考虑所有可能的值a和b:
- 如果表示形式为
a + b,则a和b都在范围内[1 .. n-1]。
- 如果表示形式为
a × b,a并且b是n大于的适当除数1。
在这两种情况下,都将[[<proper divisors of n larger than 1>], [1, 2, ..., n-1]]计算列表(ÆḌḊ,Ṗ),将当前链接映射到每个数字߀€,将正确的线对加在一起(+U$)并获得最小值(FṂo)。
代码说明
ÆḌḊ,Ṗ߀€+U$FṂo Main link. Assume n = 10.
ÆḌ Proper divisors. [1,2,5]
Ḋ Ḋequeue, remove the first element. [2,5]
,Ṗ Pair with Ṗop. Auto convert n = 10 to range
[1,2,3,4,5,6,7,8,9,10] and remove the last element
10, get [1,2,3,4,5,6,7,8,9].
߀€ Apply this link over each element.
+U$ Add with the Upend of itself.
FṂ Flatten and get the Ṃinimum element.
o Logical or with n.
If the list is empty, minimum returns 0 (falsy), so logical or
convert it to n.