!Einfügen! ! n! b! e! t! w! e! e! n!

24

Gepostet von hier .

Diese Herausforderung ist aus dieser Frage hoch "destilliert" . Besonderer Dank geht an @Akababa!

In dieser Aufgabe sollten Sie am Anfang der Zeichenfolge und nach jedem Zeichen ein Ausrufezeichen einfügen.

Regeln

  • Es wird immer eine nicht leere Zeichenfolge eingegeben. Die Eingabe enthält auch keine Registerkarten. Sie können davon ausgehen, dass die Eingabe nur nicht erweiterte druckbare ASCII-Zeichen und Zeilenumbrüche enthält.
  • Die Eingabe enthält keine nachgestellten Zeilenumbrüche, solange Ihre Sprache keine Zeilenumbrüche erkennt.
  • Dies ist ein Wettbewerb; Die kürzeste Antwort sollte gewinnen.

Beispiele

  • 4 Zeilenumbrüche führen zu 5 durch Zeilenumbrüche getrennten Ausrufezeichen. Es ist sehr schwierig, diesen Text als Markdown-Text zu definieren, daher wird dies stattdessen angegeben.
1 2 3 4 5 6
129591 129012 129127 129582

0

Ausgänge

! 1! ! 2! !3! ! 4! ! 5! ! 6!
! 1! 2! 9! 5! 9! 1! ! 1! 2! 9! 0! 1! 2! ! 1! 2! 9! 1! 2! 7! ! 1! 2! 9! 5! 8! 2!
!
! 0!
asd afjoK ak: e
kPrLd
    fOJOE;
    KFO
KFkepjgop sgpaoj faj

Ausgänge

! a! s! d! ! a! f! j! o! K! ! a! k!:! e!
! k! P! r! L! d!
! ! ! ! ! f! O! J! O! E!;!
! ! ! ! ! K! F! O!
! K! F! K! E! P! J! G! O! P! ! s! g! p! a! o! j! ! ! ! f! a! j!

Ein Basistestfall mit nur einem Zeichen:

ein

Ausgänge

!ein!

(Auto-Vervollständigung! Nur ein Scherz, so etwas gibt es nicht.) Enthält Ausrufezeichen:

!!
!!
!!
!!
!!

Ausgänge:

!!!!!
!!!!!
!!!!!
!!!!!
!!!!!
EIN
quelle
7
Ich verstehe die Ablehnung wirklich nicht - dies ist eine klare und gut geschriebene Herausforderung. Re: ein Duplikat zu sein - es ist nicht (das vorangestellte '!' Macht einen großen Unterschied), und ich glaube nicht, dass jemand dies vorgeschlagen hat (keine engen Abstimmungen).
Jonathan Allan
1
Wenn eine Sprache den Unterschied zwischen a\nund nicht erkennen akann, können wir dann verlangen, dass keine Zeilenumbrüche folgen?
Giuseppe
13
Zwischen den einzelnen Upvotes werden Downvotes eingefügt, so wie es die Herausforderung beschreibt.
A
2
Das ist tot.
V. Courtois

Antworten:

12

Python 3 , 27 Bytes

lambda s:f"!{'!'.join(s)}!"

Probieren Sie es online!

Ehrlich gesagt hoffe ich, dass mir jemand einen coolen Weg zeigen kann, dies mit einer geringeren Anzahl von Bytes zu tun.

Setzen Sie Monica wieder ein
quelle
Dies behandelt die Leerzeile nicht richtig
Flocken
@flakes Was meinst du? Wenn Sie eine leere Zeichenkette meinen: Wir brauchen keine leere Zeichenkette zu behandeln (und unabhängig davon !!, was in diesem Fall für mich sinnvoll ist). Wenn du den String meinst \n: Das tut es, da die Ausgabe korrekt ist !\n!.
Jonathan Allan
3
@JAD Soweit ich sehen kann, ist in den Beispielen kein leerer String enthalten. Darüber hinaus heißt es in der ersten Regel wörtlich: "Es wird immer eine nicht leere Zeichenfolge eingegeben."
Setzen Sie Monica
1
Ah, ich habe mich geirrt. Das erste Beispiel enthält eine leere Zeile in der Mitte der Eingabe. Aber diese Antwort behandelt es, das Ausrufezeichen in die Mitte zu setzen !\n!\n!. gute Arbeit.
Flocken
1
codegolf.stackexchange.com/questions/190223/insert-nbetween/… wie Sie sagten, um einen kürzeren Weg zu zeigen
U10-Forward
8

