Write a piece of code that takes a string as input, and outputs a piece of code in the same language that, when run, will output the initial input string.
It must be able to handle any combination of characters A-Z, a-z, and 0-9.
Example in Python:
import sys
print "print('" + sys.argv[1] + "')"
Given the input of testing123
, it will return print('testing123')
.
Since this is code-golf, the shortest answer in bytes will win.
-
\$\begingroup\$ Can it be a function? \$\endgroup\$totallyhuman– totallyhuman2017年08月13日 19:34:06 +00:00Commented Aug 13, 2017 at 19:34
-
\$\begingroup\$ @manatwork (S)he edited it just now. \$\endgroup\$NoOneIsHere– NoOneIsHere2017年08月13日 19:42:35 +00:00Commented Aug 13, 2017 at 19:42
-
\$\begingroup\$ Must input be a string? Or can it be an integer? \$\endgroup\$Shaggy– Shaggy2017年08月13日 19:48:05 +00:00Commented Aug 13, 2017 at 19:48
-
\$\begingroup\$ Must be able to handle both integer and string inputs. \$\endgroup\$quartzic– quartzic2017年08月13日 20:00:21 +00:00Commented Aug 13, 2017 at 20:00
-
2\$\begingroup\$ Can we output a function as per the defauts on meta? \$\endgroup\$JAD– JAD2017年08月14日 18:26:59 +00:00Commented Aug 14, 2017 at 18:26
79 Answers 79
pl, 0 bytes
Code:
Explanation:
An empty program in pl is simply a cat program, outputting the exact same as the input.
In pl, all ASCII characters are essentially variables, but when the variable doesn't exist (yet), pl assumes that they are part of a string.
-
3\$\begingroup\$ I knew there was a language like this, couldn't find it though :( \$\endgroup\$Stephen– Stephen2017年08月13日 20:00:54 +00:00Commented Aug 13, 2017 at 20:00
-
2\$\begingroup\$ In the same vein, see Cat, which is an interpreted language like Python. Most modern Linux distros ship with a
cat
interpreter. ;) \$\endgroup\$Quuxplusone– Quuxplusone2017年08月13日 20:31:58 +00:00Commented Aug 13, 2017 at 20:31 -
1\$\begingroup\$ This solution also works for /// if you consider input to be appended to the program source code (since /// has no mechanism for input). /// is one of many languages (I think) where alphanumeric characters at the beginning of the program are simply output. \$\endgroup\$Sophie Swett– Sophie Swett2017年08月14日 07:22:46 +00:00Commented Aug 14, 2017 at 7:22
-
6\$\begingroup\$ Can you post the ungolfed version? ;) \$\endgroup\$maxathousand– maxathousand2017年08月15日 13:16:06 +00:00Commented Aug 15, 2017 at 13:16
brainfuck, (削除) 56 (削除ここまで) (削除) 55 (削除ここまで) 33 bytes
1 byte saved thanks to Gravitron, and 22 bytes saved thanks to Jo King!
--[>+<++++++],[[->.<]>+++.--.-<,]
Output requires an interpreter that wraps on memory underflow and has EOI=0. TIO has such an interpreter.
Explanation
--[>+<++++++]
initializes the tape with a single +
.
The input loop:
,[[->.<]>+++.--.-<,]
, take input
[ ,] while input is nonzero:
[->.<] output `+` input times
>+++. output `.` (`+` + 3)
--. output `,` (`.` - 2)
-< restore `+` and move back to input
Other solutions
Each line is its own solution.
+++[>+++++<-]>[>++++>+++<<-]>>-->,[[-<.>]<+++.---<.>>,]
--[>+<++++++],[[->.<]>+++.++++++++++++++++.-------------------<,]
++++++++++[>++++++>++++>++++<<<-]>>+++>++++++>,[[-<<.>>]<.<<.>>>,]
++++++++++[>++++++>++++>++++<<<-]>++>+++>++++++>,[[-<<.>>]<.<<.>>>,]
-
2\$\begingroup\$ +1. I don't know Brainfuck, but I can't imagine trying to solve a problem like this with it. \$\endgroup\$Jakob– Jakob2017年08月13日 21:14:07 +00:00Commented Aug 13, 2017 at 21:14
-
\$\begingroup\$ You can save 1 byte by replacing the
+++++++++++++++
with+++[>+++++<-]>
(From brainfuck constants) \$\endgroup\$Graviton– Graviton2017年08月13日 21:45:55 +00:00Commented Aug 13, 2017 at 21:45 -
\$\begingroup\$ @Graviton Oh, cool, thanks \$\endgroup\$Conor O'Brien– Conor O'Brien2017年08月13日 21:51:36 +00:00Commented Aug 13, 2017 at 21:51
-
\$\begingroup\$ you didn't replace it in the explanation \$\endgroup\$Destructible Lemon– Destructible Lemon2017年08月14日 05:24:37 +00:00Commented Aug 14, 2017 at 5:24
-
4\$\begingroup\$ You don't know Brainfuck? I'll teach you in one comment! We start on a tape of
0
's, with a pointer to a value.+
increments the value,-
decrements the value,>
moves the pointer right,<
moves the pointer left,,
reads input to the pointer as an ASCII character,.
outputs the value of the pointer as an ASCII character,[
starts a loop, and]
jumps to the corresponding[
if the value of the pointer is not0
. I'm bad at explaining, but that's how easy Brainfuck is. And Nice golf Conor! \$\endgroup\$Adalynn– Adalynn2017年08月14日 11:23:32 +00:00Commented Aug 14, 2017 at 11:23
Mornington Crescent, 27640 bytes
Take Northern Line to Moorgate
Take Circle Line to Moorgate
Take Circle Line to Westminster
Take Circle Line to Hammersmith
Take Circle Line to Aldgate
Take Circle Line to Bank
Take Circle Line to Barbican
Take Circle Line to Victoria
Take Circle Line to Victoria
Take Victoria Line to Seven Sisters
Take Victoria Line to Victoria
Take Circle Line to Victoria
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Bayswater
Take District Line to Barons Court
Take District Line to Gunnersbury
Take District Line to Hammersmith
Take District Line to Gunnersbury
Take District Line to Mile End
Take District Line to Cannon Street
Take Circle Line to Moorgate
Take Circle Line to Hammersmith
Take Circle Line to Cannon Street
Take Circle Line to Hammersmith
Take Circle Line to Cannon Street
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take District Line to Mile End
Take District Line to Barking
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Bank
Take Circle Line to Bank
Take Northern Line to Charing Cross
Take Northern Line to Charing Cross
Take Bakerloo Line to Paddington
Take Circle Line to Royal Oak
Take Circle Line to Tower Hill
Take District Line to Gunnersbury
Take District Line to Hammersmith
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Mile End
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Bank
Take Circle Line to Baker Street
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take District Line to Gunnersbury
Take District Line to Mile End
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Baker Street
Take Circle Line to Bank
Take Circle Line to Bank
Take District Line to Barking
Take District Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Liverpool Street
Take Circle Line to Bank
Take District Line to Barking
Take District Line to Bank
Take District Line to Gunnersbury
Take District Line to Upminster
Take District Line to East Ham
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Sloane Square
Take District Line to Gunnersbury
Take District Line to Hammersmith
Take Circle Line to Cannon Street
Take District Line to Gunnersbury
Take District Line to Mile End
Take District Line to East Ham
Take District Line to Mile End
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Plaistow
Take District Line to Mile End
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take District Line to Barking
Take District Line to Bank
Take District Line to Barking
Take District Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Wood Lane
Take Circle Line to Liverpool Street
Take Circle Line to Bank
Take Circle Line to Liverpool Street
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take District Line to Barking
Take District Line to Bank
Take District Line to Barking
Take District Line to Hammersmith
Take District Line to Gunnersbury
Take District Line to Dagenham East
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Mile End
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Mile End
Take District Line to Victoria
Take Circle Line to Bank
Take Circle Line to Victoria
Take Circle Line to Hammersmith
Take District Line to Mile End
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take District Line to Gunnersbury
Take District Line to Upminster
Take District Line to Mile End
Take Central Line to Bank
Take Circle Line to Victoria
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Mile End
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Wood Lane
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take District Line to Elm Park
Take District Line to Bank
Take Circle Line to Wood Lane
Take Circle Line to Bank
Take Circle Line to Bank
Take District Line to Barking
Take District Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take District Line to Barking
Take District Line to Bank
Take Circle Line to Hammersmith
Take District Line to Gunnersbury
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Bank
Take Central Line to Northolt
Take Central Line to Bank
Take Circle Line to Bank
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Mile End
Take District Line to Barons Court
Take District Line to Mile End
Take District Line to Paddington
Take Circle Line to Paddington
Take District Line to Upminster
Take District Line to Mile End
Take District Line to Wimbledon
Take District Line to Mile End
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Wood Lane
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Tower Hill
Take Circle Line to Bank
Take Circle Line to Wood Lane
Take Circle Line to Bank
Take Circle Line to Bank
Take District Line to Barking
Take District Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take District Line to Barking
Take District Line to Bank
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Bank
Take Circle Line to Hammersmith
Take District Line to Gunnersbury
Take District Line to Hammersmith
Take District Line to Mile End
Take District Line to Upminster
Take District Line to Bank
Take Circle Line to Baker Street
Take Circle Line to Bank
Take Circle Line to Bank
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take Bakerloo Line to Waterloo
Take Northern Line to Bank
Take Circle Line to Bank
Take Central Line to Mile End
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Wood Lane
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Blackfriars
Take Circle Line to Bank
Take Circle Line to Wood Lane
Take Circle Line to Bank
Take District Line to Barking
Take District Line to Paddington
Take Circle Line to Bank
Take Circle Line to Victoria
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Victoria
Take Circle Line to Wood Lane
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Wood Lane
Take Circle Line to Bank
Take Circle Line to Paddington
Take Circle Line to Victoria
Take Circle Line to Victoria
Take Victoria Line to Euston
Take Victoria Line to Victoria
Take Circle Line to Victoria
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Wood Lane
Take Circle Line to Paddington
Take Circle Line to Bank
Take Central Line to Northolt
Take Central Line to Bank
Take District Line to Southfields
Take District Line to Gunnersbury
Take District Line to Hammersmith
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Baker Street
Take Circle Line to Bank
Take Circle Line to Bank
Take District Line to Upminster
Take District Line to Ravenscourt Park
Take District Line to Gunnersbury
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Mile End
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Mile End
Take District Line to Paddington
Take Circle Line to Paddington
Take District Line to Upminster
Take District Line to Mile End
Take Central Line to Bank
Take Circle Line to Bank
Take Northern Line to Old Street
Take Northern Line to Bank
Take Circle Line to Bank
Take District Line to Gunnersbury
Take District Line to Mile End
Take District Line to Paddington
Take Circle Line to Paddington
Take District Line to Mile End
Take Central Line to Theydon Bois
Take Central Line to Mile End
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Mile End
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Bank
Take Northern Line to Old Street
Take Northern Line to Bank
Take Circle Line to Bank
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Mile End
Take District Line to Acton Town
Take Piccadilly Line to Cockfosters
Take Piccadilly Line to Acton Town
Take District Line to Acton Town
Take District Line to Mile End
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Wood Lane
Take Circle Line to Paddington
Take Circle Line to Wood Lane
Take Circle Line to Bank
Take District Line to Elm Park
Take District Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bayswater
Take Circle Line to Paddington
Take Circle Line to Bayswater
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Aldgate
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bayswater
Take Circle Line to Bank
Take Circle Line to Aldgate
Take Circle Line to Bank
Take Circle Line to Bank
Take District Line to Barking
Take District Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bayswater
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bayswater
Take District Line to Barking
Take District Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Barbican
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Barbican
Take Circle Line to Bank
Take Circle Line to Bank
Take District Line to East Ham
Take District Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take District Line to Elm Park
Take District Line to Bank
Take Central Line to Chancery Lane
Take Central Line to Bank
Take Circle Line to Bank
Take District Line to Gunnersbury
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Bank
Take District Line to Plaistow
Take District Line to Bank
Take Circle Line to Hammersmith
Take District Line to Mile End
Take Central Line to Bank
Take Circle Line to Bank
Take Circle Line to Farringdon
Take Circle Line to Bank
Take Circle Line to Bank
Take Central Line to Mile End
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Bank
Take Northern Line to Brent Cross
Take Northern Line to Bank
Take Circle Line to Bank
Take Central Line to Mile End
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take Circle Line to Notting Hill Gate
Take Circle Line to Notting Hill Gate
Take District Line to Upminster
Take District Line to Mile End
Take District Line to Paddington
Take Circle Line to Farringdon
Take Circle Line to Bank
Take Circle Line to Tower Hill
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Farringdon
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Farringdon
Take Circle Line to Bank
Take Circle Line to Bank
Take District Line to Southfields
Take District Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take District Line to Elm Park
Take District Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take District Line to Elm Park
Take District Line to Paddington
Take Circle Line to Blackfriars
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Royal Oak
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take District Line to Barons Court
Take District Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Blackfriars
Take Circle Line to Paddington
Take Circle Line to Blackfriars
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Royal Oak
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Farringdon
Take Circle Line to Paddington
Take Circle Line to Paddington
Take District Line to Southfields
Take District Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Embankment
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take District Line to East Ham
Take District Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Aldgate
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take District Line to East Ham
Take District Line to Bank
Take District Line to Barking
Take District Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Barbican
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take District Line to West Ham
Take District Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Aldgate
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take District Line to Barons Court
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Victoria
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Wood Lane
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Aldgate
Take Circle Line to Paddington
Take Circle Line to Aldgate
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take District Line to Barking
Take District Line to Paddington
Take Circle Line to Bank
Take District Line to Barking
Take District Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Bank
Take District Line to Barking
Take District Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Moorgate
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Aldgate
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take Central Line to Chancery Lane
Take Central Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take District Line to Barking
Take District Line to Paddington
Take Circle Line to Westminster
Take Circle Line to Paddington
Take District Line to Plaistow
Take District Line to Bank
Take Circle Line to Moorgate
Take Circle Line to Hammersmith
Take Circle Line to Bank
Take Northern Line to Charing Cross
Take Northern Line to Charing Cross
Take Northern Line to Bank
Take Circle Line to Bank
Take Circle Line to Paddington
Take Circle Line to Westminster
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Aldgate
Take Circle Line to Temple
Take Circle Line to Hammersmith
Take District Line to Mile End
Take Central Line to Bank
Take Circle Line to Aldgate
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take District Line to Gunnersbury
Take District Line to Bank
Take Circle Line to Westminster
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take District Line to Gunnersbury
Take District Line to Mile End
Take Central Line to Bank
Take Circle Line to Bank
Take Northern Line to Charing Cross
Take Northern Line to Charing Cross
Take Northern Line to Bank
Take Circle Line to Tower Hill
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take Circle Line to Notting Hill Gate
Take Circle Line to Notting Hill Gate
Take District Line to Upminster
Take District Line to Tower Hill
Take Circle Line to Bank
Take Circle Line to Temple
Take Circle Line to Bank
Take Circle Line to Bayswater
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Bayswater
Take Circle Line to Tower Hill
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take Circle Line to Notting Hill Gate
Take Circle Line to Notting Hill Gate
Take District Line to Upminster
Take District Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Embankment
Take Circle Line to Hammersmith
Take Circle Line to Tower Hill
Take Circle Line to Bank
Take Circle Line to Embankment
Take Northern Line to Angel
Take Northern Line to Bank
Take Central Line to Marble Arch
Take Central Line to Bank
Take Circle Line to Bank
Take Circle Line to Westminster
Take District Line to Upminster
Take District Line to Bank
Take Circle Line to Aldgate
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Bank
Take Circle Line to Aldgate
Take Circle Line to Hammersmith
Take District Line to Gunnersbury
Take District Line to Mile End
Take Central Line to Bank
Take Circle Line to Aldgate
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take District Line to Mile End
Take Central Line to Bank
Take Circle Line to Bank
Take Northern Line to Charing Cross
Take Northern Line to Charing Cross
Take Northern Line to Bank
Take Circle Line to Tower Hill
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take Circle Line to Notting Hill Gate
Take Circle Line to Notting Hill Gate
Take District Line to Upminster
Take District Line to Embankment
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Piccadilly Line to Bounds Green
Take Piccadilly Line to Hammersmith
Take Circle Line to Embankment
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Cannon Street
Take Circle Line to Hammersmith
Take Circle Line to Cannon Street
Take District Line to Acton Town
Take District Line to Acton Town
Take Piccadilly Line to Bounds Green
Take Piccadilly Line to Holborn
Take Central Line to Holborn
Take Central Line to Bank
Take Circle Line to Hammersmith
Take District Line to West Ham
Take District Line to Bank
Take Circle Line to Aldgate
Take Circle Line to Aldgate
Take Metropolitan Line to Chalfont & Latimer
Take Metropolitan Line to King's Cross St. Pancras
Take Victoria Line to Seven Sisters
Take Victoria Line to Euston
Take Victoria Line to Euston
Take Northern Line to Bank
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Bank
Take Circle Line to Tower Hill
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Stepney Green
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Stepney Green
Take Hammersmith & City Line to Moorgate
Take Circle Line to Moorgate
Take Metropolitan Line to Chalfont & Latimer
Take Metropolitan Line to Moorgate
Take Circle Line to Moorgate
Take Circle Line to Bank
Take Circle Line to Bank
Take District Line to Upminster
Take District Line to Bank
Take Circle Line to Tower Hill
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take Piccadilly Line to Russell Square
Take Piccadilly Line to Russell Square
Take Piccadilly Line to Acton Town
Take District Line to Acton Town
Take District Line to Bank
Take Circle Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Bank
Take District Line to East Ham
Take District Line to Bank
Take Circle Line to Hammersmith
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take District Line to East Ham
Take District Line to Tower Hill
Take Circle Line to Bank
Take District Line to West Ham
Take District Line to Bank
Take Circle Line to Bank
Take Northern Line to Angel
Take Northern Line to Bank
Take Circle Line to Moorgate
Take Circle Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Barbican
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Moorgate
Take Circle Line to Bank
Take Northern Line to Morden
Take Northern Line to Bank
Take Circle Line to Bank
Take District Line to Gunnersbury
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Victoria
Take Victoria Line to Seven Sisters
Take Victoria Line to Victoria
Take Circle Line to Victoria
Take District Line to Mile End
Take District Line to Embankment
Take Northern Line to Kennington
Take Northern Line to Bank
Take Circle Line to Bank
Take Central Line to Mile End
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Liverpool Street
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Aldgate
Take Metropolitan Line to Croxley
Take Metropolitan Line to Aldgate
Take Circle Line to Aldgate
Take Circle Line to Bank
Take Circle Line to Bank
Take District Line to Gunnersbury
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take District Line to Gunnersbury
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to West Brompton
Take District Line to Gunnersbury
Take District Line to Mile End
Take District Line to Acton Town
Take District Line to Mile End
Take District Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Victoria
Take Victoria Line to Seven Sisters
Take Victoria Line to Victoria
Take Circle Line to Victoria
Take District Line to Mile End
Take District Line to Acton Town
Take District Line to Acton Town
Take Piccadilly Line to Hounslow Central
Take Piccadilly Line to Acton Town
Take District Line to Acton Town
Take District Line to Mile End
Take District Line to Gunnersbury
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Gunnersbury
Take District Line to Paddington
Take Circle Line to Bank
Take Circle Line to Bank
Take Northern Line to Mornington Crescent
Explanation
First, a quick refresher on Mornington Crescent:
- each station can either hold a string of arbitrary length or a bigint
- there's also an accumulator which also holds a string or a bigint
- all stations start with their own name as their value
- at the beginning, the accumulator contains your program's input
- each time you go to a station, the station's value and the accumulator are swapped
- some stations are special and override this behavior
- the line you use to get to a station doesn't matter
- you start at Mornington Crescent
- to end the program, you go to Mornington Crescent too
- at the end, the value of the accumulator is printed
Since printing strings is hard (see Martin Ender's Mornington Crescent "Hello, World!" program), we will need a simple template that can be used to output generic strings. Since the length of the generated programs don't matter, I've settled on this:
Take Northern Line to Bank
Take Northern Line to Bank
Take District Line to Paddington
We'll need to generate each character separately and concatenate them, since the substring approach used by Martin is much harder to implement in the general case. Paddington is the station that performs string concatenation. When you arrive at Paddington, the following happens:
accumulator, paddington = paddington + accumulator, accumulator
This behavior is used to initialize Paddington to the empty string that's assumed to be the input.
Take District Line to Victoria
Take Victoria Line to Seven Sisters
Take Victoria Line to Euston
Take Victoria Line to Euston
Take Northern Line to Bank
Go to Seven Sisters, which sets the accumulator to 7, and store it in the Bank. The Bank is the only way to copy values - Hammersmith is a readonly copy of Bank's value.
Take District Line to Hammersmith
Take District Line to Cannon Street
Take District Line to Hammersmith
Take District Line to Cannon Street
Take District Line to Bank
Divide 7 by 7 to get 1, a divisor of all ASCII values we need to support.
Take District Line to Hammersmith
Take District Line to Upminster
For each character, start by copying the 1 to Upminster.
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Upminster
Add more ones as necessary.
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Bank
Take District Line to Bank
Take Northern Line to Charing Cross
Take Northern Line to Charing Cross
Take Bakerloo Line to Paddington
Take Bakerloo Line to Paddington
Take Bakerloo Line to Charing Cross
Take Northern Line to Embankment
Finish up by going to Upminster only once, to keep the new value in the accumulator instead of storing it again. Take it to Charing Cross to turn the ASCII value into a character and append it to the string. The last two lines are there because I've misread the specification, so I'll stop here and golf my program down first.
-
\$\begingroup\$ (disclaimer: I've just learnt this language) About the exact same approach I can think of (7/7=1). But why don't you just set Upminister only once at the beginning of the program? \$\endgroup\$user202729– user2027292018年04月07日 16:07:37 +00:00Commented Apr 7, 2018 at 16:07
-
\$\begingroup\$ @user202729 How would that work? / Fun fact: repeated
Take District Line to Upminster
lines calculate the fibonacci sequence \$\endgroup\$Maya– Maya2018年04月07日 16:27:09 +00:00Commented Apr 7, 2018 at 16:27 -
\$\begingroup\$ Looks like I misunderstood the spec. But that's exactly what it says there... someone need to edit the wiki. \$\endgroup\$user202729– user2027292018年04月07日 16:29:09 +00:00Commented Apr 7, 2018 at 16:29
Jelly, 1 byte
Ṿ
Woo builtins!
The builtin Ṿ
unevals the input.
A more interesting one:
)""j
Joins the string """" by the input.
-
1\$\begingroup\$ For the second one I think you can do
"";
for -1. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2017年08月13日 19:55:30 +00:00Commented Aug 13, 2017 at 19:55
Charcoal, 1 byte
θ
By default, a string of ASCII characters .. ~
simply prints itself, so it just remains to print the input.
-
\$\begingroup\$ I was going to add this same answer. :-) \$\endgroup\$Charlie– Charlie2017年08月13日 21:16:13 +00:00Commented Aug 13, 2017 at 21:16
-
\$\begingroup\$ @CarlosAlejo Well it's not as if there was a different answer... \$\endgroup\$Neil– Neil2017年08月13日 21:23:04 +00:00Commented Aug 13, 2017 at 21:23
-
2\$\begingroup\$ Well there is :P \$\endgroup\$ASCII-only– ASCII-only2017年08月14日 11:33:45 +00:00Commented Aug 14, 2017 at 11:33
-
\$\begingroup\$ @ASCII-only Touché! \$\endgroup\$Neil– Neil2017年08月14日 12:02:07 +00:00Commented Aug 14, 2017 at 12:02
C (gcc), (削除) 89 (削除ここまで) (削除) 87 (削除ここまで) (削除) 58 (削除ここまで) 56 bytes
Saved two bytes thanks to Jakob!
main(a,c)char**c;{printf("main(){puts(\"%s\");}",c[1]);}
-
\$\begingroup\$ "It must be able to handle any combination of characters A-Z, a-z, and 0-9." You might want to go with the escapes strategy after all. \$\endgroup\$Jakob– Jakob2017年08月13日 21:10:49 +00:00Commented Aug 13, 2017 at 21:10
-
\$\begingroup\$ @Jakob yeah I just read that :/, thanks \$\endgroup\$Conor O'Brien– Conor O'Brien2017年08月13日 21:11:10 +00:00Commented Aug 13, 2017 at 21:11
-
\$\begingroup\$ I had also just finished writing the escaper regex for a Java solution when I read that. Bummer. \$\endgroup\$Jakob– Jakob2017年08月13日 21:19:00 +00:00Commented Aug 13, 2017 at 21:19
-
\$\begingroup\$ @Jakob Yeah, same for me, but with eacal. RIP \$\endgroup\$Conor O'Brien– Conor O'Brien2017年08月13日 21:20:19 +00:00Commented Aug 13, 2017 at 21:20
-
\$\begingroup\$ You can use
puts
in the printed program to save 2 bytes, right? Or is it a problem that it appends a newline? \$\endgroup\$Jakob– Jakob2017年08月14日 17:33:37 +00:00Commented Aug 14, 2017 at 17:33
Japt, 2 bytes
iQ
i
is a function that inserts a specified string at a specified index into the input. Q
is a variable that defaults to a quotation mark "
, and since there's no index given, this defaults to 0
. The end result is a quotation mark inserted at the beginning of the string, which Japt auto-finishes when running.
This works on strings containing anything except "
, {
, or \
, though of course the string is guaranteed to consist of alphanumeric chars so this doesn't matter.
-
2\$\begingroup\$ An alternate 22 byte solution is
print'print'+`input()`
. \$\endgroup\$notjagan– notjagan2017年08月14日 02:43:47 +00:00Commented Aug 14, 2017 at 2:43 -
\$\begingroup\$ This wouldn't work.
input
in Python 2 is equivalent toeval(raw_input())
. So it has to be a pythonic expression for it to work. \$\endgroup\$Zizouz212– Zizouz2122017年08月14日 16:25:41 +00:00Commented Aug 14, 2017 at 16:25 -
\$\begingroup\$ Yes, that is allowed. ---Let me find the appropriate meta...--- Aha, found it. \$\endgroup\$totallyhuman– totallyhuman2017年08月14日 17:00:16 +00:00Commented Aug 14, 2017 at 17:00
-
5
MATLAB / Octave, 15 bytes
@(t)['disp ',t]
I completely overlooked the fact that the program only needs to handle alphanumeric characters, or, importantly, does not need to handle space characters. This means we can use the 'command' syntax, which uses significantly less bytes.
MATLAB, 27 bytes
For completeness, here's a version that can handle arbitrary input:
@(t)['disp(',mat2str(t),41]
Defines an anonymous function taking the string t
, and converts it to the program. Curiously, this does not work in Octave, which seems to have different ideas of what mat2str
should do.
-
\$\begingroup\$ I can't test this, but I think:
@(t)['disp ',mat2str(t)]
should work...? \$\endgroup\$Stewie Griffin– Stewie Griffin2018年04月07日 13:43:28 +00:00Commented Apr 7, 2018 at 13:43 -
\$\begingroup\$ @StewieGriffin That doesn't work because
mat2str
adds quotation marks, which are not necessary in command syntax. I had the function syntax combined withmat2str
to handle spaces in the input, but on rereading the challenge, that's not actually necessary, cutting the bytecount nearly in half. Thanks! \$\endgroup\$Sanchises– Sanchises2018年04月10日 13:22:57 +00:00Commented Apr 10, 2018 at 13:22 -
\$\begingroup\$ I thought quotation marks was necessary if there were spaces in the input but I might be wrong. I didn't notice that the input was only alphanumeric either... \$\endgroup\$Stewie Griffin– Stewie Griffin2018年04月10日 13:31:17 +00:00Commented Apr 10, 2018 at 13:31
-
\$\begingroup\$ Like this (ungolfed). \$\endgroup\$Stewie Griffin– Stewie Griffin2018年04月10日 13:35:02 +00:00Commented Apr 10, 2018 at 13:35
-
\$\begingroup\$ @StewieGriffin You are right, I misjudged the way command syntax works. However, command syntax seems to be full of suprises: Try it online! \$\endgroup\$Sanchises– Sanchises2018年04月10日 13:47:12 +00:00Commented Apr 10, 2018 at 13:47
PowerShell, 9 Bytes
"'$args'"
single or double quotes in powershell can be used to contain strings, but only double-quotes allow variable expansion.
with an input of foo
this will output 'foo'
which is a valid powershell program which outputs foo
Befunge-98 (FBBI), (削除) 21 (削除ここまで) (削除) 16 (削除ここまで) 12 bytes
-5 bytes thanks to NieDzejkob
-4 bytes thanks to Jo King
#,~'',,',,'@
Outputs 't,'e,'s,'t,@
for an input of test
How?
Initially the pointer moves East:
#, # skips the next instruction
~ push a byte of input
'', push ' and print it
, print the byte of input
',, push , and print it
'@ push @ to the stack
If there is no more input left, ~
reverses the direction of the pointer:
, print @
# skip nothing
@ terminate
Emojicode, 88 bytes
🐖😍➡️🔡🍇🍎🍪🔤🏁🍇😀❌🔤🔤🐕🔤❌🔤🍉🔤🍪🍉
Input:
anyString
Output:
🏁🍇😀🔤anyString🔤🍉
Script Output:
anyString
QBIC, 7 bytes
?@?@`+;
Explanation
? PRINT on the screen
@ ` a literal
?@ question mark and at
+; and append the input
Sample run
Command line: lala
?@lala
The output is a string literal containing the input, preceded with a PRINT
command.
Batch 11 bytes
I'm sure there's away to get it smaller, but this is pretty small.
set/p=echo
The breakdown:
set ::Define new variable
/p ::Create prompt
= ::Define a variable in prompt
echo ::Prompt begins with 'echo '
In English:
The user is asked for input with a leading phrase echo
. Then the user may type in whatever, and the program terminates (e.g; echo hello world!
). This leaves us with a program that when ran, will output hello world!
.
Yes, the whitespace is supposed to be there
-
\$\begingroup\$ I don't know batch (and this is from long ago), but this looks wrong. Wouldn't the
echo
portion be text echoed to the console and not program output? \$\endgroup\$Jakob– Jakob2018年06月19日 04:13:12 +00:00Commented Jun 19, 2018 at 4:13 -
\$\begingroup\$ @Jakob suprosingly no, it's essentially functionally equivalent to the python example given in the initial challenge. \$\endgroup\$Graviton– Graviton2018年06月19日 04:19:19 +00:00Commented Jun 19, 2018 at 4:19
-
\$\begingroup\$ Oops--what I meant is that I doubt the program outputs the text the user types. It's probably just echoed to the console, right? \$\endgroup\$Jakob– Jakob2018年06月19日 04:30:56 +00:00Commented Jun 19, 2018 at 4:30
-
\$\begingroup\$ @Jakob Right, which is equivalent to printing. The example prints a print function while mine echos an echo function. \$\endgroup\$Graviton– Graviton2018年06月19日 04:36:11 +00:00Commented Jun 19, 2018 at 4:36
-
\$\begingroup\$ OK, but the example prints the entire program to standard out. Your program prints only
echo
to standard out. In fact, (I assume) if input comes from a file or pipe, all you'd see is the prompt. Has that kind of output been allowed? \$\endgroup\$Jakob– Jakob2018年06月19日 04:45:29 +00:00Commented Jun 19, 2018 at 4:45
V, 2 bytes
ii
In Vim, i
changes to insert mode and allows inserting text. In this case, it just inserts the i
in front of the input text (to create the second program). V is Vim compatible, but adds an implicit <esc>
to the end of the program, so I don't need to worry about it here.
Cubically, 87 bytes
U3D1R3L1F3B1U1D3~:7+1(-1@3(-1%1)6:1+3111@6%1-31111+004@6:1+11111%6:1+45@6:1-1%6~:7+1)6
A port of my answer here. There already existed a challenge to take input and output Cubically code that produced that input, and I had an answer in Cubically so... profit?
-
\$\begingroup\$ Save a few bytes - remove the arguments from
%6
s and@6
s; they can now be called implicitly. (You can also do that on your answer on the cubifier thread.) \$\endgroup\$MD XF– MD XF2017年10月08日 21:51:05 +00:00Commented Oct 8, 2017 at 21:51
D, (削除) 92 (削除ここまで) 89 bytes
void main(){import std.stdio;write(`void main(){import std.stdio;"`~readln~`".write;}`);}
SmileBASIC, 21 bytes
Maybe this is cheating...
LINPUT"?"+CHR$(34);S$
Asks for input with the prompt ?"
. (? is short for PRINT, and closing quotes are not required). So the "output" program is ?"<text>
-
\$\begingroup\$ This fails for
1
\$\endgroup\$NoOneIsHere– NoOneIsHere2018年04月07日 18:36:12 +00:00Commented Apr 7, 2018 at 18:36 -
2\$\begingroup\$ @NoOneIsHere the challenge requires to take a string as input. If you pass
'1'
to the function it correctly outputsprint'1'
\$\endgroup\$ovs– ovs2018年04月07日 21:59:13 +00:00Commented Apr 7, 2018 at 21:59 -
\$\begingroup\$ Oh, I'm sorry. I didn't notice that. \$\endgroup\$NoOneIsHere– NoOneIsHere2018年04月09日 09:43:44 +00:00Commented Apr 9, 2018 at 9:43
SOGL V0.12, 2 bytes
$+
Try it Here! (expects input on stack so ,
is added for ease-of-use)
$
pushes "
, +
joins that after the input on the stack.
-
\$\begingroup\$ You can use `"` for
"
. \$\endgroup\$NoOneIsHere– NoOneIsHere2017年08月13日 19:49:04 +00:00Commented Aug 13, 2017 at 19:49 -
\$\begingroup\$ @NoOneIsHere yeah, that makes sense.. Used it everywhere else except where it's the most useful .-. \$\endgroup\$dzaima– dzaima2017年08月13日 19:50:28 +00:00Commented Aug 13, 2017 at 19:50
-
\$\begingroup\$ Can you remove the space? \$\endgroup\$NoOneIsHere– NoOneIsHere2017年08月13日 19:52:45 +00:00Commented Aug 13, 2017 at 19:52
-
\$\begingroup\$ @NoOneIsHere Removing either space would result in a two terms in a row error. Perl 6 has significant whitespace, but it is only significant in that it either has to be there, or has to not be there. (there are ways of opting out of both though) \$\endgroup\$Brad Gilbert b2gills– Brad Gilbert b2gills2017年08月13日 20:07:23 +00:00Commented Aug 13, 2017 at 20:07
8th, (削除) 34 (削除ここまで) 37 bytes
Code
: f >s "\"" tuck s:+ s:+ " ." s:+ . ;
Example
ok> "Print 42" f
"Print 42" .
ok> "Print 42" .
Print 42
PHP, 12 bytes
<?=$argv[1];
This is to be run from the command line with the input as the parameter argument. And yes, it simply outputs the input string—but that is valid PHP: anything outside the <?php
?>
delimiters is output unprocessed.
Here is the script produced by the 'testing123' input in action as a demonstration: Try it online!
-
1\$\begingroup\$ this won't work quite right if the input string contains
<?php
, mind you ;) \$\endgroup\$mystery– mystery2017年08月14日 20:06:45 +00:00Commented Aug 14, 2017 at 20:06 -
\$\begingroup\$ @Andrea Read the question: "It must be able to handle any combination of characters A-Z, a-z, and 0-9." So '<?php' is invalid input... \$\endgroup\$WebSmithery– WebSmithery2017年08月15日 06:22:02 +00:00Commented Aug 15, 2017 at 6:22
-
1\$\begingroup\$ aw, that's too easy :( \$\endgroup\$mystery– mystery2017年08月15日 21:33:53 +00:00Commented Aug 15, 2017 at 21:33
MATL, 2 bytes
&D
Simply wraps the string in quotes using &D
, which is MATL's equivalent to MATLAB's mat2str
, a function specifically made to make something that, when eval
'd, will give the original matrix (or in this case, string).
The resulting 'program' is just the input string wrapped in quotes, which is thus pushed on the stack, and implicitly displayed.
eacal, 38 bytes
strap string put string
put strap arg
Simply appends the string put string
to the memory string, then appends the argument, which is printed.
Batch, 14 bytes
@echo @echo(%*
Works for special characters too if they are quoted using "
s rather than ^
.
-
\$\begingroup\$ Perhaps
@echo.@echo.%*
would be more correct? The input could be potentially empty. \$\endgroup\$Conor O'Brien– Conor O'Brien2017年08月13日 21:14:31 +00:00Commented Aug 13, 2017 at 21:14 -
\$\begingroup\$ @ConorO'Brien Well I don't need the first
.
because that's never empty, and I used a(
for the second case because that's more reliable than.
, but thanks for the suggestions anyway! \$\endgroup\$Neil– Neil2017年08月13日 21:22:33 +00:00Commented Aug 13, 2017 at 21:22 -
\$\begingroup\$ np! I just like the symmetry between the
@echo.
s lol \$\endgroup\$Conor O'Brien– Conor O'Brien2017年08月13日 21:23:16 +00:00Commented Aug 13, 2017 at 21:23
Ly, 14 bytes
"\""&i"\"&o"&o
Explanation
"\""&i"\"&o"&o
"\"" # push `"`
&i # take input
"\"&o" # push `"&o`
&o # output stack
# test -> "test"&o
# "test"&o = push "test" and output stack
JavaScript ES6, 25 bytes (outputs code to "standard output")
s=>alert(`alert('${s}')`)
JavaScript ES6, 23 bytes (returns code, that outputs to "standard output")
s=>`alert('${s}')`
JavaScript ES6, 14 bytes (returns a function, that returns the result)
s=>`_=>"${s}"`
-
\$\begingroup\$ You're missing the quotation marks in your last solution, which should be your submitted solution as it's the shortest of the 3. \$\endgroup\$Shaggy– Shaggy2017年08月13日 20:58:05 +00:00Commented Aug 13, 2017 at 20:58
-
\$\begingroup\$ @Shaggy Right, let me add i \$\endgroup\$Bálint– Bálint2017年08月13日 20:59:32 +00:00Commented Aug 13, 2017 at 20:59
-
1\$\begingroup\$ You swapped string literals in your last function (and now it throws syntax error). Side note: it is not returning a function, it is returning a string which represents a function which returns the input. \$\endgroup\$user72349– user723492017年08月13日 21:31:45 +00:00Commented Aug 13, 2017 at 21:31
Brain-Flak, (削除) 92 (削除ここまで) 68 bytes
-22 bytes thanks to Wheat Wizard
Includes +2 for -cr
{<>(((((()()()()()){}){}){})())<>{({}[()])<>((({}[()])()))<>}{}}<>
# For every character
{
# Put ")(" on the off stack
<>(((((()()()()()){}){}){})())<>
# for 0 to the ASCII value of this character
{({}[()])
# Replace the ")" with "(" and add "))"
<>((({}[()])()))<>
# End for
}{}
# end for and switch to the off stack for printing (in reverse order because of -r)
}<>
Pyth, (削除) 2 (削除ここまで) 1 byte
z
Just outputs the input. Requires strings to be in quotes.
-1 byte thanks to KarlKastor
-
\$\begingroup\$ Can you just do
+\"
? (\x
char literal + implicitQ
) \$\endgroup\$ETHproductions– ETHproductions2017年08月13日 19:46:41 +00:00Commented Aug 13, 2017 at 19:46 -
\$\begingroup\$ @ETHproductions Even better,
+N
\$\endgroup\$NoOneIsHere– NoOneIsHere2017年08月13日 19:47:08 +00:00Commented Aug 13, 2017 at 19:47 -
\$\begingroup\$ Nice, I don't know Pyth quite that well :-) \$\endgroup\$ETHproductions– ETHproductions2017年08月13日 19:47:31 +00:00Commented Aug 13, 2017 at 19:47