首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >树轮年龄

树轮年龄
EN

Code Golf用户
提问于 2015-09-09 17:07:19
回答 17查看 3.2K关注 0票数 27

Introduction

昨天我看到了一个生日拼图。恭喜你!!

这周,我还看了一集电视节目“骨头”,一具身体被埋在一棵树下。为了计算死亡时间,他们数了数年轮。

树年轮的形成是因为树木在冬天长得慢,在夏天长得快。因此,你可以通过计算年轮来计算树的年龄。此外,你也可以看到自然事件,如雨季或旱季。

挑战

给定一个整数n >= 1作为输入,编写一个完整的程序来输出树龄环。

因为环可以改变形状,所以使用三个不同的字符('0','*','+')来表示气候周期。

1岁

代码语言:javascript
复制
0

2岁

代码语言:javascript
复制
***
*0*
***

3岁

代码语言:javascript
复制
+++++
+***+
+*0*+
+***+
+++++

4岁

代码语言:javascript
复制
0000000
0+++++0
0+***+0
0+*0*+0
0+***+0
0+++++0
0000000

树的大小是2*n - 1边的正方形。

以字节为单位的最短代码获胜。

EN

回答 17

Code Golf用户

回答已采纳

发布于 2019-12-18 12:54:14

派克,13字节

代码语言:javascript
复制
0QV"0*+"o@A.X

基于这个出色的派克回答了另一个挑战,所以一定要把那个也投上去!

在网上试试。

解释:

代码语言:javascript
复制
0              # Start with a "0" in the center
 QV            # Loop the input amount of times:
   "0*+"       #  Push string "0*+"
        o      #  Push index++ (0 by default; and increases by 1 after pushing)
         @     #  And use it to index it into the string (0-based with automatic wraparound)
          A    #  Deep apply the following command:
           .X  #   Surround the string with this character around it
               # (after which the result is output implicitly)
票数 2
EN

Code Golf用户

发布于 2015-09-10 09:33:37

BBC,93字节

代码语言:javascript
复制
1I.r:r=r-1:F.i=-r TOr:F.j=-r TOr:p=ABS(i):q=ABS(j):IFp<q TH.p=q
2V.48-(p MOD3)*6MOD7:N.:P.:N.

缩写的关键字在这里很有帮助。在第2行中,我使用VDU命令(相当于C的putchar())打印每个字符。这比P.MID$("0*+",p MOD3+1,1)高效得多。

在这里,它运行在Mac上的BeebEm3中:

票数 12
EN

Code Golf用户

发布于 2015-09-09 17:29:26

CJam,25字节

代码语言:javascript
复制
q~,_1>W%\+_ff{e>"0*+"=}N*

在这里测试一下。

解释

代码语言:javascript
复制
q~,       e# Read input N, turn into range [0 1 ... N-1]
_1>       e# Duplicate and cut off the zero.
W%        e# Reverse.
\+        e# Prepend to original range to give [N-1 ... 1 0 1 ... N-1]
_         e# Duplicate
ff{       e# Nested map for each pair of elements in that array.
  e>      e# Take the maximum, i.e. chessboard distance from the centre.
  "0*+"=  e# Select the right character using cyclic indexing into this string.
}
N*        e# Join the lines with line feeds.
票数 7
EN
页面原文内容由Code Golf提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

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

复制
相关文章

相似问题

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