Script that outputs a script that prints a given input

29

2

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.

Quartzic

Posted 2017-08-13T19:31:10.157

Reputation: 407

Can it be a function? – totallyhuman – 2017-08-13T19:34:06.143

@manatwork (S)he edited it just now. – NoOneIsHere – 2017-08-13T19:42:35.653

Must input be a string? Or can it be an integer? – Shaggy – 2017-08-13T19:48:05.150

Must be able to handle both integer and string inputs. – Quartzic – 2017-08-13T20:00:21.183

@Quartzic what if the language can't do integer inputs, but only inputs as strings? (aka, you would take, for example, "1" for an integer) – Stephen – 2017-08-13T20:01:23.437

You should edit that into the challenge, which only mentions strings. Note, though, that requiring solutions to be able to handle both types of input would invalidate at least one of the existing answers, probably more. – Shaggy – 2017-08-13T20:18:59.957

So only A-Z, a-z, and 0-9 can appear in the input? – Conor O'Brien – 2017-08-13T21:09:46.913

@ConorO'Brien Your code only has to handle A-Z, a-z, and 0-9 in the input to be deemed valid. What you do with invalid inputs is up to you. – Quartzic – 2017-08-13T21:24:09.317

Can we have arbitrary strings around the intended string? – ATaco – 2017-08-13T23:15:22.493

What about zero length input strings ? Is it considered as invalid input ? – HatsuPointerKun – 2017-08-14T07:07:00.450

Very similar to this, but more broad.

– MD XF – 2017-08-14T16:12:05.383

2Can we output a function as per the defauts on meta? – JAD – 2017-08-14T18:26:59.163

Answers

28

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.

Adnan

Posted 2017-08-13T19:31:10.157

Reputation: 41 965

3I knew there was a language like this, couldn't find it though :( – Stephen – 2017-08-13T20:00:54.553

2In the same vein, see Cat, which is an interpreted language like Python. Most modern Linux distros ship with a cat interpreter. ;) – Quuxplusone – 2017-08-13T20:31:58.313

1This 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. – Tanner Swett – 2017-08-14T07:22:46.277

6Can you post the ungolfed version? ;) – maxathousand – 2017-08-15T13:16:06.503

17

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.

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

Conor O'Brien

Posted 2017-08-13T19:31:10.157

Reputation: 36 228

1+1. I don't know Brainfuck, but I can't imagine trying to solve a problem like this with it. – Jakob – 2017-08-13T21:14:07.160

You can save 1 byte by replacing the +++++++++++++++ with +++[>+++++<-]> (From brainfuck constants)

– Graviton – 2017-08-13T21:45:55.740

@Graviton Oh, cool, thanks – Conor O'Brien – 2017-08-13T21:51:36.943

you didn't replace it in the explanation – Destructible Lemon – 2017-08-14T05:24:37.670

4You 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! – Zacharý – 2017-08-14T11:23:32.117

Can't you use , instead of .? Try it online!

– Jo King – 2018-04-10T04:30:44.487

@JoKing That's a smart idea, using EOF=0 to get a new cell value. Nice! – Conor O'Brien – 2018-04-10T11:20:19.193

13

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.

NieDzejkob

Posted 2017-08-13T19:31:10.157

Reputation: 4 630

(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? – user202729 – 2018-04-07T16:07:37.663

@user202729 How would that work? / Fun fact: repeated Take District Line to Upminster lines calculate the fibonacci sequence

– NieDzejkob – 2018-04-07T16:27:09.547

Looks like I misunderstood the spec. But that's exactly what it says there... someone need to edit the wiki.

– user202729 – 2018-04-07T16:29:09.557

7

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!

fireflame241

Posted 2017-08-13T19:31:10.157

Reputation: 7 021

1For the second one I think you can do ”“; for -1. – Erik the Outgolfer – 2017-08-13T19:55:30.957

7

Charcoal, 1 byte

θ

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

Neil

Posted 2017-08-13T19:31:10.157

Reputation: 95 035

I was going to add this same answer. :-) – Charlie – 2017-08-13T21:16:13.347

@CarlosAlejo Well it's not as if there was a different answer... – Neil – 2017-08-13T21:23:04.250

2

Well there is :P

– ASCII-only – 2017-08-14T11:33:45.633

@ASCII-only Touché! – Neil – 2017-08-14T12:02:07.003

6

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!

Conor O'Brien

Posted 2017-08-13T19:31:10.157

