首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >卑微的神

卑微的神
EN

Code Golf用户
提问于 2021-04-30 04:47:36
回答 11查看 1.4K关注 0票数 8

Story

基地之神正在为凡人打开天堂之门,让他们加入基党。你,作为信徒之一,想跟随他们的脚步去提升到天堂。

但不是每个人都能进去。

上帝张贴这个问题,让你证明你是值得他们的聚会。

任务

您将得到2个输入。

  • 首先是X,它是基数为10的非负整数。
  • 第二个是base,它是一个要迭代的基列表。
  • 基总是在1~10的范围内的正整数。
  • 该基至少包含一个非1基。

您需要以迭代基的形式显示(打印) X

示例:

代码语言:javascript
运行
复制
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

规则

  • 无标准漏洞
  • 输入、输出以任何合理、方便的格式均可接受。

上帝需要简短的代码--他们将允许访问每种语言中最短的代码。完成他们提升的任务!

EN

回答 11

Code Golf用户

发布于 2021-04-30 05:49:05

Python 3,41字节

我根据@att的一个聪明的观察,对我以前的解决方案进行了大规模的改进,以使用碱基是\le 10 这一事实。

代码语言:javascript
运行
复制
f=lambda x,y,*b:x and 10*f(x//y,*b,y)+x%y

在网上试试!

Python 3,48字节

以数字列表的形式输出数字。需要几个字节来处理X = 0 中的边缘情况。

代码语言:javascript
运行
复制
f=lambda x,y,*b:x//y and f(x//y,*b,y)+[x%y]or[x]

在网上试试!

票数 3
EN

Code Golf用户

发布于 2021-04-30 10:48:54

05AB1E,11 字节数

代码语言:javascript
运行
复制
sиvy‰`s}JRï

我觉得这样可以更短一些,但我对打高尔夫球有点生疏了。

将基的列表作为第一个输入,整数X作为第二个输入。

在网上试试验证所有测试用例.

解释:

代码语言:javascript
运行
复制
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)
票数 3
EN

Code Golf用户

发布于 2021-04-30 04:59:25

Python 3,57字节

代码语言:javascript
运行
复制
f=lambda x,a,*b,j=0:x and f(x//a,*b[1:],a,j=[])+[x%a]or j

在网上试试!

-5个字节,借用Arnauld的想法使用splat。

票数 2
EN
页面原文内容由Code Golf提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://codegolf.stackexchange.com/questions/224730

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档