JavaScript (ES6), 19 Byte

Nimmt die Eingabe als Array von Zeichen.

s=>`!${s.join`!`}!`

Probieren Sie es online!


JavaScript (ES6),  23 bis  20 Byte

3 Bytes gespart dank @ShieruAsakoto

Übernimmt die Eingabe als Zeichenfolge.

s=>[,...s,,].join`!`

Probieren Sie es online!


JavaScript (ES6), 22 Byte

Vorgeschlagen von @tjjfvi

Übernimmt die Eingabe als Zeichenfolge.

s=>s.replace(/|/g,"!")

Probieren Sie es online!

Arnauld
quelle
@ tjjfvi Einundsechzig!
Arnauld
5
Ich habe eine 20 für Ihre 23:s=>[,...s,,].join`!`
Shieru Asakoto
7

R , 25 Bytes

function(x)gsub("","!",x)

Probieren Sie es online!

Eine Funktion, die einen Zeichenvektor akzeptiert und zurückgibt.

Nick Kennedy
quelle
Kann 3 Bytes Rasur durch die Funktionsform auf Schalen scan(,''), wie so tio.run/##K/r/P724NElDSUlHSVFJpzg5MU9DR11dU/O/...
Sumner18
@ Sumner18 danke. Ich habe damit angefangen, aber es teilt die Eingabe in Leerzeichen.
Nick Kennedy
1
@ Sumner18 Die Herausforderung besteht darin, Eingaben mit Zeilenumbrüchen zu behandeln, was nicht möglich ist scan(aber mit der Lösung von Nick, zumindest wenn Sie die Ausgabe mit anzeigen cat).
Robin Ryder
7

8086-Computercode, COM-Format (MS-DOS 2+), 32 Byte

(-1 je nach Emulator: siehe unten)

Um die besten Ergebnisse zu erzielen, leiten Sie die Standardeingabe aus einer Datei um, da die Eingabe aufgrund der fehlenden Pufferung eine ungewöhnlich aussehende Ausgabe ergibt. Außerdem sehen Zeilenumbrüche etwas seltsam aus, weil sie als gespeichert CR LFwerden und das CRTeil die Ausgabe durcheinander bringt .

Dieses Programm verhält sich in einer tatsächlichen MS-DOS-Emulation (z. B. PCjs) gut, aber DOSBox schien Probleme mit Strg + Z EOF zu haben (siehe Kommentare in der Assembly-Liste). Versuchen Sie daher NICHT , Eingaben über die Konsole in DOSBox einzugeben, es sei denn, Sie Fügen Sie den zusätzlichen Scheck hinzu!

BB 01 00 53 59 BA 0B 01 B4 40 CD 21 4A 4B B4 3F CD 21 85 C0 74 09 B4 40 43 41 CD 21 49 EB EE C3

