26
\$\begingroup\$

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:

!!!!!
!!!!!
!!!!!
!!!!!
!!!!!
\$\endgroup\$
  • 6
    \$\begingroup\$ very similar question \$\endgroup\$ – Giuseppe Aug 18 '19 at 11:06
  • 7
    \$\begingroup\$ 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). \$\endgroup\$ – Jonathan Allan Aug 18 '19 at 13:45
  • 1
    \$\begingroup\$ if a language can't tell the difference between a\n and a, can we require that there are no trailing newlines? \$\endgroup\$ – Giuseppe Aug 18 '19 at 14:29
  • 13
    \$\begingroup\$ Downvotes are inserted between every upvote, just like what the challege describes. \$\endgroup\$ – a'_' Aug 18 '19 at 14:34
  • 2
    \$\begingroup\$ This is dead. \$\endgroup\$ – V. Courtois Aug 19 '19 at 7:30

66 Answers 66

1
\$\begingroup\$

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.
\$\endgroup\$
1
\$\begingroup\$

Elvish, 32 bytes

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

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

\$\endgroup\$
  • 2
    \$\begingroup\$ 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? \$\endgroup\$ – caird coinheringaahing Aug 22 '19 at 12:04
  • \$\begingroup\$ @cairdcoinheringaahing I added a link to the provided live environment. \$\endgroup\$ – kon Aug 22 '19 at 13:36
1
\$\begingroup\$

Ahead, 12 bytes

~irj!'~
@Wu<

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Lua, 31 bytes

print((io.read():gsub("","!")))
\$\endgroup\$
1
\$\begingroup\$

C (gcc), 32 bytes

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

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Red, 47 bytes

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

Try it online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.