城の階段を作ってください!


13

印刷可能なASCII(改行なし)で構成される文字列が与えられます。あなたの仕事は、私の城に素敵な階段を作ることです。

素敵な階段を構築するには?

  • まず、文字列のすべての回転を取得する必要があります。たとえば、文字列abcdには次の回転があります:(abcd, bcda, cdab, dabc各文字は最後の文字に達するまで最後に移動します)。

  • 各回転を互いの上に配置します。

    abcd
    bcda
    cdab
    dabc
    
  • 真っ直ぐな壁には登れないので、階段を作らなければなりません。つまり、ローテーションリストのインデックスに対応する各ローテーションの前にいくつかのスペースを追加する必要があります。

    abcd
     bcda
      cdab
       dabc
    
  • また、私の城の反対側にリンクする階段が必要なので、以下のような階段を作成し、各回転を反転させて間隔を追加する必要があります。

    abcd      dcba
     bcda    adcb
      cdab  badc
       dabccbad
    

これはであるため、バイト単位の最短コードが優先され、タグの標準ルールが適用されます。


テストケース

  • 入力:abcd、出力:

    abcd      dcba
     bcda    adcb
      cdab  badc
       dabccbad
    
  • 入力:aaaa、出力:

    aaaa      aaaa
     aaaa    aaaa
      aaaa  aaaa
       aaaaaaaa
    
  • 入力:Code golf、出力(スペースに注意してください):

    Code golf                flog edoC
     ode golfC              Cflog edo 
      de golfCo            oCflog ed  
       e golfCod          doCflog e   
         golfCode        edoCflog     
         golfCode        edoCflog     
          olfCode g    g edoCflo      
           lfCode go  og edoCfl       
            fCode gollog edoCf
    


階段が上がり始めて、降りてから降りるのではなく、降りるのではないでしょうか?:P
スティーブン

@StepHenこの挑戦の目的のために、それはすべきではありません:p
Mr Xcoder


dabc。-------
オリバーNi

回答:


8

05AB1E、12バイト

コード:

vDNúsÀ}\».B∞

05AB1Eエンコードを使用します。オンラインでお試しください!

説明:

v     }        # Length input times, do.. (N = iteration count)
 DNú           #   Duplicate and prepend N spaces
    sÀ         #   Swap and rotate one to the left
       \       # Discard the top of the stack
        »      # Join the stack by newlines
         .B    # Pad with spaces into a rectangle
           ∞   # Mirror the string



3

網膜、47バイト

.
$.`$* $&$'$`$.'$* ¶
%(`^
$_¶
O$^`.(?=.*$)

¶

オンラインでお試しください!説明:最初の段階では、各文字を考慮し、現在の位置に等しいスペース、文字列の残り、文字列の先頭、文字列の残りに等しいスペースを作成して、左階段を作成します。残りのスクリプトは、生成された各行で順番に実行されます。最初に行が複製され、次に複製内の文字が反転され、次に行とその複製が連結されます。




2

23 21 20バイト

FLθ«FLθ§θ⁺κι↘MLθ←»‖C

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

おそらくもっとゴルフができますが、モバイルアプリから投稿しています。詳細バージョンリンク。


ああ、ところで、あなたは、少なくとも使用時の説明を追加していない場合はフラグ-a PLS
ASCIIのみの

@ASCIIのみ申し訳ありませんが、詳細バージョンは説明としてカウントされると思いました。
チャーリー

その表示されませんでしたどのようなNVM待って
ASCIIのみの

当時はそうではなかったと思いますが、最近では任意の文字列で多角形を埋めることができ、9バイトに必要な結果を正確に得ることができますG→↘←Lθθ‖C
ニール

2

Haskell、80 79バイト

(s:u)#t|q<-(t>>" ")++s:u++t++(u>>" ")=q++reverse q++'\n':u#(t++[s])
u#_=u
(#"")

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

使い方

(#"")                      -- start with the input string and an empty accumulator

(s:u)#t                    -- let s be the first char and u the rest of the input
                           -- string, and t the accumulator
    |q<-                   -- let q be half of the current line, i.e.
        (t>>" ")++         --   length of t times spaces
        s:u++              --   s and u (aka the input string)
        t++                --   the accumulator
        (u>>" ")           --   length of u times spaces
    = q ++ reverse q ++    -- the current line is q and q reversed
        '\n' :             -- and a newline
        u#(t++[s])         -- and a recursive call with u as the new input
                           -- string and s put at the end of t
_#_=[]                     -- base case: stop if the input string is empty

編集:1バイトありがとう@ØrjanJohansen。


u#_=uバイトを保存します。
Ørjanヨハンセン

@ØrjanJohansen:最初に文字列のリストを持っていて、 unlinesそこでu#_=uはタイプチェックを行わず、後で単一の文字列の作成に切り替えました...ありがとう!
nimi



1

Mathematica、119バイト

b=StringRotateLeft;j=Table;Column@j[""<>{" "~j~i,b[s=#,i],j["  ",t-i],b[StringReverse@s,-i]},{i,0,t=StringLength@#-1}]&

1

PHP、95バイト

for($e=strlen($s=$argn);$i<$e;$s.=$s[$i],$s[$i++]=" ")echo$t=str_pad($s,2*$e-1),strrev($t),"
";

パイプとして実行する-nR、オンラインで試してください

壊す

for($e=strlen($s=$argn);    # import input
    $i<$e;                  # loop length times
    $s.=$s[$i],                 # 2. append current character
    $s[$i++]=" ")               # 3. set current character to space
    echo$t=str_pad($s,2*$e-1),  # 1. print string padded with length-1 spaces
        strrev($t),             #    print reverse
        "\n";                   #    print newline

1

Japt、22バイト


l
VÇç +UéZn)+´Vç)ê1÷

主要な改行はプログラムの一部です。

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

WIP CodePenを使用してすべてのテストケース実行します

説明

暗黙的:U=入力文字列。最初の行は、上書きしないように空白Uです。

2行目は、暗黙的に長さ(割り当てlの)UにしますV

3行目:

VÇç +UéZn)+´Vç)ê1÷
VoZ{Zç +UéZn)+--Vç)ê1} · Ungolfed
VoZ{                 }   Create array [0, V) and map by...
    Zç                      The current value (Z) times " "
       +UéZn)               Concatenated with U rotated Z times left
             +--Vç)         Concatenated with --V times " ". This decrements V
                   ê1       Palindromize with repeated last char
                       · Join with newlines and implicitly output


