首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >信件质疑

信件质疑
EN

Code Golf用户
提问于 2018-10-02 09:59:11
回答 24查看 1.9K关注 0票数 7

使用“conemon”这个词打印每个字符比上一个字符多2倍。第一个字母“c”应打印10次,第二个字母为12次,以此类推。每个重复的字母字符串都应该打印在新行上。

最终的结果是:

代码语言:javascript
复制
cccccccccc
oooooooooooo
nnnnnnnnnnnnnn
eeeeeeeeeeeeeeee
mmmmmmmmmmmmmmmmmm
oooooooooooooooooooo
nnnnnnnnnnnnnnnnnnnnnn
EN

回答 24

Code Golf用户

回答已采纳

发布于 2018-10-02 10:04:22

Python 2,36字节

代码语言:javascript
复制
i=8
for c in'conemon':i+=2;print c*i

在网上试试!

票数 5
EN

Code Golf用户

发布于 2018-10-02 10:50:33

MathGolf,15字节

代码语言:javascript
复制
╕│Pùmon+ô8î∞+*p

在网上试试!

解释

代码语言:javascript
复制
╕│P                 Compression of 'cone'
   ùmon             Push 'mon'
       +            Concatenate together
        ô          Foreach over each letter
         8         Push 8
          î∞       Push the index of the loop (1 based) and double it
            +      Add the 8
             *p    Repeat the letter that many times and print with a newline
票数 2
EN

Code Golf用户

发布于 2018-10-02 10:54:53

Java 11,78字节

代码语言:javascript
复制
v->{int i=8;for(var c:"conemon".split(""))System.out.println(c.repeat(i+=2));}

在网上试试。 (注意:对于相同的字节计数,String.repeat(int)被模拟为repeat(String,int),因为Java11还没有在TIO上)。

解释:

代码语言:javascript
复制
v->{                     // Method with empty unused parameter and no return-type
  int i=8;               //  Integer `i`, starting at 8
  for(var c:"conemon".split(""))
                         //  Loop over the characters (as Strings) of "codemon"
    System.out.println(  //   Print with trailing new-line:
      c.repeat(          //    The current character repeated
        i+=2));}         //    `i` amount of times, after we've first increased `i` by 2
票数 2
EN
页面原文内容由Code Golf提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

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

复制
相关文章

相似问题

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