29
\$\begingroup\$

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 , the shortest answer in bytes will win.

\$\endgroup\$
  • \$\begingroup\$ Can it be a function? \$\endgroup\$ – totallyhuman Aug 13 '17 at 19:34
  • \$\begingroup\$ @manatwork (S)he edited it just now. \$\endgroup\$ – NoOneIsHere Aug 13 '17 at 19:42
  • \$\begingroup\$ Must input be a string? Or can it be an integer? \$\endgroup\$ – Shaggy Aug 13 '17 at 19:48
  • \$\begingroup\$ Must be able to handle both integer and string inputs. \$\endgroup\$ – Quartzic Aug 13 '17 at 20:00
  • 2
    \$\begingroup\$ Can we output a function as per the defauts on meta? \$\endgroup\$ – JAD Aug 14 '17 at 18:26

72 Answers 72

28
\$\begingroup\$

pl, 0 bytes

Code:

Try it online!

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.

\$\endgroup\$
  • 3
    \$\begingroup\$ I knew there was a language like this, couldn't find it though :( \$\endgroup\$ – Stephen Aug 13 '17 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 Aug 13 '17 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\$ – Tanner Swett Aug 14 '17 at 7:22
  • 6
    \$\begingroup\$ Can you post the ungolfed version? ;) \$\endgroup\$ – maxathousand Aug 15 '17 at 13:16
17
\$\begingroup\$

brainfuck, 56 55 33 bytes

1 byte saved thanks to Gravitron, and 22 bytes saved thanks to Jo King!

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

Try it online!

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.

+++[>+++++<-]>[>++++>+++<<-]>>-->,[[-<.>]<+++.---<.>>,]
--[>+<++++++],[[->.<]>+++.++++++++++++++++.-------------------<,]
++++++++++[>++++++>++++>++++<<<-]>>+++>++++++>,[[-<<.>>]<.<<.>>>,]
++++++++++[>++++++>++++>++++<<<-]>++>+++>++++++>,[[-<<.>>]<.<<.>>>,]
\$\endgroup\$
  • 1
    \$\begingroup\$ +1. I don't know Brainfuck, but I can't imagine trying to solve a problem like this with it. \$\endgroup\$ – Jakob Aug 13 '17 at 21:14
  • \$\begingroup\$ You can save 1 byte by replacing the +++++++++++++++ with +++[>+++++<-]> (From brainfuck constants) \$\endgroup\$ – Graviton Aug 13 '17 at 21:45
  • \$\begingroup\$ @Graviton Oh, cool, thanks \$\endgroup\$ – Conor O'Brien Aug 13 '17 at 21:51
  • \$\begingroup\$ you didn't replace it in the explanation \$\endgroup\$ – Destructible Lemon Aug 14 '17 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 not 0. I'm bad at explaining, but that's how easy Brainfuck is. And Nice golf Conor! \$\endgroup\$ – Zacharý Aug 14 '17 at 11:23
13
+250
\$\begingroup\$

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

Try it online!

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.

\$\endgroup\$
  • \$\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 Apr 7 '18 at 16:07
  • \$\begingroup\$ @user202729 How would that work? / Fun fact: repeated Take District Line to Upminster lines calculate the fibonacci sequence \$\endgroup\$ – NieDzejkob Apr 7 '18 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 Apr 7 '18 at 16:29
7
\$\begingroup\$

Jelly, 1 byte

Woo builtins!

The builtin unevals the input.

Try it online!

A more interesting one:

⁾“”j

Joins the string "“”" by the input.

Try it online!

\$\endgroup\$
  • 1
    \$\begingroup\$ For the second one I think you can do ”“; for -1. \$\endgroup\$ – Erik the Outgolfer Aug 13 '17 at 19:55
7
\$\begingroup\$

Charcoal, 1 byte

θ

By default, a string of ASCII characters .. ~ simply prints itself, so it just remains to print the input.

\$\endgroup\$
  • \$\begingroup\$ I was going to add this same answer. :-) \$\endgroup\$ – Charlie Aug 13 '17 at 21:16
  • \$\begingroup\$ @CarlosAlejo Well it's not as if there was a different answer... \$\endgroup\$ – Neil Aug 13 '17 at 21:23
  • 2
    \$\begingroup\$ Well there is :P \$\endgroup\$ – ASCII-only Aug 14 '17 at 11:33
  • \$\begingroup\$ @ASCII-only Touché! \$\endgroup\$ – Neil Aug 14 '17 at 12:02
6
\$\begingroup\$

C (gcc), 89 87 58 56 bytes