Einige interessante Teile:

  • Ich sparte durch die Wiederverwendung von Speicher einige Datenraum , die bereits ausgeführt worden war (die 21Hin INT 21Hsein geschieht !)

  • Ich konnte fast einen interessanten Trick anwenden, den ich auf der Seite "Die verborgene Kraft von BCD-Anweisungen" gefunden hatte, der es mir ermöglicht hätte, AAAanstelle eines Standards TESTeinen Vergleich ALmit 0 durchzuführen und dabei ein Byte zu sparen. Leider ist dies nicht vollständig dokumentiert, so dass ich mich nicht darauf verlassen konnte: PCjs passen zum Beispiel nur die Carry- und Auxiliary-Carry-Flags an. :-(

Assembler-Code (TASM-Idealmodus):

IDEAL
MODEL   TINY

CODESEG
ORG 100H

;; DOSBox (tested with 0.74-2) didn't seem to handle Ctrl-Z as EOF
;; so uncomment the ";;" lines to run it there.
MAIN:
    MOV     BX,1
    PUSH    BX
    POP     CX
    MOV     DX,OFFSET MAIN_1+1  ; The 21H in INT 21H
    MOV     AH,40H
MAIN_1:
    INT     21H
    DEC     DX
    ;;PUSH  DX
    ;;POP   SI
IO_LOOP:
    DEC     BX
    MOV     AH,3FH
    INT     21H
    ;;; This should work on an non-emulated PC. 
    ;;;AAA      ; AL=0?
    TEST    AX,AX
    JZ      DONE
    ;;CMP   [BYTE PTR SI],1AH
    ;;JZ    DONE
    MOV     AH,40H
    INC     BX
    INC     CX
    INT     21H
    DEC     CX
    JMP     IO_LOOP
DONE:
    RET
ENDS
END MAIN
ErikF
quelle
7

Brainfuck , 24 22 Bytes

-2 Bytes dank JoKing.

-[-[-<]>>+<],[>.<.,]>.

Probieren Sie es online!

Krzysztof Szewczyk
quelle
@JoKing danke, ich habe meine Antwort aktualisiert.
Krzysztof Szewczyk
verdammt, das ist verdammt
Cruncher
6

Pepe , 47 Bytes

REREEeRErEErREeeEeeeeEREEeeREEeereeREEEEeeEReee

Probieren Sie es online!

Erläuterung:

REREEeRE # Push 0,then input (str),then 0 -> (R)
         # The zeroes are pushed to correct the inserting
rEE # Begin loop labelled 0 -> (r)
  rREeeEeeeeE # Push "!" -> (R)
              # r flag inserts it instead of pushing
  REEeeREEee # Move pointer pos 2 steps forward -> (R)
ree # Loop while (R) != 0
REEEEeeE # Remove characters of (R) that are in stack of (r)
         # Removes the 0 in (R)
Reee # Output (R)
nicht definiert
quelle
Wie schreibt man diesen Code? Gibt es einen Code-Konverter, den Sie verwenden? Dies scheint verrückt zu sein, um zu versuchen und zu schreiben
Cruncher
1
@Cruncher 1) Ich verwende dies als meine Anleitung. 2) Nein, ich benutze keinen Code-Konverter, ich benutze nur die Anleitung, um den Code zu schreiben.
u_ndefined
6

Labyrinth ,  19 11 10  9 Bytes

33
..
",@

Probieren Sie es online!

Wie?

Wir betreten das Labyrinth oben links mit einem unendlichen Stapel von Nullen ...

                         I / O    stack
                                  0,0,0,...
3 - pop * 10 + 3                  3,0,0,0,...
  - 2 neighbours, forward
3 - pop * 10 + 3                  33,0,0,0,...
  - 2 neighbours, forward
. - pop & print chr          !    0,0,0,...
  - T junction from the side
  -   TOS==0, forward
, - read chr or -1       L        76,0,0,0,...   or   -1,0,0,0
  - T junction from the base
  -   if TOS > 0 right:
" -     no-op                     76,0,0,0,...
  -     2 neighbours, forward
. -     pop & print chr      L    0,0,0,...
  -     T junction from the side
  -       TOS==0, forward
3 -       ...back to the start
  -   elif TOS == -1 left:
@ -     exit                                          we're out!


  * right, but on the first occasion (from above) we hit the wall and turn
    around, so that's like a left

Zum Glück müssen wir nicht druckbare Dateien nicht verarbeiten, sonst würde uns das erste Null-Byte umdrehen ,und Chaos anrichten.

Jonathan Allan
quelle
5

sed , 12 bytes

s/\b\|\B/!/g

Probieren Sie es online!

-3 Bytes dank Cows Quack

Jona
quelle
Tatsächlich ist der Sed-Code nur 15 Zeichen lang: Probieren Sie es online aus! .
Handarbeit
Grosses Dankeschön. Mir war nicht klar, wie das funktioniert ...
Jonah
1
s/\b\|\B/!/gfunktioniert auch für 12 Bytes
Kritixi Lithos
@Cowsquack danke. aktualisiert.
Jonah,
4

Zsh , 32 Bytes

for c ('' ${(s::)1})echo -nE $c!

Probieren Sie es online!

(s::)Teilt sich in Zeichen, ''fügt am Anfang ein leeres Element hinzu und gibt echo -nE $c!jeweils ein Echo gefolgt von einem !.

GammaFunction
quelle
4

Perl 5 -p0, 17 6 bytes

s,,!,g

Try it online!

My original answer was -p and $_='!'.s,.,$&!,gr. Thanks to @Nahuel Fouilleul for cutting 11 bytes and to @Grimy for the -p0 tip.

Kjetil S.
quelle
2
6 bytes
Nahuel Fouilleul
1
@NahuelFouilleul -lp gives incorrect output for the \n\n\n\n test case (returns 4 newline-separated ! instead of the specified 5). -p0 works correctly.
Grimmy
4

