木の生と死


8

チャレンジ

整数Nを入力として受け取り、ツリーが現在存在する生死の段階を出力するプログラムを作成します。Nは常に0から10の間です。

生と死の段階

  • 人生:人生のステージを描くには、単純に文字で構成されるサイズNのベースを描き、結果が0より大きい場合は上に^移動してNから2 を引き^、もう一度サイズを変えて文字の線を描きます。新しいのNNが0より大きい間繰り返します。終了するには|Nの開始値が奇数の場合は1 文字、偶数の||場合は2 文字を配置します。
    例:N = 5

      ^
     ^^^
    ^^^^^
      |
    

    N = 0の場合、葉(^)なしで茎のみが描画されることに注意してください。

  • 死:これは大体同じである生活基盤であることを除いて、- N 10、あなたが使用Mするのではなく^、あなたがに2を追加Nと、上記と同じ手順で行を再描画が、今回は、あなたがに2を追加Nことながら、は10以下です。
    例:N = 3

       M
      MMM
     MMMMM
    MMMMMMM
       |
    

目標

プログラムは2つの異なる言語で実行する必要があり、どちらも入力Nを受け取る必要があります。最初の言語はNに従って木のライフステージを出力する必要があり、2番目の言語は死のステージを出力する必要があります。

ルール

  • これはであり、すべての要件を満たすバイト単位の最短のコードです。
  • コードは2つの異なる言語で実行する必要があります。はい、Python 2とPython 3 は異なる言語です。
  • 標準の抜け穴は禁止されています。
  • 末尾の改行またはスペースは許可されます。

テストケース

入力: N = 1

第一言語(生活):

 ^
 |

第二言語(死):

    M
   MMM
  MMMMM
 MMMMMMM
MMMMMMMMM
    |

入力: N = 10

第一言語(生活):

    ^^
   ^^^^
  ^^^^^^
 ^^^^^^^^
^^^^^^^^^^
    ||

第二言語(死):

||

幸運のコーディング!


末尾/先頭の改行または末尾のスペースはありますか?
dzaima 2017

@dzaimaはい、私がいることを編集します。
イアンH.

回答:


10

Dyalog APL / SOGL、70 65 63 62バイト

0000000: 7b0d 04eb c0fd 5832 5c49 e32a 2e4c ac20  {.....X2\I.*.L. 
0000010: 4d2a 5b3a 836b 6b7d 01ea 500d 9b31 a90f  M*[:.kk}..P..1..
0000020: 7b0f c285 c8c7 b932 c00e f8b1 c70f 7db0  {......2......}.
0000030: 32c2 8531 9c85 80b2 b50f aa32 f97d       2..1.......2.}

古典的なDyalog APLエンコーディングで解釈されます:-ライフ:(印刷不可を含む)、期待⎕IO←1

{' ^|⎕X2I┤z.L?pMzÅÏÏ}ûP'[1+⍵{⍵,⍨⌽⍉(2|⍺)↓⍉⍵}↑2,⍨1/⍨¨⍳⌈⍵÷2]}

ここでTryAPL!

{' ^|..'[1+⍵{⍵,⍨⌽⍉(2|⍺)↓⍉⍵}↑2,⍨1/⍨¨⍳⌈⍵÷2]}

         1+      add 1 to every value
 ' ^|..'[  ....] index the array getten below into " ^|.." with SOGLs code never being indexed in


⍵{..}↑2,⍨1/⍨¨⍳⌈⍵÷2

          1/⍨¨      replace each with that many 1s
              ⍳     the first ... numbers
               ⌈      ceiling of
                ⍵÷2     the right argument divided by 2
       2,⍨          append 2
      ↑             mix; convert to a 2D array, padding with zeroes
⍵{..}               execute that function with the arguments ⍵ - my right argument and the result of above


   {⍵,⍨⌽⍉(2|⍺)↓⍉⍵}  helper function
    ⍵,⍨             append the right arg to
               ⍉⍵     the right arg transposed
              ↓       without the first ... rows
         (2|⍺)          remainder of left arg ÷ 2
       ⌽⍉             transposed and reversed

SOGLエンコーディングで解釈-死:

{∑⁴╝υ”X2\I┐*.Lκ M*[:≥kk}¹╚P∑Β1Ι»{»φ√ωΩΡ2υ«⌠ΝΩ»}μ2φ√1β√↓νΟ»ι2⌡}

ここでお試しください!

説明:

{∑⁴╝υ”X                         push "{∑⁴╝υ" and pop it - noop
       2\                       push input divides by 2
         I┐*                    get that many + 1 vertical bars
            .Lκ                 push 10-input
                M*              get that many "M"s as a string
                  [    }        while ToS isn't falsy (here: isn't "")
                   :              duplicate the string
                    ≥             put the duplicate at the stacks bottom
                     kk           remove the last 2 letters (does nothing when the string is empty)
                        ¹       wrap everything in an array
                         ╚      center horizontally
                          P     print that
                           ...  execute a bunch of random nonsense which luckily does nothing

これには時間がかかりすぎました。APLパートのゴルフのヒントは大歓迎です。以前に何も変更されない限り、ほとんどすべてが当てはまるはずです。 ûP'

ダイアログでファイルを選択してをクリックすることによりxxdSOGLで(リバース後に)ファイルをロードできます。 Browse...load SOGL codepage encoded file





2

C(gcc) / Python 2、308バイト

#define _\
"""
main(N,n,j,k){scanf("%d",&N);j=-~!(N%2);for(n=j;n<=N;n+=2){printf("%*c",(N-n)/2+1,94);for(k=n-1;k;k--)printf("^");puts("");}printf("%*c",++N/2,124);N%2?puts("|"):0;}
#define _"""
#define/*
N=10-input();j=[1,0][N%2]
for n in range(1,-~N,2):print(N-n)/2*" "+"M"*(n+j)
print~-N/2*" "+"|"*-~j
#*/_

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

Python 2 / C(gcc)、308バイト

#define _\
"""
main(N,n,j,k){scanf("%d",&N);j=-~!(N%2);for(n=j;n<=N;n+=2){printf("%*c",(N-n)/2+1,94);for(k=n-1;k;k--)printf("^");puts("");}printf("%*c",++N/2,124);N%2?puts("|"):0;}
#define _"""
#define/*
N=10-input();j=[1,0][N%2]
for n in range(1,-~N,2):print(N-n)/2*" "+"M"*(n+j)
print~-N/2*" "+"|"*-~j
#*/_

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

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