Saved two bytes thanks to Jakob!

main(a,c)char**c;{printf("main(){puts(\"%s\");}",c[1]);}

Try it online!

\$\endgroup\$
  • \$\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 Aug 13 '17 at 21:10
  • \$\begingroup\$ @Jakob yeah I just read that :/, thanks \$\endgroup\$ – Conor O'Brien Aug 13 '17 at 21:11
  • \$\begingroup\$ I had also just finished writing the escaper regex for a Java solution when I read that. Bummer. \$\endgroup\$ – Jakob Aug 13 '17 at 21:19
  • \$\begingroup\$ @Jakob Yeah, same for me, but with eacal. RIP \$\endgroup\$ – Conor O'Brien Aug 13 '17 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 Aug 14 '17 at 17:33
5
\$\begingroup\$

Japt, 2 bytes

iQ

Try it online!

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.

\$\endgroup\$
4
\$\begingroup\$

Python 2, 22 bytes

print'print%r'%input()

Try it online!

\$\endgroup\$
  • 2
    \$\begingroup\$ An alternate 22 byte solution is print'print'+`input()`. \$\endgroup\$ – notjagan Aug 14 '17 at 2:43
  • \$\begingroup\$ This wouldn't work. input in Python 2 is equivalent to eval(raw_input()). So it has to be a pythonic expression for it to work. \$\endgroup\$ – Zizouz212 Aug 14 '17 at 16:25
  • \$\begingroup\$ Yes, that is allowed. ---Let me find the appropriate meta...--- Aha, found it. \$\endgroup\$ – totallyhuman Aug 14 '17 at 17:00
  • 4
    \$\begingroup\$ 21 bytes \$\endgroup\$ – LyricLy Aug 14 '17 at 21:12
4
\$\begingroup\$

MATLAB / Octave, 15 bytes

@(t)['disp ',t]

Try it online!

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.

\$\endgroup\$
  • \$\begingroup\$ I can't test this, but I think: @(t)['disp ',mat2str(t)] should work...? \$\endgroup\$ – Stewie Griffin Apr 7 '18 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 with mat2str 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 Apr 10 '18 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 Apr 10 '18 at 13:31
  • \$\begingroup\$ Like this (ungolfed). \$\endgroup\$ – Stewie Griffin Apr 10 '18 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 Apr 10 '18 at 13:47
3
\$\begingroup\$

Befunge-98 (FBBI), 21 16 12 bytes

-5 bytes thanks to NieDzejkob
-4 bytes thanks to Jo King

#,~'',,',,'@

Try it online!

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

Emojicode, 88 bytes

🐖😍➡️🔡🍇🍎🍪🔤🏁🍇😀❌🔤🔤🐕🔤❌🔤🍉🔤🍪🍉

Try it online!

Input:

anyString

Output:

🏁🍇😀🔤anyString🔤🍉

Script Output:

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

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.

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

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

\$\endgroup\$
  • \$\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 Jun 19 '18 at 4:13
  • \$\begingroup\$ @Jakob suprosingly no, it's essentially functionally equivalent to the python example given in the initial challenge. \$\endgroup\$ – Graviton Jun 19 '18 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 Jun 19 '18 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 Jun 19 '18 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 Jun 19 '18 at 4:45
2
\$\begingroup\$

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.

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

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

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

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 

Try it online!

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?

\$\endgroup\$
  • \$\begingroup\$ Save a few bytes - remove the arguments from %6s and @6s; they can now be called implicitly. (You can also do that on your answer on the cubifier thread.) \$\endgroup\$ – MD XF Oct 8 '17 at 21:51
2
\$\begingroup\$

D, 92 89 bytes

void main(){import std.stdio;write(`void main(){import std.stdio;"`~readln~`".write;}`);}

Try it online!

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

Python 2, 17 bytes

'print%r'.__mod__

Try it online!

\$\endgroup\$
  • \$\begingroup\$ This fails for 1 \$\endgroup\$ – NoOneIsHere Apr 7 '18 at 18:36
  • 2
    \$\begingroup\$ @NoOneIsHere the challenge requires to take a string as input. If you pass '1' to the function it correctly outputs print'1' \$\endgroup\$ – ovs Apr 7 '18 at 21:59
  • \$\begingroup\$ Oh, I'm sorry. I didn't notice that. \$\endgroup\$ – NoOneIsHere Apr 9 '18 at 9:43
1
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ You can use `"` for ". \$\endgroup\$ – NoOneIsHere Aug 13 '17 at 19:49
  • \$\begingroup\$ @NoOneIsHere yeah, that makes sense.. Used it everywhere else except where it's the most useful .-. \$\endgroup\$ – dzaima Aug 13 '17 at 19:50
