-6
\$\begingroup\$

Challenge

Your challenge is to make a simple program that takes the [input] and formats it as "Hello, [input]!"

Input

Either a function call variable or STDIN, this is the name. Can contain any character, UTF-8, and can be empty - would result in Hello,!. Also newlines in the input are fine -

On a new
line 
->
Hello, On a new
line!

Why? Because the challenge is not about if the message makes sense or not, it's about 'how quickly can you format?'.

Output

Hello, !

Example

Here would be a program in CJam:

"Hello, %s!"qae%

lolad -> Hello, lolad!

John Smith -> Hello, John Smith!

this is a
new line -> 
Hello, this is a
new line!

<null> -> Hello, !

Winner

The winner is the answer with the shortest bytes, as always.

\$\endgroup\$
  • \$\begingroup\$ This appears to mainly be outputting the input, with some extra text added, which is already a challenge. Therefore I have voted to close this question as a duplicate. \$\endgroup\$ – caird coinheringaahing Mar 27 '18 at 15:29
  • \$\begingroup\$ Despite their similarities this challenge differs in a non-trivial way from Simple cat program: Simple cat program restricts submissions to full programs while this challenge does not. \$\endgroup\$ – 0 ' Mar 27 '18 at 17:00

16 Answers 16

2
\$\begingroup\$

Retina, 13 bytes

'!>`^
Hello, 

Try it online!

Explanation

^
Hello, 

This part prepends the Hello, (and a space) to the input. Then > lets us configure the implicit output of the program and with '! we can append the exclamation mark to the output (basically a generalisation of printing with a trailing linefeed).

\$\endgroup\$
2
\$\begingroup\$

pl, 9 bytes

Hello, _!

Try it online!

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

Java 8, 18 bytes

s->"Hello, "+s+"!"

Try it online.

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

05AB1E, 8 7 bytes

”Ÿ™, ÿ!

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Perl 5, 19 bytes

say"Hello, ",<>,"!"

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Elixir, 23 bytes

fn a->"Hello, #{a}!"end

Try it online!

Elixir, 32 bytes

IO.puts"Hello, #{IO.read :all}!"

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Add++, 21 bytes

x:"Hello, "
+?
+"!"
O

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Japt, 12 bytes

Couldn't think of a simpler solution.

"Hello, {N}!

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Compressing the string will save you 2 bytes. \$\endgroup\$ – Shaggy Mar 25 '18 at 19:55
0
\$\begingroup\$

AWK, 21 bytes

{print"Hello, "$0"!"}

Try it online!

\$\endgroup\$
0
\$\begingroup\$

sed, 15 bytes

s/.*/Hello, &!/

Try it online!

\$\endgroup\$
0
\$\begingroup\$

ReRegex, 17 bytes

Trivial and probably as short as it can get.

Hello, (?#input)!

Try it online!

\$\endgroup\$
0
\$\begingroup\$

JavaScript, 17 bytes

s=>`Hello, ${s}!`
\$\endgroup\$
0
\$\begingroup\$

4, 111 bytes

3.6009960199602996207252062002020200052062009020200152052062012020200252062044520620325207218215217219620335204

Try it online!

Nothing too special going on here. This is just a glorified cat program.

\$\endgroup\$
0
\$\begingroup\$

Ruby, 33 bytes

A lambda, accepting a string and returning a string:

->s{"Hello,#{s.size>0?' '+s:s}!"}

Try it online!

Ruby + -p, 16 bytes (not fully compliant)

A full program, which does not support empty inputs (prints nothing) or inputs containing newlines (treats each line as a separate input):

$_="Hello, #$_!"

Try it online!

The fun trick here: when string interpolation is done on a variable name starting with $, the curly braces can be dropped from the normal #{} wrapper.

\$\endgroup\$
0
\$\begingroup\$

Haskell, 21 bytes

("Hello, "++).(++"!")

Try it online!

\$\endgroup\$
0
\$\begingroup\$

V / vim, 11 bytes

iHello, <esc>A!

<esc> is a literal escape character

Try it online! (V)

\$\endgroup\$

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