Reputation: 36 228

"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. – Jakob – 2017-08-13T21:10:49.480

@Jakob yeah I just read that :/, thanks – Conor O'Brien – 2017-08-13T21:11:10.287

I had also just finished writing the escaper regex for a Java solution when I read that. Bummer. – Jakob – 2017-08-13T21:19:00.830

@Jakob Yeah, same for me, but with eacal. RIP – Conor O'Brien – 2017-08-13T21:20:19.677

You can use puts in the printed program to save 2 bytes, right? Or is it a problem that it appends a newline? – Jakob – 2017-08-14T17:33:37.177

5

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.

ETHproductions

Posted 2017-08-13T19:31:10.157

Reputation: 47 880

4

Python 2, 22 bytes

print'print%r'%input()

Try it online!

totallyhuman

Posted 2017-08-13T19:31:10.157

Reputation: 15 378

2An alternate 22 byte solution is print'print'+\input()``. – notjagan – 2017-08-14T02:43:47.437

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. – Zizouz212 – 2017-08-14T16:25:41.367

Yes, that is allowed. ---Let me find the appropriate meta...--- Aha, found it.

– totallyhuman – 2017-08-14T17:00:16.957

421 bytes – LyricLy – 2017-08-14T21:12:55.903

4

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.

Sanchises

Posted 2017-08-13T19:31:10.157

Reputation: 8 530

I can't test this, but I think: @(t)['disp ',mat2str(t)] should work...? – Stewie Griffin – 2018-04-07T13:43:28.237

@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! – Sanchises – 2018-04-10T13:22:57.477

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... – Stewie Griffin – 2018-04-10T13:31:17.990

Like this (ungolfed). – Stewie Griffin – 2018-04-10T13:35:02.430

@StewieGriffin You are right, I misjudged the way command syntax works. However, command syntax seems to be full of suprises: Try it online!

– Sanchises – 2018-04-10T13:47:12.533

3

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

ovs

Posted 2017-08-13T19:31:10.157

Reputation: 21 408

3

Emojicode, 88 bytes

➡️❌❌

Try it online!

Input:

anyString

Output:

anyString

Script Output:

anyString

X1M4L

Posted 2017-08-13T19:31:10.157

Reputation: 1 586

2

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.

steenbergh

Posted 2017-08-13T19:31:10.157

Reputation: 7 772

2

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

Graviton

Posted 2017-08-13T19:31:10.157

Reputation: 2 295

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? – Jakob – 2018-06-19T04:13:12.447

@Jakob suprosingly no, it's essentially functionally equivalent to the python example given in the initial challenge. – Graviton – 2018-06-19T04:19:19.903

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? – Jakob – 2018-06-19T04:30:56.257

@Jakob Right, which is equivalent to printing. The example prints a print function while mine echos an echo function. – Graviton – 2018-06-19T04:36:11.067

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? – Jakob – 2018-06-19T04:45:29.153

2

D, 92 89 bytes

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

Try it online!

Zacharý

Posted 2017-08-13T19:31:10.157

Reputation: 5 710

2

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.

nmjcman101

Posted 2017-08-13T19:31:10.157

Reputation: 3 274

2

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

colsw

Posted 2017-08-13T19:31:10.157

Reputation: 3 195

2

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?

Kamil Drakari

Posted 2017-08-13T19:31:10.157

Reputation: 3 461

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.) – MD XF – 2017-10-08T21:51:05.440

2

Python 2, 17 bytes

'print%r'.__mod__

Try it online!

ovs

Posted 2017-08-13T19:31:10.157

Reputation: 21 408

This fails for 1 – NoOneIsHere – 2018-04-07T18:36:12.577

2@NoOneIsHere the challenge requires to take a string as input. If you pass '1' to the function it correctly outputs print'1' – ovs – 2018-04-07T21:59:13.757

Oh, I'm sorry. I didn't notice that. – NoOneIsHere – 2018-04-09T09:43:44.980

1

Pyth, 2 1 byte

z

Try it online!

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

-1 byte thanks to KarlKastor

NoOneIsHere

Posted 2017-08-13T19:31:10.157

Reputation: 1 916

Can you just do +\"? (\x char literal + implicit Q) – ETHproductions – 2017-08-13T19:46:41.737

@ETHproductions Even better, +N – NoOneIsHere – 2017-08-13T19:47:08.043

Nice, I don't know Pyth quite that well :-) – ETHproductions – 2017-08-13T19:47:31.257