1

Javascript(ES6)、118バイト

s=>[...s].map((_,y)=>Array(l=(j=s.length)*4-2).fill().map((_,x)=>(x=x<l/2?x:l-x-1)>=y&y+j>x?s[x%j]:" ").join``).join`
`

サンプルコードスニペット:

f=
s=>[...s].map((_,y)=>Array(l=(j=s.length)*4-2).fill().map((_,x)=>(x=x<l/2?x:l-x-1)>=y&y+j>x?s[x%j]:" ").join``).join`
`
o.innerText=f("Code golf")
<pre id=o>



1

8番目173 168バイト

コード

s:len n:1- ( >r dup s:len n:1- "" ( " " s:+ ) rot times dup 0 r@ s:slice -rot r> -1 s:slice s:+ s:+ dup s:rev swap . . cr null s:/ a:shift a:push "" a:join ) 0 rot loop

コメント付きの未ゴルフバージョン

: shifter \ s -- s
  null s:/     \ convert string into array
  a:shift      \ remove the first item in the array and put it on TOS
  a:push       \ append the former 1st item to array
  "" a:join    \ convert array into string
;

: stairway \ s -- s
  s:len n:1-
  (
    >r                       \ save loop index
    dup                      \ duplicate input string 
    s:len n:1-               \ get string length
    "" ( " " s:+ ) rot times \ make filler
    dup                      \ duplicate filler 
    0 r@ s:slice             \ make left filler
    -rot                     \ put left filler at proper position
    r> -1 s:slice            \ make right filler
    s:+ s:+                  \ build string ( 1st half of stairway )
    dup s:rev                \ build 2nd half 
    swap . . cr              \ print it
    shifter                  \ shift rotate 1st character
  ) 0 rot loop               \ loop from 0 to len(string)-1
;

使用法と例

ok> "abcd" s:len n:1- ( >r dup s:len n:1- "" ( " " s:+ ) rot times dup 0 r@ s:slice -rot r> -1 s:slice s:+ s:+ dup s:rev swap . . cr null s:/ a:shift a:push "" a:join ) 0 rot loop
abcd      dcba
 bcda    adcb 
  cdab  badc  
   dabccbad 

またはより明確に

ok> "Code golf" stairway
Code golf                flog edoC
 ode golfC              Cflog edo 
  de golfCo            oCflog ed  
   e golfCod          doCflog e   
     golfCode        edoCflog     
     golfCode        edoCflog     
      olfCode g    g edoCflo      
       lfCode go  og edoCfl       
        fCode gollog edoCf 
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.