Crea un cutter Gimbap


23

Gimbap (김밥) è cibo coreano, in qualche modo sembra un rotolo di sushi.

Ecco che l'emoticon coreana rappresenta Gimbap: @))))))))))

La tua ricerca è di creare un cutter ASCII Gimbap.

Regola

L'input è una stringa creata con solo @e ).

L'output taglia ogni Gimbap valido )e quindi aggiunge @tra di loro. Così, per esempio @))a @) @).

Gimbap valido inizia con @e seguito da qualsiasi importo di ).

Se non esiste un Gimbap valido, l'output è vuoto.

Ingresso e uscita

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

Condizioni vincenti

Questo è , quindi vince il codice più corto.

dalla sandbox


2
La regola equivale a "emettere una copia di @) per ogni )nell'input senza contare quelli precedenti @? Può il nostro output includere uno spazio finale, come "@) @) "?
xnor

È. E l'output può includere uno spazio finale.
LegenDUST,

Dobbiamo generare una stringa delimitata da spazio o possiamo generare una matrice di sezioni? Inoltre, siamo limitati a quei 2 caratteri o possiamo usare 2 caratteri qualsiasi di nostra scelta?
Shaggy

La prima volta che provo a leggere il titolo "Disordine gimp-bat? Cosa?"
Draco18s

Risposte:




5

C (gcc) , 53 byte

i;f(char*_){for(i=1;*_;!i&*_++&&printf("@) "))i&=*_;}

Provalo online!

i;f(char*_){for(    *_;                      )      }   //loop over the string:
                i=1;   !i&                    i&=*_;    //skip leading `)`s
                       !i&*_++&&printf("@) ")           //and print "@) "for each `)` thereafter



4

Retina 0.8.2 , 14 byte

^\)+|@

\)
@) 

Provalo online! Il link include casi di test. Spiegazione:

^\)+|@

Elimina i primi )e tutti i @secondi.

\)
@) 

Sostituisci tutte le )s con @)s. (Nota: spazio finale).





2

05AB1E , 12 byte

')Û'@KS'@ìðý

Provalo online!

Spiegazione

')Û            # trim leading ")"
   '@K         # remove all "@"
      S        # split to list of characters
       '@ì     # prepend "@" to each
          ðý   # join on spaces

2

Lotto, 58 byte

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

Accetta l'input come parametro della riga di comando. Spiegazione:

@set s=%1@

Suffix an @nel caso in cui l'input non ne contenga alcuna.

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

Elimina fino al primo @, sostituendolo con a (per garantire che la stringa non sia vuota (perché %:%non funziona su stringhe vuote). La (rende anche il echolavoro se il resto della stringa è vuota.

@set s=%s:@=%

Elimina eventuali messaggi rimanenti @.

@echo%s:)=@) %

Espandi eventuali rimanenti ).



2

Japt v2.0a0 -S, 15 byte

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

Provalo

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

Alternativa

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

Provalo

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

Rubino -p , 28 byte

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

Provalo online!

Spiegazione

                                # -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 byte

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

Provalo online!


Benvenuti in PPCG. Sfortunatamente, il tuo codice non è in grado di gestire correttamente )i principali e multipli @. E che ne dici di usare Provalo online ?
LegenDUST,

1
Come puoi vedere nel quinto o ultimo esempio, i primi )devono essere ignorati.
LegenDUST,

@LegenDUST, hai ragione! non è stato così facile. Immagino che la versione funzionante sia molto più brutta
Vicente Bolea l'

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


1

Pyth , 20 byte

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

Provalo online!Si noti che c'è uno spazio finale alla fine del programma. Questa è (o meglio, iniziata come) una traduzione piuttosto diretta della risposta di Python 2 (sebbene la parte di lstrip fosse sorprendentemente difficile).

Spiegazione:

*            # 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 byte

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

Provalo online!


Spiegazione

^":                   ~ 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

Provalo online!


1

PowerShell , 42 byte

''+($args|sls '(?<=@.*)\)'-a|% m*|%{'@)'})

Provalo online!

srotolato:

$arrayOfCuttedGimbaps = $args|select-string '(?<=@.*)\)' -AllMatches|% Matches|%{'@)'}
''+($arrayOfCuttedGimbaps)    # toString and output
Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.