いくつかのダイヤモンドをダブルアップ


25

問題

nここで正の整数を与えますn < 100

次のようにダイヤモンドパターンを出力します。

入力 n=1

/\/\
\/\/

入力n=2

 /\      /\
//\\/\/\//\\
\\//\/\/\\//
 \/      \/

入力n=3

  /\                /\
 //\\  /\      /\  //\\
///\\\//\\/\/\//\\///\\\
\\\///\\//\/\/\\//\\\///
 \\//  \/      \/  \\//
  \/                \/

入力n=4

   /\                              /\
  //\\    /\                /\    //\\
 ///\\\  //\\  /\      /\  //\\  ///\\\
////\\\\///\\\//\\/\/\//\\///\\\////\\\\
\\\\////\\\///\\//\/\/\\//\\\///\\\\////
 \\\///  \\//  \/      \/  \\//  \\\///
  \\//    \/                \/    \\//
   \/                              \/

等々。

ルール

  • 許可されたプログラムと機能。
  • 末尾の空白が許可されます。
  • 行の先頭に空白がない/か、\許可されていません。
  • 末尾および先頭の改行が許可されます。
  • バイト単位の最短コードが勝つ

これはおそらくかなり関連しています


2
...今、あなたにしている幻覚を@carusocomputing
エリックOutgolfer


1
@dzaimaと一緒にサンドボックスに!
魔法のタコUr

1
確かに@carusocomputingが、最初私が把握する必要があり、なぜそれが起こったのか:P
dzaima

回答:


12

SOGL V0.12、24のバイト

ā.∫ā;∫ \*+}ø┼↔±╬¡;øΚ┼}╬³

ここで試してみてください!

説明:

