基地之神正在为凡人打开天堂之门,让他们加入基党。你,作为信徒之一,想跟随他们的脚步去提升到天堂。
但不是每个人都能进去。
上帝张贴这个问题,让你证明你是值得他们的聚会。
您将得到2个输入。
X,它是基数为10的非负整数。base,它是一个要迭代的基列表。1基。您需要以迭代基的形式显示(打印) X。
示例:
X ,[base] -> ans
6 ,[2] -> 110
It has only 1 base in base list, thus it converts number into base2
6 ,[2,4] -> 30
First base is 2, so 6%2=0 is the first digit and (6-0)/2 =3 is forwarded to next base.
Second base is 4, so 3%4=3 is the second digit and there is no remaining.
30 ,[2,3] -> 2100
First two digits come from 30%2=0, 15%3=0, with 15/3=5 is passed to next base,
which loops back to 2 => 5%2 = 1,pass 2=> 2%3 = 2
10 ,[9,2] -> 11
20 ,[3,4,5] -> 122
0 ,[any bases] -> 0上帝需要简短的代码--他们将允许访问每种语言中最短的代码。完成他们提升的任务!
发布于 2021-04-30 05:49:05
发布于 2021-04-30 10:48:54
sиvy‰`s}JRï我觉得这样可以更短一些,但我对打高尔夫球有点生疏了。
将基的列表作为第一个输入,整数X作为第二个输入。
s # Swap the two (implicit) inputs, so the stack is bases-list, integer X
и # Repeat the bases-list X amount of times
v # Loop over each value `y` in this list:
y‰ # Divmod `y` ([v//y, v%y]), which will use the second (implicit) input-integer
# X as value in the very first iteration
` # Pop this list, and push both separated to the stack
s # Swap their order, so the v//y is at the top, as value for the next iteration
}J # After the loop: join all integers on the stack together
R # Reverse it
ï # And cast it to an integer to remove any leading 0s
# (after which the result is output implicitly)https://codegolf.stackexchange.com/questions/224730
复制相似问题