ASCII六角形リングタイリングを作成する


10

ASCIIを使用して、六角形のリングタイルのセクションを印刷します。

ここに小さなセクションがあります:

       /\__/\
      /_/  \_\
 /\__/\ \__/ /\__/\ 
/_/  \_\/__\/_/  \_\
\ \__/ /\__/\ \__/ /
 \/__\/_/  \_\/__\/
 /\__/\ \__/ /\__/\ 
/_/  \_\/__\/_/  \_\ 
\ \__/ /\__/\ \__/ /
 \/__\/_/  \_\/__\/
      \ \__/ /
       \/__\/

ここに大きなセクションがあります:

\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\
 \/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\
 /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /
/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/
\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\
 \/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\
 /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /
/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/
\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\
 \/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\
 /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /
/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/

チャレンジ

2つの整数hとが指定されているw場合、hは高さとwhxwです。六角形リングタイリングのセクションを出力します。

入力1

4x4

出力1

 /\__/\ \__/ /\__/\ \__/ /
/_/  \_\/__\/_/  \_\/__\/
\ \__/ /\__/\ \__/ /\__/\
 \/__\/_/  \_\/__\/_/  \_\
 /\__/\ \__/ /\__/\ \__/ /
/_/  \_\/__\/_/  \_\/__\/
\ \__/ /\__/\ \__/ /\__/\
 \/__\/_/  \_\/__\/_/  \_\
 /\__/\ \__/ /\__/\ \__/ /
/_/  \_\/__\/_/  \_\/__\/
\ \__/ /\__/\ \__/ /\__/\
 \/__\/_/  \_\/__\/_/  \_\
 /\__/\ \__/ /\__/\ \__/ /
/_/  \_\/__\/_/  \_\/__\/
\ \__/ /\__/\ \__/ /\__/\
 \/__\/_/  \_\/__\/_/  \_\

入力2

3x3

出力2

 /\__/\ \__/ /\__/\
/_/  \_\/__\/_/  \_\
\ \__/ /\__/\ \__/ /
 \/__\/_/  \_\/__\/
 /\__/\ \__/ /\__/\
/_/  \_\/__\/_/  \_\
\ \__/ /\__/\ \__/ /
 \/__\/_/  \_\/__\/
 /\__/\ \__/ /\__/\
/_/  \_\/__\/_/  \_\
\ \__/ /\__/\ \__/ /
 \/__\/_/  \_\/__\/

入力3

1x3

出力3

 /\__/\ \__/ /\__/\
/_/  \_\/__\/_/  \_\
\ \__/ /\__/\ \__/ /
 \/__\/_/  \_\/__\/

入力4

3x6

出力4

 /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /
/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/
\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\
 \/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\
 /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /
/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/
\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\
 \/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\
 /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /
/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/
\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\
 \/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\

明確化

  • 私の質問はこれに似ています:Me Want Honeycomb
  • 入力はフォームの1行になりますhxw
  • stdout(または類似のもの)への出力。
  • これはコードゴルフなので、バイト単位の最短の回答が優先されます。

6
明確で客観性を保つために、出力する必要があるセクションの大きさを正確に明確にする必要があります
James

私はあなたのコメントを見たところです。より明確にするために寸法を修正します
Bobas_Pett

モデレーターが私のコメントを見たとは思わないので、質問が次の2時間保留のままである場合は、明確にするために、私が行った編集と4番目の例で更新された質問を作成します。混乱してしまい申し訳ありません。私が行った編集があなたが望んでいたものに近くない場合は、コメントを投稿して必要なことを教えてください。
Bobas_Pett、

これはkolmogorov-complexityとタグ付けする必要がありますか?
Pavel

1秒で追加できません...
Bobas_Pett、

回答:


2

Befunge、137バイト

私はある種のscifiハンドガンを作ったようです。

&>4*>~>$&>\>1-:4%3v
>00gg,\1-:v^_@#:\<>+00p\::6*\00g2/+2%+1+66+:
^%+66<:+1\_$$55+,^
_\/__\/_/  \
\ \__/ /\__/\
/_/  \_\/__\/
 /\__/\ \__/