1

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.

dzaima

Posted 2017-08-13T19:31:10.157

Reputation: 19 048

You can use `"` for ". – NoOneIsHere – 2017-08-13T19:49:04.647

@NoOneIsHere yeah, that makes sense.. Used it everywhere else except where it's the most useful .-. – dzaima – 2017-08-13T19:50:28.977

1

Perl 6, 19 bytes

say "say "~get.perl

Try it

This should work for any Unicode input in NFC

Brad Gilbert b2gills

Posted 2017-08-13T19:31:10.157

Reputation: 12 713

Can you remove the space? – NoOneIsHere – 2017-08-13T19:52:45.477

@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) – Brad Gilbert b2gills – 2017-08-13T20:07:23.583

1

8th, 34 37 bytes

Code

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

Example

ok> "Print 42" f
"Print 42" .
ok> "Print 42" .
Print 42

Chaos Manor

Posted 2017-08-13T19:31:10.157

Reputation: 521

1

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!

WebSmithery

Posted 2017-08-13T19:31:10.157

Reputation: 221

1this won't work quite right if the input string contains <?php, mind you ;) – Andrea – 2017-08-14T20:06:45.943

@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… – WebSmithery – 2017-08-15T06:22:02.830

1aw, that's too easy :( – Andrea – 2017-08-15T21:33:53.780

1

Haskell, 2 bytes

id

id returns it's argument unchanged.

id "abc" returns "abc" which evaluates to itself, which is a valid output method according to or standard rules. id is polymorphic and works for all kind of input types, so it also works for integer inputs.

The challenge requires to "output a piece of code". As @TannerSwett point out in a comment, the output of id is not valid Haskell source code, but a Haskell value or function that can be evaluated further, so it might also qualify as "code". If "code" means "source code" then we have a 4 byte answer

Haskell, 4 bytes (outputs source code)

show

nimi

Posted 2017-08-13T19:31:10.157

Reputation: 34 639

Doesn't id "abc" really evaluate to the string abc (which would normally be written with quotation marks to indicate that it's a string), rather than to the string literal "abc"? I would think that "interpreting the output of id "abc" as a Haskell expression" would mean interpreting abc, not "abc", as an expression. – Tanner Swett – 2017-08-14T07:34:19.853

@TannerSwett: hmm, hard to tell. The challenge requires to "output a piece of code". If "code" means "source code", the you're probably right. If "code" means something that can be evaluated then I think id is a valid answer. I'll edit this in my answer. – nimi – 2017-08-14T17:05:10.807

1

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.

Sanchises

Posted 2017-08-13T19:31:10.157

Reputation: 8 530

1

Java 8, 16 bytes

A rather strange challenge, especially given that the solution is only required to support alphanumeric strings.

s->"v->\""+s+'"'

This is a lambda from a string to the string representation of a lambda taking an empty argument of any type and returning the string.

Jakob

Posted 2017-08-13T19:31:10.157

Reputation: 2 428

Just to note - the solution doesn't have to only support alphanumeric strings, it's just that it's only required to support alphanumeric strings. – Quartzic – 2017-08-14T03:05:31.783

@Quartzic Right, that's what I meant. The wording in my post was ambiguous; I've corrected it. – Jakob – 2017-08-14T04:07:25.097

is it allowed to take an empty argument though? – ASCII-only – 2018-06-23T04:21:49.177

Yep, that's the consensus on the meta site. The interpretation we Java golfers have been using is that a single empty input may be added only if there are no other inputs and the empty input is unused.

– Jakob – 2018-06-23T05:03:09.710

1

Batch, 14 bytes

