アスキーアイスクリーム


15

Nの整数正にかかるプログラムや関数を記述し、プリント又は戻り、その上半分からなる半円であるN×Nアスキーアート列(「その下半分からなる下向きの三角形でsおよびVs」は、とパディングとして使用されるスペース。

つまり、ASCIIアイスクリームコーンを作成します:(N = 17の出力)

      (((((      
    (((((((((    
  (((((((((((((  
  (((((((((((((  
 ((((((((((((((( 
 ((((((((((((((( 
(((((((((((((((((
(((((((((((((((((
VVVVVVVVVVVVVVVVV
 VVVVVVVVVVVVVVV 
  VVVVVVVVVVVVV  
   VVVVVVVVVVV   
    VVVVVVVVV    
     VVVVVVV     
      VVVVV      
       VVV       
        V        

N = 1〜5の出力を次に示します。奇数Nの場合、三角形は常に大きな半分でなければなりません。

V

((
VV

(((
VVV
 V 

 (( 
((((
VVVV
 VV 

 ((( 
(((((
VVVVV
 VVV 
  V  

N = 101のペーストビンです。

そして、ここに未使用のPython 3リファレンス実装があります:

N = int(input())
ic = [[' '] * N for _ in range(N)]
for y in range(N//2):
    for x in range(N):
        if (x - (N - 1) / 2)**2 + (y - (N - 1) / 2)**2 < (N / 2)**2:
            ic[y][x] = '('
for y in range(N//2, N):
    for x in range(y - N//2, N - (y - N//2)):
        ic[y][x] = 'V'
for line in ic:
    print(''.join(line))

詳細

  • stdin、コマンドライン、または関数の引数から入力を取得します。stdoutまたは同様のものへの出力、または関数を記述する場合は文字列を返すことができます。
  • コーン部分は、すべてのNのリファレンス実装と正確に一致する必要があります。
  • アイスクリーム部分は、すべてのNに対して明らかに半円の形状である限り、参照実装と完全に一致する必要ありませ(これは、丸め誤差による半円のわずかな違いを心配する必要がないためです) )
  • 不要な先行スペースはありませんが、余分な後続スペースが存在する場合があります。
  • 出力には、オプションで末尾の改行を含めることができます。
  • オプションで、、、およびスペースの代わりに(、他の3つの印刷可能なASCII文字を使用できVます。

得点

バイト単位の最短提出勝ちです。Tiebreakerは最も古い提出物に進みます。


6
タイトルを読んだときに「IceCII ASCream」を考えたのは私だけですか?
Sp3000

15
SP3000うわあ、私はそう願って... @
カルバンの趣味

回答:


7

CJam、46バイト

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

{:Z{Z{Z(2./:R-zYR<):P#YR-zP#+Z2./P#>SP?}/N}fY}

これは現在、元の仕様を正確に模倣していると思います。これは、この回答を作成し始めたときに必要でした。元の仕様に対する数学の精度を下げることで数バイトを節約できる可能性がありますが、1バイトまたは2バイト以上を節約する方法が見つかるまで、そのままにしておきます。

説明

{               "Begin block";
  :Z{             "For each y from 0 to input-1";
    Z{              "For each x from 0 to input-1";
      Z(2./:R         "Calculate the radius as (input-1)/2.0";
      -z              "Calculate the horizontal distance from the center";
      YR<):P          "Calculate the power to raise distances to: (y<radius)+1
                       (This results in Euclidean distance being calculated for
                        the ice cream and Manhattan distance being calculated
                        for the cone)";
      #               "Raise the horizontal distance to the determined power";
      YR-zP#          "Calculate the vertical distance from the center and
                       raise it to the determined power";
      +               "Add the horizontal and vertical distances";
      Z2./P#          "Calculate the solid distance threshold and raise it to
                       the determined power";
      >SP?            "If the solid threshold is exceeded, produce a space;
                       otherwise, produce the determined power digit
                       (This results in ice cream being represented by the
                        digit '2' and the cone by the digit '1')";
    }/              "End x loop";
    N               "Produce a new line";
  }fY             "End y loop";
}               "End block";

これが表示されますが使用する2のと1代わりにS ' (さんとVさん?
マークリード

@MarkReedこれは許可されています。詳細セクションの最後の行。
ジャクベ

3

インカ2 129 123 121 111 107

これは主にpythonの例の式を使用しますが、二重ループではなくjot-dotsとiotasを使用します。このi関数は、関数に対してjot-dotjを呼び出す循環テストを実行します。そして、関数は関数の三角形テストを実行します。この関数は結果をcatenates とし、N×Nにそれを再形成します。klcjl

編集:-6 2つのマップを1に結合します。
編集:-2無駄なラベルを削除します。
編集:より良いタイプスクリプト。
編集:-10繰り返し式を配列ごとに適用します。
編集:-4繰り返し式を関数として除外します。
編集:ごとの解説。

q:y-(n-1)%2
i:[((n%2)^2)>+/(qx y)^2
j:(~[y%2)i.(~y)
k:2*[x>[|qy
l:(@1+~]y%2)k.(~y)
c:y y#((jn<y),ly){' (V' 

より詳細には、エントリポイントは、c暗黙的にnamedという1つの引数を取る関数yです。

c:y y#((jn<y),ly){' (V' 
         n<y            } assign y to 'n'
        jn<y            } call j(y)
              ly        } call l(y)
      ((    ),  )       } catenate the results
      (         ){' (V' } map 0 1 2 to ' ' '(' 'V'
  y y#                  } reshape to NxN

j関数は、同じ入力値を受信するyパラメータ。

j:(~[y%2)i.(~y)
     y%2         } y divided by 2
    [            } floor
   ~             } iota. this generates the row indices 0..y/2
            ~y   } iota y. this generates the column indices 0..y
  (     )i.(  )  } jot-dot with the function i

ここでのドットドットは二重ループを実行します。i左右の配列(0..n / 2および0..n)の要素のすべての組み合わせで関数を呼び出します。そうi関数は、として受け取るYテーブルのインデックス、そして、それはとして受け取るXの指数。名前はここで少し逆戻りしました:)。xy

i:[((n%2)^2)>+/(qx y)^2
     n%2                 } n divided by 2
    (n%2)^2              } squared
                 x y     } make a 2-element array (x,y)
                qx y     } call q on this array

どこqません

q:y-(n-1)%2
     n-1    } n minus 1
         %2 } divided by 2
  y-        } y minus that

戻る i

i:[((n%2)^2)>+/(qx y)^2
               (    )^2  } square the result from q(x,y)
             +/          } sum the two numbers
            >            } compare the left side (above) with the right (=> 0/1)
  [                      } floor

床は必要ありません。しかし、どうやらインタプリタにバグがあります。

lこの関数はと同じように動作jJOT-ドットを使用して、機能。

l:(@1+~]y%2)k.(~y)
        y%2         } y divided by 2
       ]            } ceiling
      ~             } iota 0..ceil(y/2)-1
    1+              } add 1 => 1..ceil(y/2)
   @                } reverse => ceil(y/2)..1
               ~y   } iota y  0..y-1
  (        )k.(  )  } jot-dot using k

このk関数は、マッピングで後で値をアイスクリームの値と区別できるように、2でスケーリングされるブール値を生成します。

k:2*[x>[|qy
     x       } k's left arg
         qy  } y-(n-1)%2
        |    } abs
       [     } floor
     x       } left-hand-side again
      >      } compare 
    [        } floor (should be unnecessary)
  2*         } scale by 2

アクション(trREPLのプロンプトであるタブ文字を削除するためにパイピング):

josh@Z1 ~/inca
$ ./inca2 <icecream | tr -d '\t'

c1
V

c2
((
VV

c3
(((
VVV
 V 

c4
 (( 
((((
VVVV
 VV 

c5
 ((( 
(((((
VVVVV
 VVV 
  V  

josh@Z1 ~/inca
$ 

2

Python 2、193 192

文字列を使用せず、数学のみ

N=input()
R=(N+1)/2;r=range(R)
s=lambda L,U:(10**U-10**L)/9
f=lambda N,m:s(0,N)+s(m,N-m)
g=lambda N,m:s(0,N)+s(m,N-m)*6
for i in r[1:]:print f(N,int(R-(2*R*i-i*i)**.5))
for i in r:print g(N,i)

s(L,U)U右端のLゼロと残りの1
f(N,m)桁の-digits 」の形式の数を返します。各セクションの内側セクション2とm幅の境界線が同じN桁の数値を返しますが、「色」に使用します円錐のテクスチャにより密接に一致するため、内部セクションの1
g(N,m)7

出力

N=8         N=9
11122111    112222211
12222221    122222221
22222222    222222222
22222222    222222222
77777777    777777777
17777771    177777771
11777711    117777711
11177111    111777111
            111171111

非常にユニークな方法:)
カルビンの趣味

アイスクリームも見ることができれば:P
オプティマイザー

2

Perl 6、175

多くのゴルフをせずに、非常に簡単な実装、ただの余分な空白/句読点の除去:

sub MAIN($d){my$r=($d/2).Int;for 1..$r ->$n
{my$y=$n-$r;my$h=sqrt($r*$r-$y*$y).Int;my$w=2*$h+$d%2;say
' 'x($r-$h)~'('x$w};for 1..($d-$r) ->$y {say ' 'x($y-1)~'V'x($d-2*$y+2)}}
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.