6502, 12 bytes (13 bytes if Apple II)

6502

The machine code assumes that a pair of zero page locations are connected to character input ($FE) and output (FF) hardware. Many 6502-based systems facilitate I/O in this fashion, albeit I/O address are usually not in zero page.

For simplicity, I used Py65, a 6502 microcomputer system simulator written in Python.

Hier ist ein Speicherauszug von Py65. Sie können den folgenden Code an einer beliebigen Stelle auf der Nullseite laden, sodass sich $ FE und $ FF nicht überschneiden.

       PC  AC XR YR SP NV-BDIZC
6502: 0000 00 00 00 ff 00110010
.mem 0:b
0000:  a9  21  85  ff  a5  fe  f0  fc  85  ff  d0  f4

In einem Windows-Befehlsfenster können Sie beliebigen Text einfügen (Strg + V) oder einfach eingeben. Drücken Sie bei der Eingabe Strg + J für eine neue Zeile (dasselbe ASCII-Zeichen). Drücken Sie Strg + C, um den Prozessor zu unterbrechen und zur Py65-Eingabeaufforderung zurückzukehren.

Assembler-Code ist natürlich einfacher zu lesen.

       PC  AC XR YR SP NV-BDIZC
6502: 0000 00 00 00 ff 00110010
.d 00:0b
$0000  a9 21     LDA #$21
$0002  85 ff     STA $ff
$0004  a5 fe     LDA $fe
$0006  f0 fc     BEQ $0004
$0008  85 ff     STA $ff
$000a  d0 f4     BNE $0000

Der Übersichtlichkeit halber hier der Assembler-Code im CBA65- Format.

; ASSEMBLE:
; cba65 bangit
;
; LOAD/RUN
; python3 py65/monitor.py -i 00fe -o 00ff -l bangit.bin
; goto 0000

        .FILES  BIN=256

; I/O LOCATIONS
GETC    .EQU    $FE             ; (1) MOVING PY65'S GETC TO ZP SHAVES 1 BYTE
PUTC    .EQU    $FF             ; (1) MOVING PY65'S PUTC TO ZP SHAVES 2 BYTES

        .ORG    $0000

VROOM   LDA     #'!'
        STA     PUTC
VROOM2  LDA     GETC
        BEQ     VROOM2
        STA     PUTC
        BNE     VROOM

        .END

Apple II

Der obige Code geht davon aus, dass eine Null angibt, dass keine Eingabe vorliegt, und setzt die Abfrage fort, bis ein Wert ungleich Null zurückgegeben wird.

Zum Vergleich signalisieren Apple I und Apple II die Verfügbarkeit eines neuen Zeichens durch Setzen von Bit 7 der Tastatur-E / A-Adresse, das nach dem Abrufen des Zeichens gelöscht werden muss. Auf diesen Systemen wird die Zeichen-E / A normalerweise durch Aufrufen von Systemüberwachungsroutinen ausgeführt, anstatt direkt auf die Hardware zuzugreifen.

Durch Aufrufen von RDKEY ($ FD0C) und COUT ($ FDED) kann das Apple II-Äquivalent des oben genannten in 13 Bytes codiert werden und kann überall im RAM ausgeführt werden. Hier ist der Code, den ich in einem Apple // e-Emulator ausgeführt habe, a2ix auf Android 9.

Das Drücken der Eingabetaste hat den gleichen Effekt wie eine neue Zeile.

*300L

0300-   A9 A1       LDA   #$A1
0302-   20 ED FD    JSR   $FDED
0305-   20 0C FD    JSR   $FD0C
0308-   20 ED FD    JSR   $FDED
030B-   F0 F3       BEQ   $0300

Haben Sie bemerkt, dass anstelle des normalen ASCII-Werts # $ 21 für das Ausrufezeichen # $ A1 verwendet wird? Das liegt daran, dass beim Senden von Standard-ASCII-Werten an COUT diese im "inversen Modus" (schwarz auf weiß) angezeigt werden. Um ASCII in normalem Weiß auf Schwarz anzuzeigen, müssen Sie dem Zeichenwert im Akkumulator vor dem Aufruf von COUT # $ 80 hinzufügen. Da RDKEY Zeichen mit dem Hi-Bit-Satz zurückgibt, löschten Assembly-Programme im Allgemeinen das Bit des Zeichens, um seinen ASCII-Wert zu erhalten, bevor sie es verwendeten.