@echo @echo(%*

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

Neil

Posted 2017-08-13T19:31:10.157

Reputation: 95 035

Perhaps @echo.@echo.%* would be more correct? The input could be potentially empty. – Conor O'Brien – 2017-08-13T21:14:31.703

@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! – Neil – 2017-08-13T21:22:33.303

np! I just like the symmetry between the @echo.s lol – Conor O'Brien – 2017-08-13T21:23:16.290

1

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.

Conor O'Brien

Posted 2017-08-13T19:31:10.157

Reputation: 36 228

1

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

LyricLy

Posted 2017-08-13T19:31:10.157

Reputation: 3 313

1

05AB1E, 3 bytes

'"«

Try it online!


Surround input with quotes.

-1 @Adnan.

Magic Octopus Urn

Posted 2017-08-13T19:31:10.157

Reputation: 19 422

1

Bash, 10 bytes

Saved 2 bytes thanks to @manatwork!

echo{,} $1

Try it online!

musicman523

Posted 2017-08-13T19:31:10.157

Reputation: 4 472

1

R (+ pryr), 27 25 bytes

pryr::f(function()cat(x))

which evaluates to the function:

function (x) 
function() cat(x)

which returns the function:

function()cat(x)

where x is defined in the scope of the first function, and taken directly from its input.

JAD

Posted 2017-08-13T19:31:10.157

Reputation: 2 898

If I try this, I get: f=pryr::f(function()print(x)) f('test') function()print(x) <environment: 0x000000000aad19d8> I'm not sure I can actually then run that output code and get the string 'test'. Obviously this answer outputs a function that prints the string, I'm just not sure how literally to interpret the spec. – BLT – 2017-08-14T15:28:22.957

@BLT I am not sure what exactly your objection is. The returned function will print whatever was passed into x. – JAD – 2017-08-14T15:51:39.533

I guess it's more a question than an objection. The spec is "outputs a piece of code ... that, when run, will output the initial input string." Literally taken, that means I need to be able to run function()cat(x) and get the string, but that's not literally true - I'd have to save that function, and x would have to be saved somewhere ... does this mean that the spec isn't actually requiring "a piece of code that when run...`, and in fact is fine with returning a function that outputs the string? – BLT – 2017-08-14T17:23:49.853

I'm just getting hung up by the fact that if I run function()cat(x) then it won't actually return x - I have to actually invoke the function with x as input. Am I misunderstanding? Being overly literal? – BLT – 2017-08-14T17:26:51.690

@BLT I understand. I just assumed the standard definition of full program/function. I'll ask to clarify. – JAD – 2017-08-14T18:26:27.400

1

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.

TheLethalCoder

Posted 2017-08-13T19:31:10.157

Reputation: 6 930

Considering the spec only claims that you need to handle A-Z, a-z, and 0-9, isn't this competing? – jkelm – 2017-08-14T11:37:41.477

@jkelm I must have missed that part, then yes this is competing. – TheLethalCoder – 2017-08-14T11:38:39.540

Would this work for input 01? – a spaghetto – 2018-04-14T03:27:10.257

@quartata I believe so, it’s been a while since I’ve used Carrot though. – TheLethalCoder – 2018-04-14T08:38:47.963

1

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)
}<>

Riley

Posted 2017-08-13T19:31:10.157

Reputation: 11 345

1

QBasic, 25 23 bytes

INPUT s$
?"?";
WRITE s$

Gets input from the user, and then prints a question mark followed by the input wrapped in double quotes. (Question mark is a shortcut for PRINT.)

DLosc

Posted 2017-08-13T19:31:10.157

Reputation: 21 213

1

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>

12Me21

Posted 2017-08-13T19:31:10.157

Reputation: 6 110

1

><>, 29 bytes

/->:?v";"o;
/l^  >"o''"o{ooo1

Takes input using the -s flag Prints a program that reads and print the original input character by character.

input -> 'i'o'n'o'p'o'u'o't'o;

SE - stop firing the good guys

Posted 2017-08-13T19:31:10.157

Reputation: 529

1

Lua, 31 bytes

print('print([['..(...)..']])')

Try it online!

Alex Allen

Posted 2017-08-13T19:31:10.157

Reputation: 91

1

Julia 0.6, 8 bytes

s->()->s

Try it online!

Function that takes a string, and returns a closure that returns the string when called.

Alternately, a program outputting a program:

Julia 0.6, 28 26 bytes

print(:(show($(ARGS[1]))))

Try it online!

(Removed, of all things, a trailing whitespace. Smh. Also changed inner print to show.)

sundar - Reinstate Monica

Posted 2017-08-13T19:31:10.157

Reputation: 5 296

1

R, 41 37 characters

function(x)"[[<-"(sys.call(),1,"cat")

How it works:

sys.call (makes only sense if used from within a function) returns the call; the first element of it is the name of the function; this is replaced on-the-fly by cat (which will print its arguments).

A nicer version:

sqk <- function(x)"[[<-"(sys.call(),1,as.name("cat"))
# will print cat(args) instead of "cat"(args) - both are functional but the 2nd is nicer

Example with output:

> sqk("The paws")
cat("The paws")

lebatsnok

Posted 2017-08-13T19:31:10.157

Reputation: 383

0

Proton, 15 bytes

'print(%r)'&(%)

Try it online!

Binds 'print(%r)' to the left argument of % string formatting. When the input is given, it is applied as the second (right) argument which formats into the print statement.

HyperNeutrino

Posted 2017-08-13T19:31:10.157

Reputation: 26 575

0

Pyth, 3 bytes

+Nz

Try it online!

Explaination:

+Nz   expects any input
+     joins on same line
 N    quotation mark
  z   input as string

chromaticiT

Posted 2017-08-13T19:31:10.157

Reputation: 211

0

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}"`

