Gimbapカッターを作る


23

ジンバップ(김밥)は韓国料理で、やや巻き寿司のように見えます。

韓国の顔文字はGimbapを表しています: @))))))))))

あなたの探求は、ASCII Gimbapカッターを作ることです。

ルール

入力はとのみ@で作成された文字列)です。

出力は、すべての有効なGimbapをでカット) @それらの間に追加します。例えばそう@))@) @)

有効なGimbapはで始まり@、その後に任意の量が続き)ます。

有効なGimbapがない場合、出力は空白です。

入出力

Input | Output
@))))) | @) @) @) @) @)
@))))))) | @) @) @) @) @) @) @)
@))@))) | @) @) @) @) @)
@) | @)
)) | 
@ | 
@@)@@@))) | @) @) @) @)
@)@)@)) | @) @) @) @)
@@@)) | @) @)
))@) | @)

勝利条件

これはなので、最短のコードが優先されます。

サンドボックスから


2
出力のコピー」にルールと同等である@) すべてのための)入力で任意の前にそれらを数えていないが@、私たちの出力のような、末尾にスペースを含めることはできますか?"@) @) "
XNOR

そうです。また、出力には末尾スペースを含めることができます。
LegenDUST

スペースで区切られた文字列を出力する必要がありますか、またはスライスの配列を出力できますか?また、これらの2文字に制限されていますか、または選択した2文字を使用できますか?
シャギー

タイトルを読んでみた「Gimp-bat clutter?what?」
Draco18s

回答:












2

バッチ、58バイト

@set s=%1@
@set s=%s:*@=(%
@set s=%s:@=%
@echo%s:)=@) %

入力をコマンドラインパラメーターとして受け取ります。説明:

@set s=%1@

@入力に何も含まれていない場合のサフィックス。

@set s=%s:*@=(%

最初まで削除し、文字列が空でないことを確認するため@にそれを置き換え(ます(空の文字列では%:%機能しないため)。また、文字列の残りが空の場合に(も機能しますecho

@set s=%s:@=%

残り@のを削除します。

@echo%s:)=@) %

残り)のを展開します。



2

Japt v2.0a0、15 -Sバイト

r/^\)+|@/ ¬mi'@

それを試してみてください

r/^\)+|@/ ¬mi'@     :Implicit input of string
r                   :Remove
 /^\)+|@/           :  "@"s and leading ")"s
          ¬         :Split
           m        :Map
            i'@     :  Prepend "@"
                    :Implicit output, joined with spaces

代替案

e/^\)/ è\) Æ"@)

それを試してみてください

e/^\)/ è\) Æ"@)     :Implicit input of string
e                   :Recursively remove
 /^\)/              :  Leading ")"
       è\)          :Count remaining ")"s
           Æ        :Map the range [0,Count)
            "@)     :  Literal string
                    :Implicit output, joined with spaces





1

ルビー -p、28バイト

$_= ~/@/&&'@) '*$'.count(?))

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

説明

                                # -p gets a line of STDIN
$_=                             # Set output to
    ~/@/                        # Find first '@' in input
                                # nil (falsey) if not found
        &&                      # If found, set output to
          '@) '                 # Sliced gimbap
               *                # Repeat
                $'              # In the string after the first '@',
                  .count(?))    # ... count the number of ')'
                                # -p outputs the contents of $_
                                # nil outputs as a blank string


1

sed、30バイト

s/)\?@\()\?\)/\1/g; s/)/@) /gp

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


PPCGへようこそ。残念ながら、コードは先頭)と複数を@適切に処理できません。また、Try it onlineを使用しどうですか?
LegenDUST

1
5番目または最後の例でわかるように、先頭)のsは無視する必要があります。
LegenDUST

@LegenDUST、あなたは正しいです!簡単ではありませんでした。作業バージョンの方がずっと雑だと思います
Vicente Bolea

28文字:s / ^)* //; s / [^)] // g; s /./@)/ gp
jnfnt


1

Pyth、20バイト

*?}\@z/>zxz\@\)0"@) 

オンラインでお試しください!プログラムの最後に末尾のスペースがあることに注意してください。これは(または、むしろ、として開始された)Python 2の回答のかなり直接的な翻訳です(ただし、lstripの部分は驚くほど困難でした)。

説明:

*            # repeat string
  ?          # repeat count: ternary
    }\@z     # condition: check whether input contains @
    /        # if condition is true: count occurrences of one string in another
      >      # array slice: all elements of array (or string) from a specific index and upwards
        z    # the thing to slice (input)
        xz\@ # the index first occurrence of \@ in z
      \)     # string to count occurrences of (\x is shorthand for "x")
    0        # value when ternary condition is false
  "@) "      # the string to be repeated (automatically terminated by end-of-line)

1

krrp、63バイト

^":\L,^*':?#?E'E!-@1#!r'?=#!f'$64.-?*L$64.L$41.L$32.-@0#!r'.0".

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


説明

^":                   ~ take the string as a parameter named `"`
 \L                   ~ import the list module
 ,^*':                ~ apply a binary function
  ?#?E'               ~  if the string is empty,
   E                  ~   return the empty string; else
   !-@1#!r'           ~   define `-` as the cut Gimbap
   ?=#!f'$64.         ~    if an at sign is seen,
    -                 ~    return the cut Gimbap; else
    ?*                ~    if an at sign has been seen,
     L$64.L$41.L$32.- ~     return a Gimbap piece together
                      ~     with freshly cut Gimbap; else
     @0#!r'           ~     proceed to cut
 .0".                 ~ to zero and the above taken string

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


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