跟着去年的活动,我们在做代码:高尔夫预告牌2022!
从今天(12月1日)到圣诞节(12月25日)的每一天,都会发布一个以圣诞节为主题的挑战,就像“降临”的日历一样。这是一个免费的和公正的乐趣参与的活动,没有领导板和奖品解决他们快速或解决他们的最短代码。更多细节可以在上面的链接中找到。
我有两种奇怪形状的巧克力供应无限:
为了庆祝即将到来的圣诞节,我想把它们组装成一个巨大的巧克力金字塔。当金字塔的底部是一个大小为R \times C的矩形时,构建这样一个金字塔的过程如下:
下图显示了2 \times 3的过程。一楼需要8块白巧克力和7块黑巧克力,整个金字塔需要10块白和8块黑巧克力。
考虑到基础矩形的宽度和高度,我需要多少块白巧克力和黑巧克力才能形成巧克力金字塔?
您可以假设宽度和高度是正整数。你可以按任何顺序输出两个数字。
适用标准的密码-高尔夫规则。以字节为单位的最短代码获胜。
(width, height) -> (white, dark)
(2, 3) -> (10, 8)
(10, 10) -> (670, 660)
(10, 1) -> (10, 9)发布于 2022-12-01 01:26:07
发布于 2022-12-01 08:04:44
Wݨ€-DPαOD>‚O@emanresuAVyxal回答港,所以一定要支持他/她!
输入为对[width,height];输出为对[dark,white]。
W # Get the minimum of the (implicit) input-pair
Ý # Pop and push a list in the range [0,min]
¨ # Remove the last item to make the range [0,min)
€- # Subtract each from the (implicit) input-pair
D # Duplicate this list of pairs
P # Get the product of each inner pairs
α # Get the absolute difference with the values in the pairs
O # Sum each inner pair
D # Duplicate this list
> # Increase each inner value by 1
‚ # Pair the two lists together
O # Sum each inner list
# (after which this pair is output implicitly as result [dark,white])https://codegolf.stackexchange.com/questions/255042
复制相似问题