Bálint

Posted 2017-08-13T19:31:10.157

Reputation: 1 847

You're missing the quotation marks in your last solution, which should be your submitted solution as it's the shortest of the 3. – Shaggy – 2017-08-13T20:58:05.987

@Shaggy Right, let me add i – Bálint – 2017-08-13T20:59:32.093

1You 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. – None – 2017-08-13T21:31:45.787

0

Lua, 30 bytes

print("print(\"".. ....."\")")

Try it online!

Leaky Nun

Posted 2017-08-13T19:31:10.157

Reputation: 45 011

you can replace the " with ' to allow you to change the "s to "s or you could change the " to 's to get 28 bytes – Alex Allen – 2018-06-20T01:33:16.580

0

Mathematica, 15 bytes

"\""<>#<>"\"&"&

Not much.

LegionMammal978

Posted 2017-08-13T19:31:10.157

Reputation: 15 731

0

Mathematica, 14 bytes

Defer@Print@#&

For input "test", this function will output Print["test"], which prints "test" when run.

JungHwan Min

Posted 2017-08-13T19:31:10.157

Reputation: 13 290

0

Rexx (Regina), 14 bytes

say say arg(1)

Try it online!

theblitz

Posted 2017-08-13T19:31:10.157

Reputation: 1 201

0

C++, 125 bytes

Warning : the code that will be printed will be invalid if input contains at least one of the character "

#include<iostream>
int main(int a,char**v){std::cout<<"#include<iostream>\nint main(){std::cout<<\""<<(a>1?v[1]:"")<<"\";}";}

C++, 116 bytes, undefined behavior if nothing is passed as console argument

If empty strings are considered as invalid input :

#include<iostream>
int main(int a,char**v){std::cout<<"#include<iostream>\nint main(){std::cout<<\""<<v[1]<<"\";}";}

HatsuPointerKun

Posted 2017-08-13T19:31:10.157

Reputation: 1 891

Technically, for an empty string as input you'd have to do ./program "", so the second program is equally valid. – NieDzejkob – 2018-04-08T08:54:31.583

0

Retina, 5 bytes

\`^
¶

Try it online!

For an input like testing123 returns the program:


testing123

which in turn produces the desired output.

Try it online!

There might be a trick to disable the newline append with shorter syntax, but I don't know it!

Dom Hastings

Posted 2017-08-13T19:31:10.157

Reputation: 16 415

0

C#, 16 bytes

s=>$"()=>\"{s}\""

TheLethalCoder

Posted 2017-08-13T19:31:10.157

Reputation: 6 930

0

Common Lisp, 13 bytes

`,(read-line)

Try it online!

For instance, given the input john, the output will be "john", which evaluates to itself.

For a program that works through printing and not through the REPL:

Common Lisp, 20 bytes

`(princ,(read-line))

that produces (princ input-string).

Renzo

Posted 2017-08-13T19:31:10.157

Reputation: 2 260

0

><>, 37 bytes

i:1+?!v
-1"#"~<.1fo;!?l"<.09o;!?l"r}:

Try it online!

Fairly simple;

Takes input, prints out a printing loop with the string attached to the end.

Teal pelican

Posted 2017-08-13T19:31:10.157

Reputation: 1 338

0

Swift, 47 bytes

print("print(\"\(CommandLine.arguments[1])\")")

I think this is pretty straight forward.

Caleb Kleveter

Posted 2017-08-13T19:31:10.157

Reputation: 647

0

CJam, 2 bytes

q`

Explanation:

