# !I!n!s!e!r!t! !i!n!b!e!t!w!e!e!n!

Posted from here.

This challenge is highly "distilled" from this question. Special thanks to @Akababa!

In this task, you should insert an exclamation mark at the start of the string and after every character.

## Rules

• There will always be a non-empty-string input. The input will not contain tabs either. You can assume that the input only contain non-extended ASCII printable characters and newlines.
• The input will not contain trailing newlines as long as your language can't detect a newline.
• This is a contest; the shortest answer should win.

## Examples

• 4 newlines result in 5 newline-delimited exclamation marks. It is very hard to put this as a Markdown text, so this is stated instead.
1 2 3 4 5 6
129591 129012 129127 129582

0


Outputs

!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


Outputs

!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!


A base test case with only one character:

a


Outputs

!a!


(Auto-completion! Just kidding, there is no such thing.) Contains exclamation marks:

!!
!!
!!
!!
!!


Outputs:

!!!!!
!!!!!
!!!!!
!!!!!
!!!!!

• very similar question Aug 18, 2019 at 11:06
• I really don't understand the downvote - this is a clear and well written challenge. Re: being a duplicate - it's not (preceding '!' makes for a big difference), and I don't believe anyone has suggested so (no close votes). Aug 18, 2019 at 13:45
• if a language can't tell the difference between a\n and a, can we require that there are no trailing newlines? Aug 18, 2019 at 14:29
• Downvotes are inserted between every upvote, just like what the challege describes.
– user85052
Aug 18, 2019 at 14:34
• Is the case of a single space input " ", is the output supposed to be "!" or "! !"
– Kai
Aug 19, 2019 at 3:52

# SNOBOL4 (CSNOBOL4), 94 bytes

I	I =INPUT	:F(END)
S	I LEN(1) . X REM . I	:F(O)
O ='!' O X	:(S)
O	OUTPUT =O '!'
O =	:(I)
END


Try it online!

Prints with an additional trailing newline (as SNOBOL always prints a line break). The way input is consumed, there is no way of distinguishing between a final line ending in \n or not.

# Stax, 6 5 bytes

_z'!R


Run and debug it

Replace "" with "!" using regex replacement. I don't exactly understand why this works.

Edit: Found it in the Ecma spec: 15.5.4.10

If there is a match with an emptystring (in other words, if the value of regexp.lastIndex is left unchanged), increment regexp.lastIndex by 1.

Old Stuff:

I would have been able to get to 5 bytes in either of two scenarios.

1. If input was provided in an escaped literal e.g. "line1\nline2". But I opted against that for the sake of "usability".
2. If there was not a bug feature in stax's zip implementation when encountering empty strings/arrays.

# C (gcc), 48 45 bytes

f(char*s){putchar(33);*s&&f(s+write(1,s,1));}


Try it online!

-3 thanks to ceilingcat

# Wolfram Language (Mathematica), 4948 42 bytes

#~StringSplit~""~StringRiffle~{a="!",a,a}&


Try it online!

-6 bytes thanks to @attinat

• The code in the Header, Code, and Footer sections is run. You can use infix notation and drop the { } in StringSplit for 42 bytes
– att
Aug 19, 2019 at 23:24
• @attinat Thanks that helps a lot!
– Kai
Aug 20, 2019 at 19:50

# Brachylog, 10 bytes

"!"w.∋w?w⊥


Try it online!

Takes input through the output variable, and unifies the input variable with "!", printing the output.

"!"w          Print "!", which is the input variable.
.∋w       Print an element of the output variable.
?w     Print the input variable again.
⊥    Fail.


# Elvish, 32 bytes

use re;re:replace "" "!" (slurp)

Copy and paste into the Live Environment to try it out!

• Welcome to the site! Would it be possible to edit in a link to an online interpreter, such as Try it online! so that other users can verify your program? Aug 22, 2019 at 12:04
– kon
Aug 22, 2019 at 13:36

~irj!'~
@Wu<


Try it online!

# Lua, 31 bytes

print((io.read():gsub("","!")))


# C (gcc), 32 bytes

f(s){printf("!%s",s)-1&&f(s+4);}


Try it online!

# Red, 47 bytes

func[s][parse s[insert"!"any[skip insert"!"]]s]


Try it online!

# C#, 142 bytes

public class P{public static void Main(string[]a){System.Console.Write("!");foreach(char c in a[0]){System.Console.Write(c.ToString()+"!");}}}


# Branch, 11 bytes

33.,[.33.,]


Try it on the online Branch interpreter!

Put 33 on the tree and output (!). Then, grab input. Finally, while that value is not EOF, output it, output 33 (!), and grab input again.

# Vim, 13 bytes

:%s/\_./!&/g



Works by putting a ! before every character, including newline characters. The TIO version doesn't work properly for the 4 newline testcase, but it does work in Vim.

Try it online!

# BRASCA, 14 13 bytes

-1 byte thanks to RezNesX

,![$'!oo{]'!o  Try it online! ## Explanation , - Reverse stack ![$    {]      - Loop stack length:
'!oo        -     Print "!" followed by the next letter
'!o   - Print the last "!"

• 13 bytes: ,![$'!oo{]'!o May 12, 2021 at 11:20 # Husk, 10 8 bytes -2 bytes thanks to Razetime! :'!ṁe'!  Try it online! # Pip, 5 bytes aJW'!  Try it online! The JW builtin was made for challenges like this. # x86-16 machine code, 8 bytes 00000000: b021 aaa4 aae2 fcc3 .!......  Listing: B0 21 MOV AL, '!' ; character to insert AA STOSB ; write first ! to output string CLOOP: A4 MOVSB ; copy input char to output string AA STOSB ; write ! to output string E2 FC LOOP CLOOP ; loop until end of input C3 RET ; return to caller  Callable function, input at SI, length in CX. Output to string at DI. Test runs: # Zsh, 12 bytes <<<${1///!}!


Try it online!

# Julia, 21 20 19 bytes

x->'!'join(x,!)*'!'


Try it online!

# Subleq (8-bit), 1211 bytes

-1 byte for removing last 0

2 -1 33
-1 8 -1
8 -1 0
8 8


Subleq emulator

## Explanation

0:  2 -1 33 ' Output 2: (char(33)); 3rd argument is not used for output so use it for memory
3: -1  8 -1 ' Read input to 8:, exit if null
6:  8 -1  0 ' Output 8:
9:  8  8    ' 8: = 0 goto 0
`