ピラミッドスキーム


13

マヤのピラミッドは、古代の建築の重要な部分であり、一般的に宗教目的に使用されていました。

それらは通常階段状のピラミッドでしたが、それぞれの階段は登るにはあまりにも急でした。司祭は儀式を行うために別の階段を介して彼らの頂点に登ります。ピラミッドは、その高さのためにランドマークとしても使用され、時には高官の埋葬地としても使用されました。


チャレンジ

ユーザー仕様に基づいてピラミッドの回路図を印刷できるプログラムを作成します(以下を参照)。


必要条件

  • スペースで区切られた2つの変数の入力を受け取ります。

  • 入力は、STDIN(または最も近い代替手段)を介して受け入れられる必要があります。

  • 出力は、STDOUT(または最も近い代替)を介して行われる必要があります。


入力

  • 正の整数としての高さ。これは、ベースレベルの幅(ブロック単位)として使用されます。ピラミッドの各後続のレベルは、幅有する(ブロックで)前床の幅です。n - 1n

  • 1または任意の奇数の正の整数≤(より小さい)になるブロックサイズ。


ブロック

指定されたブロックサイズによって、個々のピースの幅(および高さ)が決まります。基本的に、ブロックサイズがi^2表示されているボックス内にスペースがありますi

1x1ブロックは次のようになります。

+++
| |
+++

5x5ブロックは次のようになります。

+++++++
|     |
|     |
|     |
|     |
|     |
+++++++

水平方向に隣接するブロック

水平に並んだブロックは、中央の壁を1つに結合する必要あります。

これが必要です:

+++++
| | |
+++++

このようなものの代わりに:

++++++
| || |
++++++

垂直方向に隣接するブロック(-5%のボーナス)

縦に並んだブロックには特別な例外があります。中央の壁を1つに統合できます。

したがって、1x1ブロックの代わりに次のようになります。

 +++
 | |
 +++
+++++
| | |
+++++

彼らは可能性があり、このようになります。

 +++
 | |
+++++
| | |
+++++

Input: 3 1

Output:

  +++
  | |
  +++
 +++++
 | | |
 +++++
+++++++
| | | |
+++++++

OR

  +++
  | |
 +++++
 | | |
+++++++
| | | |
+++++++

Input: 2 3

Output:

  +++++
  |   |
  |   |
  |   |
  +++++
+++++++++
|   |   |
|   |   |
|   |   |
+++++++++

OR

  +++++
  |   |
  |   |
  |   |
+++++++++
|   |   |
|   |   |
|   |   |
+++++++++

スコアボード

スコアボードでランク付けするには、回答を次の形式で入力します。

# Language, Score

または、ボーナス-5%を獲得した場合:

# Language, Score (Bytes - 5%)

あなたのスコアは整数です。スコアが小数の場合、整数に切り上げます。


最小入力は何ですか?1 1
mınxomaτ

はい、単一のブロックになります。@minxomat「入力」セクションで説明します。
ザックゲイツ

入力は何を3 2生成しますか?
Hand-E-Food

「入力」セクションの下の2番目の箇条書きによると、2番目の入力整数は奇数でなければなりません。@ Hand-E-Foodのような入力に対して何が起こるかを尋ねるつもりだった2 3場合、前のフロアの幅がブロックn - 1 = 0nあるときに終了します。
ザックゲイツ

@ZachGates、ありがとう!気にしないで。明らかにコーヒーは私に失敗しました。
Hand-E-Food

回答:


1

Pyth、45(47バイト-5%)