q  e# Input
`  e# String representation

Esolanging Fruit

Posted 2017-08-13T19:31:10.157

Reputation: 13 542

0

Befunge-98 (PyFunge), 30 bytes

'":v
~\#[
<v">:#,_""#
<>4k,'@,

Try it online!

This prints a program in the form "...ihgfedcba">:#,_@, which prints abcdefghi...

Explanation

The code boils down to:

'":v    Push 2 quotation marks

~\#[    Get input and swap the top 2 items until EOF.
            Because every time we put a new value from input on the stack we also swap,
            the second quotation mark will float to the top, surrounding the input.

   >:#,_       A standard "print until the top is 0" loop
        ""#    Pushes a space, which is fine, since we control how much we print later
<v">:#,_"      When the IP gets reversed, we actually push the loop backwards onto
               the stack. This lets us print it later, instead of having to hardcode it.

 >4k,'@,       Prints 5 characters, being the printing loop from before, along with a @
<     @,       Prints an extra space, but it doesn't matter, and ends the program

MildlyMilquetoast

Posted 2017-08-13T19:31:10.157

Reputation: 2 907

0

J, 12 bytes

'echo',quote

Try it online!

FrownyFrog

Posted 2017-08-13T19:31:10.157

Reputation: 3 112

0

Ruby -n, 12 bytes

$><<"p'#$_'"

Try it online!

Asone Tuhid

Posted 2017-08-13T19:31:10.157

Reputation: 1 944

0

Aceto, 14 13 11 bytes

'"drsJJp'pp

Try it online!

'"       push a quote character
  d       duplicate
   r       get input
    s       swap top stack items, so the input is between the two quotes
     JJ      Join top two items, 2x
       p  p    print
        'p      push literal:p 

FantaC

Posted 2017-08-13T19:31:10.157

Reputation: 1 425

0

Javascript, 20 bytes

Uses eval to make a new function from the input string.

a=>eval(`a=>'${a}'`)

Nit

Posted 2017-08-13T19:31:10.157

Reputation: 2 667

0

Julia 0.6, 18 bytes

x->"print(\"$x\")"

Try it online!

gggg

Posted 2017-08-13T19:31:10.157

Reputation: 1 715

0

AWK, 25 bytes

$0="BEGIN{print\""$0"\"}"

Try it online!

Should work for most input other than ".

If some (possibly empty) input is allowed for the secondary program this could be shortened to:

$0="$0=\""$0"\""

Robert Benson

Posted 2017-08-13T19:31:10.157

Reputation: 1 339

0

dc, 10 bytes

91Pn93PACP

Try it online!

Straightforward: print an open bracket, then the input, then the close bracket and the letter p for the print command. 91Pn23920P also works.

brhfl

Posted 2017-08-13T19:31:10.157

Reputation: 1 291

0

WinDbg, 14 bytes

.echo.echo $u0

Input is taken by setting the fixed name alias $u0 (so that input can be either a string or number).

Running this will print:

.echo {value_of_$u0}

Which when executed prints the input.

Example:

$$ set input
r$.u0=testing123

$$ run code
.echo.echo $u0
$$output: .echo testing123

$$ run output
.echo testing123
$$output: testing123

How it works:

.echo            $$ print the rest of the statement
     .echo       $$ part of the string that gets printed
           $u0   $$ automatically expands to the value of the fixed name alias,
                 $$ the expanded alias is printed
                 $$ because only a-zA-Z0-9 needs to be handled, no special logic around the
                 $$ alias expansion with regard to spaces, ", or ; interfering with the
                 $$ next .echo needs to be done

How the output works:

.echo            $$ print the rest of the statement
      {string}   $$ the string that gets printed, guaranteed to be one statement because
                 $$ it can't contain ; or " and can't start with a space

milk

Posted 2017-08-13T19:31:10.157

Reputation: 3 043

0

T-SQL, 28 bytes

SELECT'PRINT'''+s+''''FROM t

An input table is allowed per our IO rules, so I simply create a PRINT statement with the appropriate quotation marks.

An input of FooBarBaz109481 in the input table t will result in the following output:

PRINT'FooBarBaz109481'

Which will output the original string.

The original question says the string will only contain alphanumerics, so we won't have to handle any quote marks in the input itself.

BradC

Posted 2017-08-13T19:31:10.157

Reputation: 6 099

0

JavaScript (Node.js), 49 bytes

console.log('console.log("'+process.argv[2]+'")')

Try it online!

Takes input through argv[2], the first argument in TIO (May be different depending on where it is tested), and prints in the console.log("YOUR_MESSAGE") format. Requires a string without quotes (unless escaped with \) with available characters A-Z, a-z, and 0-9.

Explanation

console.log(           // Log the output (open the outer log statement)
  'console.log("'      // Take console.log with opening parenthesis and quote
    + process.argv[2]  // Add the command-line argument after the quote (the input)
    + '")'             // Add the closing quote and parenthesis
)                      // Close the outer log statement

r2d2292

Posted 2017-08-13T19:31:10.157

Reputation: 63

0

R, 5 4 1 0 bytes

Thanks to JayCe for contributing the one-byte answer!

There are a number of short R programs that would ...

take a string as input, and output a piece of code in the same language that, when run, will output the initial input string

. Some of these are listed below, one on each row, in descending order of length:

identity     # 8 bytes
force        # 5 bytes
print
eval         # 4 bytes
c            # 1 byte
             # 0 bytes

This is inspired by NoOneIsHere's 1-byte answer in Pyth which is said to "just evaluate the input". This is exactly what force and identity do. eval and c achieve the same result in different ways. But why stop here? When you feed a string into R, it will be evaluated (to itself) and printed in quotes. A quoted string is a valid R program. That's the idea of the 0-byte answer.

Uniquely, the same program works identically in R and Python:

R way

> "yo ho ho and a bottle of rum"
[1] "yo ho ho and a bottle of rum"

Python way

>>> 'yo ho ho and a bottle of rum'
'yo ho ho and a bottle of rum'

lebatsnok

Posted 2017-08-13T19:31:10.157

Reputation: 383

Funny I had not seen your answers before posting mine. If way is valid there is a function way shorter than eval that does the job... it’s actually just one byte... c – JayCe – 2018-06-19T02:50:42.987

Or zero bytes using REPL? – lebatsnok – 2018-06-19T07:24:45.253

2The question is really what “output” means... If it means “printing” then this answer is not valid. – JayCe – 2018-06-19T12:49:06.287

0

R, 34 bytes

cat("cat(",scan(,""),")",sep="\"")

Try it online!

Non-functional answer - longer than the functional one

JayCe

Posted 2017-08-13T19:31:10.157

Reputation: 2 655

0

Excel VBA, 10 bytes

An anonymous function that outputs an anonymous function that prints the value of cell A1.

?"?"""[A1]

Example I/O

Given that cell [A1] that is populated with One

?"?"""[A1]
?"One
One

Taylor Scott

Posted 2017-08-13T19:31:10.157

Reputation: 6 709

0

Yabasic, 22 bytes

An anonymous function that takes input, S$ as a string and outputs a function that outputs S$ to the console.

This relies on the fact that the Input Call will print a ? character to the console as a prompt when no explicit prompt is provided

Input S$
?"\""+S$+"\""

Try it online!

Taylor Scott

Posted 2017-08-13T19:31:10.157

Reputation: 6 709

0

Lua, 29 bytes

print('print("'.. ... ..'")')

Try it online!

Alex Allen

Posted 2017-08-13T19:31:10.157

Reputation: 91

wat O_o what even is .. ... .. – ASCII-only – 2018-06-23T04:20:55.370

.. = [Concatenate] ... = Argument .. = [Concatenate again] – Alex Allen – 2018-06-24T12:09:24.303

0

Scala, 79 bytes

println(s"""object x{def main(a:Array[String])=println("${args.mkString}")}""")

Try it online!

Shankar Shastri

Posted 2017-08-13T19:31:10.157

Reputation: 111

you shouldn't use that as argument since it doesn't work – ASCII-only – 2018-06-23T04:17:50.737

@ASCII-only I didn't get it, can you help me explain a more bit? – Shankar Shastri – 2018-06-23T04:18:38.830

>

  • "asdf",10 doesn't work, 2. you don't have to support that. so just change it to letters and numbers only
  • < – ASCII-only – 2018-06-23T04:20:07.797

    @ASCII-only Thanks :-) – Shankar Shastri – 2018-06-23T04:21:35.560

    oh. also you have to return a valid submission, i.e. a function or program (also your submission also has to be valid. so you'd need your header and footer inside your post body as well here – ASCII-only – 2018-06-23T04:24:14.570

    @ASCII-only, So you meant I should print the whole program? – Shankar Shastri – 2018-06-23T04:28:46.777

    Let us continue this discussion in chat.

    – ASCII-only – 2018-06-23T04:35:00.090

    -1

    JavaScript Firefox, 6 bytes

    uneval
    

    l4m2

    Posted 2017-08-13T19:31:10.157

    Reputation: 5 985