1
\$\begingroup\$

Perl 6, 19 bytes

say "say "~get.perl

Try it

This should work for any Unicode input in NFC

\$\endgroup\$
  • \$\begingroup\$ Can you remove the space? \$\endgroup\$ – NoOneIsHere Aug 13 '17 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 Aug 13 '17 at 20:07
1
\$\begingroup\$

8th, 34 37 bytes

Code

: f >s "\"" tuck s:+ s:+ " ." s:+ . ;

Example

ok> "Print 42" f
"Print 42" .
ok> "Print 42" .
Print 42
\$\endgroup\$
1
\$\begingroup\$

PHP, 12 bytes

<?=$argv[1];

Try it online!

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!

\$\endgroup\$
  • 1
    \$\begingroup\$ this won't work quite right if the input string contains <?php, mind you ;) \$\endgroup\$ – Andrea Aug 14 '17 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 Aug 15 '17 at 6:22
  • 1
    \$\begingroup\$ aw, that's too easy :( \$\endgroup\$ – Andrea Aug 15 '17 at 21:33
1
\$\begingroup\$

MATL, 2 bytes

&D

Try it online!

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.

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

eacal, 38 bytes

strap string put string 
put strap arg

Try it online!

Simply appends the string put string to the memory string, then appends the argument, which is printed.

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

Batch, 14 bytes

@echo @echo(%*

Works for special characters too if they are quoted using "s rather than ^.

\$\endgroup\$
  • \$\begingroup\$ Perhaps @echo.@echo.%* would be more correct? The input could be potentially empty. \$\endgroup\$ – Conor O'Brien Aug 13 '17 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 Aug 13 '17 at 21:22
  • \$\begingroup\$ np! I just like the symmetry between the @echo.s lol \$\endgroup\$ – Conor O'Brien Aug 13 '17 at 21:23
1
\$\begingroup\$

Ly, 14 bytes

"\""&i"\"&o"&o

Try it online!

Explanation

"\""&i"\"&o"&o

"\""           # push `"`
    &i         # take input
      "\"&o"   # push `"&o`
            &o # output stack
               # test -> "test"&o
               # "test"&o = push "test" and output stack
\$\endgroup\$
1
\$\begingroup\$

05AB1E, 3 bytes

'"«

Try it online!


Surround input with quotes.

-1 @Adnan.

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

Brain-Flak, 92 68 bytes

-22 bytes thanks to Wheat Wizard

Includes +2 for -cr

{<>(((((()()()()()){}){}){})())<>{({}[()])<>((({}[()])()))<>}{}}<>

Try it online!

# 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)
}<>
\$\endgroup\$
1
\$\begingroup\$

Pyth, 2 1 byte

z

Try it online!

Just outputs the input. Requires strings to be in quotes.

-1 byte thanks to KarlKastor

\$\endgroup\$
  • \$\begingroup\$ Can you just do +\"? (\x char literal + implicit Q) \$\endgroup\$ – ETHproductions Aug 13 '17 at 19:46
  • \$\begingroup\$ @ETHproductions Even better, +N \$\endgroup\$ – NoOneIsHere Aug 13 '17 at 19:47
  • \$\begingroup\$ Nice, I don't know Pyth quite that well :-) \$\endgroup\$ – ETHproductions Aug 13 '17 at 19:47
1
\$\begingroup\$

Carrot, 1 byte

#

How it works

# //Takes the input and places it onto the string stack
  //This is then output implicitly

{input} //The next program then consists of the input string
        //This is then placed directly onto the string stack
        //Then output implicitly

An alternative, also at 1 byte is:

$

This works the same as the above but only takes the first line of input. Seeing as input will only ever be [A-Za-z0-9] this is fine.

\$\endgroup\$
  • \$\begingroup\$ Considering the spec only claims that you need to handle A-Z, a-z, and 0-9, isn't this competing? \$\endgroup\$ – jkelm Aug 14 '17 at 11:37
  • \$\begingroup\$ @jkelm I must have missed that part, then yes this is competing. \$\endgroup\$ – TheLethalCoder Aug 14 '17 at 11:38
  • \$\begingroup\$ Would this work for input 01? \$\endgroup\$ – quartata Apr 14 '18 at 3:27
  • \$\begingroup\$ @quartata I believe so, it’s been a while since I’ve used Carrot though. \$\endgroup\$ – TheLethalCoder Apr 14 '18 at 8:38

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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