オンラインでお試しください!

説明

&>4*>                    Read the height and multiply by 4.
     ~>$                 Drop the 'x' separator. 
        &>\              Read the width and swap below the height

>                        Start of the outer loop.
 1-                      Decrement the height.              
   :4%3+00p              Calculate the pattern y offset: height%4+3
           \             Swap the width back to the top.

::6*\00g2/+2%+1+         Calculate the line length: w*6+(w+y/2)%2+1 
                66+:     Initialise the pattern x offset to 12, and duplicate it.

>                        Start of the inner loop.     
 00gg                    Get a pattern char using the x on the stack and the saved y.
     ,                   Output the char.
      \1-                Swap the line length to the top of the stack and decrement it.
         :v              Check if it's zero, and if so...
          _                 ...break out of the loop to the right.
       +1\               Otherwise swap the x offset back to the top and increment it.
 %+66<:                  Mod it with 12 to make sure it's in range.
^                        Then return to the beginning of the inner loop.

$$                       Drop the x offset and line length.
  55+,                   Output a newline.
     \<                  Swap the height back to the top of the stack.
 _@#:                    Check if it's zero, and exit if that's the case.
^                        Otherwise return to the start of the outer loop.

3

Lua、174 176 156バイト

このコードは、六角形の高さ量ではなく、行の高さ量を印刷します。を追加し*4、それを修正しましたが、2バイト追加しました。 カウンターをifからmoduloに変更し、2つio.read()を1つに入れることで、いくつかのバイトを節約しました。

io.read()入力として使用します。

a,w,h,n,d={[[ /\__/\ \__/]],[[/_/  \_\/__\\]],[[\ \__/ /\__/]],[[_\/__\/_/  \\]]},io.read(,),"",0 for i=h*4,0,-1 do d=d+1 d=5%d end n=a[d]print(n:rep(w))end

を介して文字列のwidth-amountの回数を複製string:rep(width)し、for-loopでheight-amountの回数を繰り返します。[[]]バックスラッシュが本当にねじ込まれているため、(文字列)が必要です。

古いバージョン:

a,w,h,n,d={[[ /\__/\ \__/]],[[/_/  \_\/__\\]],[[\ \__/ /\__/]],[[_\/__\/_/  \\]]},io.read(),io.read(),"",0 for i=h*4,0,-1 do d=d+1 d=5%d end n=a[d]print(n:rep(w))end

1

Python 2、180バイト

a,b,c,d=' /\__/\ \__/','/_/  \_\/__\\','\ \__/ /\__/','_\/__\/_/  \\'
h,w=input()
x=w/2
e,E=[(2,1),(7,8)][w%2]
print'\n'.join([a*x+a[:e],b*x+b[:E],c*x+c[:E],' '+(d*x+d[:e])[1:]]*h)

入力を2つの整数として受け取ります

入力: 2,7

出力:

 /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\
/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\
\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /
 \/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/
 /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\
/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\
\ \__/ /\__/\ \__/ /\__/\ \__/ /\__/\ \__/ /
 \/__\/_/  \_\/__\/_/  \_\/__\/_/  \_\/__\/

1

バッチ、266バイト

@echo off
for /l %%i in (1,1,%1)do call:l %2 " \" /__\/ "_/  \_\" " \__/ /" \__/\
exit/b
:l
call:c %1 " /" %6 %5
call:c %1 / %4 %3
call:c %1 \ %5 %6
:c
set s=%~2
for /l %%j in (2,2,%1)do call set s=%%s%%%~3%~4
set/ao=%1^&1
if %o%==1 set s=%s%%~3
echo %s%

:cサブルーチンは、単一の行のために一緒に部品を連結するすべての取材を行います。リングの各行に対して4行を生成するために、:l4回呼び出されます(1つは:lの引数がのスーパーセットになるように配置することにより、1つはフォール:c)。リングの最後の行でフォールスルーする可能性もありましたが、5バイト長くなることがわかりました。

弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.