ā                         push an empty array (the main canvas)
 .∫                  }    iterate over the input, pushing 1-indexed iteration
   ā;                       push an empty array below the iteration
     ∫    }                 iterate over the iteration counter
       \*                     push current iteration amount of slashes
         +                    append those to the 2nd array
           ø┼               append nothing (so it'd space the array to a square)
             ↔±             reverse horizontally (swapping slashes)
               έ           quad-palindromize with 0 overlap and swapping characters as required
                 ;          get the canvas ontop
                  øΚ        prepend to it an empty line (so the now bigger romb would be one up)
                    ┼       append horizontally the canvas to the current romb
                      ╬³  palindromize horizontally with no overlap and swapping characters

2
うわー、それは病気のコマンドです。
魔法のタコUr

@carusocomputingかなり最近の追加も。関連ファイル。それでも残りの190個の文字をどのように処理するかを把握する必要があり
dzaima

わあ、SOGOLには190個の無料コマンドがあり、これを既に効率的にゴルフできますか?
魔法のタコUr

1
@carusocomputing LOLの190個の無料コマンドを意味しました
dzaima

2
@carusocomputingしかし、楽しい事実として、(約)256分の90の文字が実装されていないと256分の61は、任意のドキュメントを持っていない
dzaima

7

30 27バイト

F⁺¹N«Fι«F⁴«↙⁻ικ↑⟲T»←»Mι←»‖M

オンラインでお試しください!リンクは、コードの詳細バージョンです。説明:木炭の描画プリミティブは、対角線の動きが同じパリティの正方形上にとどまるため、ダイヤモンドをまったく描画できません。編集:新しい解決策は、ダイヤモンドの片側を描画してから、キャンバス全体を回転させて次の側を描画できるようにし、ダイヤモンドをループで描画できるようにすることです。次に、このループをループに含めて、各ダイヤモンドのすべての内部ダイヤモンドを描画します。最も外側のループは、互いに隣接するすべてのダイヤモンドを描画します。最後に、イメージがミラーリングされます。

Charcoalはその後拡張されており、を使用して別のバイトを保存できることに注意してくださいIncrement


あなたがそれらを必要とするとき0.5文字の動きはどこにありますか:(
CalculatorFeline

6

APL(Dyalog)70 69 66バイト

B←{'/\ '['\/'⍳⍺⍺⍵]}
C←⊢,⌽B
C(⊢⍪⊖B)⊃,/{C⊖A↑⊖' /'[⍵≤∘.+⍨⍳⍵+1]}¨⌽⍳A←⎕

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

⎕IO←0多くのシステムで標準であると想定しているため、プログラムは0インデックス付きです。

これは、STDINを介して入力を受け取るtradfnです。

説明

(やや時代遅れ)

は左引数であり、右引数で⍺⍺あり、左演算子であることに注意してください。

Bダイヤモンドのミラーリングに役立つ関数です。文字列を右引数として、逆関数を左引数として取ります(B演算子も同様です)。

B←{'/\ '['\/'⍳⍺⍺⍵]}
              ⍺⍺⍵            Apply ⍺⍺ on 
         '\/'               Find the index of the reflected string in '\/' (if the character is not found in `'\/'`, then return an index out of the bounds of the string, ie `2` if the character is a space)
   '/\ '[        ]           Use these indexes on '/\ ' to reflect the '/\' characters

そして今、私たちはプログラムの主要部分に行きます。

A←⎕              Assign the input to variable A
                Create a range 0 .. A-1
                Reverse it so that it becomes A-1 .. 0
¨                For each element do (the right argument is the element):
 ⍳⍵+1             Create a range 0 .. 
 ∘.+⍨             Create an addition table using the range to result in a matrix like so:
                   0+0 0+1 0+2 .. 0+⍵
                   1+0 1+1 1+2 .. 1+⍵
                   2+0 2+1 2+2 .. 2+⍵
                   ...
                   ⍵+0 ⍵+1 ⍵+2 .. ⍵+⍵
 ⍵≤              The elements of the matrix that are greater than or equal to the ⍵,
                 this creates a triangle matrix that looks like this:
                   0 0 .. 0 1
                   0 0 .. 1 1
                   ..
                   1 1 .. 1 1
 ' /'[...]       Index it in ' /' to get a character matrix
                 (ie replace 0s with spaces and 1s with '/'s)
                Flip this vertically
 A              Pad the top spaces

これは、⌽⍳A後で互いに連結できるように、範囲内のすべての要素に対して作成されたすべての三角形が同じ高さになるようにするために必要です。

                Flip the matrix vertically again to go back to the original state
 (⊢,  )          Concatenate it with
    B           itself, but flipped horizontally
,/              Concatenate all triangles formed by the range operator
               The resulting matrix is nested, so this operator "un-nests" it

これで、パターンの左上の部分が完成しました。残っているのは、垂直に反転してから水平に反転することです。

(⊢⍪⊖B)          Concatenate the resulting matrix with itself but flipped vertically
                (the vertically flipped matrix is concatenated below of the original matrix)
                Now the left part of the pattern is complete
(⊢,⌽B)         Concatenate the resulting matrix with itself flipped horizontally

以上です!出力は、/\sが含まれ、スペースが埋め込まれた文字マトリックスです。


6

05AB1E47 43 41 35 34 33 32バイト

'/×ηηvy∞.C.Bø€∞¹NαGð.ø}})øíJ.B»∞

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

(3バイトの改善を提案した@Emignaに4バイト感謝)


この説明は以前のバージョンに関するものであり、それ以降いくつかの反復が行われています。

>                                          # [2]
 '/×                                       # ['//']
    η                                      # ['/','//']
     €η                                    # [['/'], ['/', '//']]
       vy                    }             # {For each element...}
         ∞                                 # Mirror horizontally.
          ¶¡                               # Split mirror on newlines.
            N£                             # Shave each diamond down a layer.
              .C                           # Horizontal center.
                .B                         # Pad for the transpose.
                  ø                        # Transpose.
                   €∞                      # Mirror each (vertically).
                     ¹NαFð.ø}              # Pad each list for transpose (verticaly).
                              )            # Wrap back to list...
                               €.B         # Pad each horizontally.
                                  ¦        # Remove the random numbers?
                                   ø       # Back to horizontal...
                                    €R     # Reverse to get correct order.
                                      J    # Join, no spaces.
                                       »   # Join newlines.
                                        ∞  # Final horizontal mirror.