AmvdczdVGjm.[Jh*GhHj*H?d\ \+*+2N?d\|\+\ hH;*J\+

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

                                                   Implicit: z=input(), d=' '
    czd                                            Split input on spaces
 mvd                                               Evaluate each part of the above (convert to int)
A                                                  Store the pair in G,H
             Jh*GhH                                J = 1+(G*(H+1))
       VG                                          For N in [0 to G-1]:
          m                             hH;          Map d in [0 to H] to:
                                ?d\|\+                 Get '|' or '+' (vertical edges or corners)
                            *+2N                       Repeat the above (N+2) times
                      ?d\ \+                           Get ' ' or '+' (block centre or horizontal edge)
                    *H                                 Repeat the above H times
                   j                                   Join (|/+) by (   /+++)
           .[J                        \                Centrally pad the above to width J using spaces
         j                                           Join on newlines, implicit print
                                           *J\+    Get J '+'s, implicit print

1
+1。絶対に遅れることはありません。:P
ザック・ゲイツ

11

JavaScript(ES6)、161 (169-5%)166(174-5%)

テンプレート文字列を使用すると、2つの改行が重要でカウントされます。

EcmaScript 6ブラウザーで以下のスニペットを実行してテストします。Firefoxでは問題ありません。Chromeではなく、割り当ての破壊をサポートしていません。

スニペットの後に説明されているコード。

/*Test: redefine console.log*/ console.log=x=>O.innerHTML+=x+'\n';

for([h,b]=prompt().split` `,g='+'[R='repeat'](-~b),f=' '[R](b),n=o='';h--;o+=e+(d=g[R](++n)+`+
`)+f.replace(/./g,e+('|'+f)[R](n)+`|
`))e=' '[R](h*-~b/2);console.log(o+d)
<pre id=O></pre>

少ないゴルフ

[h, b] = prompt().split` `; // get the space separated input values
c = -~b; // Add 1 to b. As b is of string type b+1 would be a string concatenation
g = '+'.repeat(c); // top border
f = ' '.repeat(b); // inner blank row
o = ''; // initialize output string
for(n = 0; h > 0; --h) // loop on height
{
   ++n;
   e = ' '.repeat(h*c/2); // blanks for offset from left margins
   d = g.repeat(n) + `+\n`; // top border repeated, then right end and newline
   // the block body is squared, there are as many rows as columns inside
   // so I can build the right number of rows replacing the chars in a single row
   o += e + d + f.replace(/./g, e + ('|'+f).repeat(n)+`|\n`)
}
o += d // add last top border as bottom
console.log(o)    

9

ルビー、124(130-5%)

n=(g=gets).to_i
b=g[-2].to_i+1
a=(0..n*b-1).map{|i|[?+*(i/b*b+b+1),(?|+' '*(b-1))*(i/b+1)+?|][i%b<=>0].center(n*b+1)}
puts a,a[-b]

コメント付き

n=(g=gets).to_i                                  #get input and interpret as a number for pyramid height (everything after the space is ignored)
b=g[-2].to_i+1                                   #the single-character block size is the second last character (just before the newline.) Add 1 to give the pitch between squares.
a=(0..n*b-1).map{|i|                             #run through all lines except the last one
[?+*(i/b*b+b+1),                                 #calculate number of + symbols
(?|+' '*(b-1))*(i/b+1)+?|]                       #or alternatively, pattern '|    |'
     [i%b<=>0]                                   #check if i%b is zero or positive to decide which to print
     .center(n*b+1)}                             #centre the text. It will be mapped to the array a.
puts a,a[-b]                                     #a contains the pyramid, minus its last line. Print it, and add the last line

ボーナス-5%を忘れないでください(スコアを124にする)。よくできました!
ザックゲイツ

2

Python 2、117(123バイト)

h,n=map(int,raw_input().split())
p,v='+|'
while h:p+='+'*-~n;v+=' '*n+'|';h-=1;l=~n/-2*h*' ';print l+p+('\n'+l+v)*n
print p

アイデアはレンガトップ構築することであるpとして+++++++++、サイドをv通り| | |。上部はとして開始され+n+1 +の各レイヤーによって拡張されます。サイドは|として始まり、nスペースとaで補強されます|。各レイヤー、上部と側面を補強し、上部を1つ印刷し、nます。

それらを中央に配置するために、最初にインデントを印刷しlます。これは、現在の高さに応じて拡大縮小されるいくつかのスペースで構成されhます。それを更新するために、hヒットするまで高さ変数をデクリメントし0、その後、現在のレイヤーが画面の左端に対してフラッシュされます。一番上をもう一度印刷して、一番下のレイヤーを作成しました。


0

Python 2、200(210-5%)

a,b=map(int,raw_input().split());c=0;a+=1;i=a*b+a-b;e=[i*'+']
while a-1:
 v=(('|'+' '*b)*a).rstrip();p=' '*((i-len(v))/2);a-=1;c+=1
 for u in range(b):e.insert(0,p+v)
 e.insert(0,p+'+'*len(v))
print'\n'.join(e)

文字列の乗算を使用し、余分なスペースを削除しました。

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