我遇到过这种类型的难题,这通常涉及苹果,几次。其内容如下:
篮子里有一定数量的苹果。艾娃拿走了三分之一的苹果。鲍勃拿走剩下的四分之一的苹果。最后,丹尼斯拿走了剩下的六分之一的苹果.最后,有10个剩余的苹果。篮子里有几个苹果?
以上任务的答案是24。
给定一个正整数列表和一个整数,表示最后留下的苹果,返回最初在篮子中的苹果数。
[3, 4, 6], 10 -> 24
[2], 14 -> 28
[6], 30 -> 36
[4, 3], 20 -> 40
[5, 8, 7], 9 -> 15
[2, 9, 4, 8], 7 -> 24发布于 2023-02-10 20:37:18
发布于 2023-02-11 07:13:46
%[:*/1-%取剩余苹果数作为左参数,将列表作为右参数。
% (除法)形成一个二进位钩,并将左参数除以将[:*/1-%应用到右边参数(单元)的结果。%取列表中数字的倒数。1 -从1减去每个倒数。*/接受该产品;上限([:)用于一元化。发布于 2023-02-13 18:27:39
tq/hp在MATL在线试一试
% Implicitly retrieve the first input, an array
t % Duplicate the first input (x)
q % Subtract 1 (x - 1)
/ % Divide (element-wise) the two values on the stack (x / (x - 1))
h % Implicitly retrieve the second input and append to the array
p % Compute the product of all elements
% Implicitly display the resulthttps://codegolf.stackexchange.com/questions/257649
复制相似问题