あなたのダイヤモンドの間にスペースがあります
LiefdeWen

@LiefdeWen これでいいですか?後続の改行と先行する改行で?
魔法のタコUr

ηこの文字列と同じであるため、接尾辞の代わりに接頭辞を使用できます。
エミグナ

¨ここと同じで、€Rですí
エミグナ

@エミグナ私はそのうちのいくつかをゴルフしたが、ありがとう!100%異なる33バイトの回答を試みますか?
魔法のタコUr

5

CJam65 63バイト

q~_,:)_W%\+f{_2*S*a@2$-*\_,f{)'/*\Se[_W%'/'\er+}_W%Wf%+1$++}zN*

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

説明

この説明では、入力番号をとして参照しますn

q~        e# Read and eval the input (push n to the stack).
_,        e# Copy it an get the range [0 .. n-1].
:)        e# Increment each element to get [1 .. n].
_W%       e# Copy it and reverse it.
\+        e# Prepend the reverse to the original range, resulting in [n n-1 .. 1 1 .. n-1 n].
f{        e# Map over each number x in the range using n as an extra parameter:
 _2*S*a   e#  Push a string containing n*2 spaces, and wrap it in an array.
 @2$-     e#  Push n-x.
 *        e#  Repeat the space string from before n-x times.
 \        e#  Bring x back to the top.
 _,       e#  Copy it and get the range [0 .. x-1].
 f{       e#  Map over each number y in this range, using x as an extra parameter:
  )       e#   Increment y.
  '/*     e#   Repeat '/' y times.
  \Se[    e#   Pad the resulting string to length x by adding spaces to the left.
  _W%     e#   Copy the result and reverse it.
  '/'\er  e#   Replace '/' with '\' in that.
  +       e#   Concatenate to the other string. This forms one row of one diamond.
 }        e#  (end map, now we have the top half of a diamond of size x)
 _W%      e#  Copy the half-diamond and reverse it.
 Wf%      e#  Reverse each row.
 +        e#  Concatenate to the top half. Now we have a full diamond of size x.
 1$++     e#  Put the spaces from before at the beginning and end. This is to pad the top
          e#  and bottom of the smaller diamonds.
}         e# (end map)
z         e# Transpose.
N*        e# Join with newlines. Implicit output.

好奇心から、なぜe#説明で?
魔法のタコUr

1
@carusocomputingコメントであるため、説明自体を実行できます。そうでもないが、必要に応じ¯\ _(ツ)_ /¯
ビジネス猫

1
@carusocomputingは#CJam内のコメントはありません- sourceforge.net/p/cjam/wiki/Basic%20operators/#number-sign -それは他の多くの言語であっても。CJamはゴルフ言語であるため、ゴルフに適した機能にはすべて1文字のコマンドが使用されます。それは、このように他の何かのために1文字のシーケンスを解放し、2文字のシーケンスを使用していますので、コメントは、ungolfedコードのためにのみ有用です
ジョー・

3

パイソン2152の 147 143 140バイト

musicman523のおかげで-1バイト

n=input()
r=range(n)
r+=r[::-1]
for x,i in enumerate(r):a,b='/\\\/'[i<x::2];s=' '*(n+~i);print''.join((s+a*n)[:n-j]+(b*-~i+s)[j:]for j in r)

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

これは、[0,..,n,n,..,0]削除する列の量を制御するために使用して、最大のダイヤモンドの内側の列を切り刻んで小さな列を作成することにより機能します。


あなたは、変更することにより、1つの安いバイトを取得することができますr=r+r+=
musicman523


3

Dyalog APL、46

{⊃,/⍵∘{'/ \'[2+((-⍪⊖)⌽,-)(-⍺)↑∘.≥⍨⍳⍵]}¨(⌽,⊢)⍳⍵}

PPCGへようこそ。これがdfnであると見て{}、それらを含める必要があるので、私はあなたの答えにを追加しました。
クリチキシリソス


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