lee
quelle
1
Welcome to the site! :)
Rahul Bharadwaj
Thank you, @Rahul!
lee
4

Bash, 36 bytes

while read -n1 c;do printf \!$c;done

Try it online!

This counts on the newline terminating the input for the last ! mark.

spuck
quelle
Welcome! Please consider adding an explanation or link to an interpreter or something, because code-only answers are automatically flagged as low-quality.
mbomb007
@mbomb007, thanks for the pointer.
spuck
1
Unfortunately this does not add an ! at the end of the input.
Kritixi Lithos
@Cowsquack: on my terminal, the newline that terminates the input gets the ! added. On tio.run, the input needs to be terminated with a carriage return. I've updated the link to the Try it Online to reflect that.
spuck
4

MarioLANG, 95 94 90 89 69 bytes

++++++
======< >)
>+++++++",+[
=======<.==<
>+++++++!(.-
========#===

Try it online!

First time trying out MarioLANG, that was a lot of fun!

Thanks to Jo King for -20 bytes

Explanation:

So, as the name implies, MarioLANG is made to execute like a game of Super Mario Bros. It operates similarly to BF, with memory arranged in a tape of cells. There are operators to increment, decrement, print (as ascii or numeric) and read into the current memory cell, and operators to move left or right along the tape.

Mario (the instruction pointer) always begins in the top left cell of the program, with his intended direction of motion set to the right. If Mario does not have a floor-like object beneath him (=, ", or #), he will fall until he reaches a floor-like object. If Mario leaves the program space, the program ends due to Game Over :(

This specific program can basically be split into two halves: the setup, and the loop.

   Setup                          Loop
-----------------------------------------------
                       |
++++++                 |          
======<                |          >)
>+++++++               |          ",+[
=======<               |          .==<
>+++++++               |          !(.-
========               |          #===

In the Setup section, we're simply incrementing the first memory cell until we reach 33 - the ASCII value for "!". Easy enough; if this can be golfed, it's purely a matter of shape. Mario starts from the top left, picks up 10 coins, starts falling when picking up the 11th, switches directions, then repeats. He picks up the last 11 coins without switching directions; he ends the setup section at the bottom-rightmost "+".

In the loop section, Mario starts by reaching an elevator. The "!" operator makes him cease motion, so that he remains on the elevator. On the way up, it prints the corresponding ASCII character to the current memory cell's value (this one is always 33, "!"), then switches to the next cell in memory. Mario reaches the top and sets his direction to the right. He falls, and reads a character from input as its ASCII value (or -1 if no character). We increment because the only measure of control in MarioLANG is to skip an instruction if the current memory cell has a value of 0. If it does, we skip changing Mario's direction, so he will walk right off of the next floor to his doom. If it does not, we set direction to left; walking left off of the floor below decrements the current cell back to its previous value, that value is printed, and we move back to the first memory cell before getting back on the elevator.


Previous version (89 bytes):

+++++++++++>,
==========@"+
+++++++++++)[
@==========.==<
+++++++++++!(.-
===========#===
Reinstate Monica
quelle
62 bytes by using a multiplication loop instead of just a counter
Jo King
Okay now THAT is cool. I'll update as soon as I have time to redo the explanation, thanks a bunch!
Reinstate Monica
1
Aha! 60 bytes by multiplying 5*6 + 3 instead of 8*4+1
Jo King
Man, I know it isn't exactly your first rodeo, but this is really impressive. xD
Reinstate Monica
Actually, this is my first time golfing MarioLANG. I just have some experience with brainfuck as well as other 2D languages
Jo King
4

Perl 6, 16 11 bytes

{S:g/<(/!/}

Try it online!

Replaces all zero width matches with exclamation marks. Null regexes are not allowed, so we use a capture marker to capture nothing instead

Jo King
quelle
3

05AB1E, 4 bytes

€'!Ć

I/O as a list of characters.

Try it online.

Explanation:

'!  '# Prepend a "!"-item before each character in the (implicit) input-list
   Ć  # Enclose (append the first character of the list at the end of it)
      # (after which the result is output implicitly)
Kevin Cruijssen
quelle
3

Triangular, 15 13 bytes

B\3;#*~.,</@<

Try it online!

-2 bytes after remembering that Triangular has a conditional halt operator.

I believe this is as short as it gets on this one. Triangular does have conditional direction-change operators, but they unfortunately work differently than the other conditionals. While all others check if ToS <= 0, the direction-changing conditionals check ToS != 0. If this weren't the case, we would have 10 bytes in the form of Bq3~#*/@<<.

Ungolfed:

    B
   \ 3
  ; # *
 ~ . , <
/ @ <
----------------------------------------------------
B3*              - Push 11 and 3, then pop both and push their product.
    <,<          - Change directions 3 times (to save 2 bytes on last line)
        @/       - Print Top of Stack value as a character, do not pop
          ~;\    - Push a character from input to ToS. Halt if ToS <= 0. Change Direction.
              #  - Print ToS as a character and pop

Previous Version (15 bytes):

B.3\.*#).(/?~@<
Reinstate Monica
quelle
3

SimpleTemplate, 23 bytes

This is a language I wrote, and it was supposed to be for templates, but well.

!{@eachargv.0}{@echo_}!

Should be almost self-explanatory, once you see the ungolfed code:

!{@each argv.0 as char} {@echo char}!{@/}

And an explanation:

  • ! - Prints the literal ! character
  • {@each argv.0 as char} - Loops through every character, with the value set to the variable char (optional, the default variable is _).
    argv.0 is the first parameter passed to the render() method of the compiler.
  • {@echo char}! - outputs the char variable and a literal ! character.
    For the golfed version, the default variable _ is used instead.
  • {@/} - closes the loop (optional)

Pure SimpleTemplate solution:

{@fn x}!{@eachargv.0}{@echo_}!{@/}{@/}

Creates a function x that outputs the same result.

You can use it like this:

{@call x "this is an example"}

You can try all of this on: http://sandbox.onlinephpfunctions.com/code/f6baff8d411fc8227ece81eccf05b6e7d3586bfa

On the line 908, you can use the variables $golfed, $ungolfed and $fn to test all the versions.



However, if it is allowed to use a character array, the code is simplified (20 bytes):

!{@echoj"!" argv.0}!

And ungolfed:

!{@echo separator "!" argv.0}!

Basically, outputs all items in the array, joined by "!", surrounded by literal !.
Due to limitations in the compiler class, the space is mandatory (in the golfed version).

This code is also extremelly harder to use in pure SimpleTemplate (using the function as example):

{@fn x}!{@echoj"!" argv.0}!{@/}

{@// alternative: @call str_split into a "a char array"}
{@set a "a", " ", "c", "h", "a", "r", " ", "a", "r", "r", "a", "y"}

{@call x a}

The @call can call a function that exists in PHP, which means that it isn't a pure SimpleTemplate solution.

Ismael Miguel
quelle
3

Ruby, 17 16 bytes

->s{s.gsub'',?!}

Try it online!

Thanks Value Ink for -1 byte

G B
quelle
Remove the space after gsub.
Value Ink
2

Gema, 11 characters

\A=\!
?=?\!

Unfortunately ! starts a comment in Gema, so must be escaped.

Sample run:

bash-5.0$ echo -ne '1 2 3 4 5 6\n129591 129012 129127 129582\n\n0' | gema '\A=\!;?=?\!'
!1! !2! !3! !4! !5! !6!
!1!2!9!5!9!1! !1!2!9!0!1!2! !1!2!9!1!2!7! !1!2!9!5!8!2!
!
!0!

Try it online!

manatwork
quelle
2

Jelly, 5 bytes

Ż”!ṁż

A full program accepting a string, which prints the result.

Try it online!

How?

Ż”!ṁż - Main Link: list of characters, s   e.g. "abc"
 ”!   - character '!'                           '!'
   ṁ  - mould like:
Ż     -   s with a zero prepended              "!!!!"
    ż - zip together with s                    ["!a","!b","!c",'!']
      - implicit (smashing) print              !a!b!c!
Jonathan Allan
quelle
2

Japt, 4 bytes

rP'!

Try it

r      Replace
 P     all empty strings "" with
  '!   An exclamation mark (If '!' wasn't a special character in Japt I could remove the quote)
Embodiment of Ignorance
quelle
You'd only be able to ditch the ' if the replacement were a number.
Shaggy
2

Japt, 4 bytes

rP'!

Try it

Japt -P, 7 bytes

Unfortunately ! is a reserved character, necessitating the quotation marks.

ï'! i'!

Try it

Not much to explain: ï is Cartesian product and i prepends.

Shaggy
quelle