ASCII六边形链


13

问题

画一条x长六边形的链,每条的边y

输入值

x -链的长度<= 50

y -每边的长度<= 50

例子

x=1,y=1

 _
/ \
\_/

x=4,y=1

 _   _
/ \_/ \_
\_/ \_/ \
  \_/ \_/

x=3,y=2

  __      __
 /  \    /  \
/    \__/    \
\    /  \    /
 \__/    \__/
    \    /
     \__/

规则

  • 以字节为单位的最短有效答案为准。

  • 允许前导和尾随的换行符。

  • 允许尾随空白。



2
等待强制性的六角答案...
LLlAMnYP '17

2
@LLlAMnYP 现在
Martin Ender

@ user202729如果您现在写一个,我们永远不必找出会发生什么。
LiefdeWen

六角形的第一线。显然需要增加其余的边缘大小。
user202729

Answers:


8

木炭,34字节

NθFN«M∧﹪ι²⊗θ↓P×_θ←↖θ→↗θ×_θ↓↘θ←P↙θ↗

在线尝试!链接是详细版本的代码。在订单大小中取参数,计数。说明:

Nθ

输入六边形尺寸。

FN«

循环输入六边形的数量。

M∧﹪ι²⊗θ↓

在其他六边形上,向下移动整个六边形,以便将下一个六边形绘制到右下角而不是右上角。

P×_θ

画底。

←↖θ

画左下角。

→↗θ

画左上角。

×_θ

绘制顶部。

↓↘θ

画右上角。

←P↙θ

画右下侧。

假设下一个六边形在右上角。


4

Python 2中254个 224字节

def f(n,w):
 a=w*2
 for j in range(1+w*3):print''.join([[[' ',[' /'[i%w==-j%w],' \\'[i%w==~-j%w]][i/a+~-j/w&1]][(j>0)*(i/w>=(j>a))*((i/w/n<2)or(n%-2<~-j/w<3-n%2))],' _'[(j+i/w%4/2*w)%a<(i<n*a)]][i/w%2]for i in range(-~n*a)])

在线尝试!


Python 2中264个 229字节

def f(n,w):
 c=2*w;r=[[' ']*(-~n*c)for _ in' '*(1+w*3)]
 for i in range(w):
  for j in range(n):a=i+j*2*w;b=j%2*w;r[b][w+a],r[c+b][w+i+j*c],r[b+w-i][a],r[b+c-i][a+c],r[b+w-~i][a],r[b-~i][a+c]=r'__//\\'
 for l in r:print''.join(l)

在线尝试!


@ovs非常感谢:)
TFeld


3

SOGL V0.1232 31 个字节

ā.{e╚øΚe╔*ο⁴↔±┼┼╬±fe«*If2%e*I╬5

在这里尝试!

说明:

ā                              push an empty array - the canvas
 .{                            repeat input times
   e╚                            push a diagonal the length of the variable E (by default: next input)
     øΚ                          prepend a line to it
       e╔*ο                      push ["_"*E]
           ⁴                     copy that diagonal
            ↔±                   and reverse it horizontally
              ┼┼                 add the 3 parts together
                ╬±               and palindromize vertically - one hexagon is finished
                  fe«*I          push counter*E*2 + 1 (the counter is 0-based)
                       f2%e*I    push counter%2 * E + 1
                             ╬5  at [counter*E*2+1; counter%2*E+1] insert the hexagon in the canvas

3

Befunge,230个 228 225字节

+&#92#<*:0< vp93*p92+1*3:p91:&+1p
>1+:29g-!#@_>:1-19g+:19g/1-:2*49p2%!2*:1+59p19g*\19g%+69p01v
,>*19g3*79g-1-69g-!2*49g1+0g2%*79g69g-!49g0g2%*++4g,1+:39g-v
^^3*!-*g95g91+1g96!-g95%4p04p01:`\g90p05`0::/g91:p97%*4g91:_$55+
 \/_

在线尝试!


1

JavaScript(ES6),215字节

以currying语法接受输入(y)(x)

y=>(F=(x,c=!(p=y-1,w=x*y*2+y,a=[...(' '.repeat(w++)+`
`).repeat(3*y+1)],g=(d,k)=>k!=y?g(d,-~k,a[p+=d]='_\\/'[c%3]):c++))=>x--?F(x,g(1),g(w+1),p++,g(w-1),g(-1),p+=w,g(~w),p--,g(1-w),p+=(c/6&1?w:-w)*y-w+y*2):a.join``)

演示版


0

画布,25 个字节

ø╶{╷⁷«×¹2%⁷×╵⁷⇵_× ⁷/∔×╬│╋

在这里尝试!

说明(某些字符已更改为看起来是空格):

ø╶{╷⁷«×¹2%⁷×╵⁷⇵_× ⁷/∔×╬│╋
ø                          push an empty canvas
 ╶{                        for 1..input
   ╷                         decrease (so this starts with 0)
    ⁷«×                      multiply by X*2; X coordinate of new hexagon done
       ¹2%                   push 0-indexed counter%2
          ⁷×                 multiply by X
            ╵                and increment; Y coordinate done
             ⁷⇵              push ceil(X/2), saving the remainder
               _×            repeat "_" that many times
                  ⁷/         push " " and an ASCII diagonal with size X
                    ∔        prepend verticall the space before the diagonal
                              done so there's space for the underscores
                     ×       and append the underscores horizontally to the diagonal
                      ╬│     quad-palindromize with Y overlap of 1
                              and X overlap of the remainder taken before
                        ╋    and at the before defined coords ((I-1)*X*2; (i%2)*X + 1)
                              insert the hexagon in the canvas
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.