Skript, das ein Skript ausgibt, das eine bestimmte Eingabe druckt


29

Schreiben Sie einen Code, der eine Zeichenfolge als Eingabe verwendet, und geben Sie einen Code in derselben Sprache aus , in der beim Ausführen die ursprüngliche Eingabezeichenfolge ausgegeben wird.

Es muss in der Lage sein, eine beliebige Kombination der Zeichen AZ, az und 0-9 zu verarbeiten.

Beispiel in Python:

import sys
print "print('" + sys.argv[1]  + "')"

Bei Eingabe von testing123wird es zurückgegeben print('testing123').

Da es sich um , wird die kürzeste Antwort in Bytes gewinnen.


Kann es eine Funktion sein?
Totalhuman

@manatwork (S) hat er gerade bearbeitet.
NoOneIsHere

Muss die Eingabe eine Zeichenfolge sein? Oder kann es eine ganze Zahl sein?
Shaggy

Muss sowohl Integer- als auch String-Eingaben verarbeiten können.
Quarz

2
Können wir eine Funktion gemäß den Defauten auf Meta ausgeben?
JAD

Antworten:


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 sind alle ASCII-Zeichen im Wesentlichen Variablen. Wenn die Variable jedoch (noch) nicht vorhanden ist, geht pl davon aus, dass sie Teil einer Zeichenfolge sind.


3
I knew there was a language like this, couldn't find it though :(
Stephen

2
In the same vein, see Cat, which is an interpreted language like Python. Most modern Linux distros ship with a cat interpreter. ;)
Quuxplusone

1
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.
Tanner Swett

6
Can you post the ungolfed version? ;)
maxathousand

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.

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

1
+1. I don't know Brainfuck, but I can't imagine trying to solve a problem like this with it.
Jakob

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

@Graviton Oh, cool, thanks
Conor O'Brien

you didn't replace it in the explanation
Destructible Lemon

4
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!
Zacharý

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.


(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


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


7

Charcoal, 1 byte

θ

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


I was going to add this same answer. :-)
Charlie

@CarlosAlejo Well it's not as if there was a different answer...
Neil

2
Well there is :P
ASCII-only

@ASCII-only Touché!
Neil

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!


"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

@Jakob yeah I just read that :/, thanks
Conor O'Brien

I had also just finished writing the escaper regex for a Java solution when I read that. Bummer.
Jakob

@Jakob Yeah, same for me, but with eacal. RIP
Conor O'Brien

You can use puts in the printed program to save 2 bytes, right? Or is it a problem that it appends a newline?
Jakob

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.



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.


I can't test this, but I think: @(t)['disp ',mat2str(t)] should work...?
Stewie Griffin

@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

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

Like this (ungolfed).
Stewie Griffin

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

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

3

Emojicode, 88 bytes

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

Try it online!

Input:

anyString

Output:

🏁🍇😀🔤anyString🔤🍉

Script Output:

anyString

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.


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


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

@Jakob suprosingly no, it's essentially functionally equivalent to the python example given in the initial challenge.
Graviton

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

@Jakob Right, which is equivalent to printing. The example prints a print function while mine echos an echo function.
Graviton

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

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.


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


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?


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



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.


You can use `"` for ".
NoOneIsHere

@NoOneIsHere yeah, that makes sense.. Used it everywhere else except where it's the most useful .-.
dzaima

1

Perl 6, 19 bytes

say "say "~get.perl

Try it

This should work for any Unicode input in NFC


Can you remove the space?
NoOneIsHere

@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

1

8th, 34 37 bytes

Code

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

Example

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

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!


1
this won't work quite right if the input string contains <?php, mind you ;)
Andrea

@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

1
aw, that's too easy :(
Andrea

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.


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.


1

Batch, 14 bytes

@echo @echo(%*

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


Perhaps @echo.@echo.%* would be more correct? The input could be potentially empty.
Conor O'Brien

@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

np! I just like the symmetry between the @echo.s lol
Conor O'Brien

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


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


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.


Considering the spec only claims that you need to handle A-Z, a-z, and 0-9, isn't this competing?
jkelm

@jkelm I must have missed that part, then yes this is competing.
TheLethalCoder

Would this work for input 01?
a spaghetto

@quartata I believe so, it’s been a while since I’ve used Carrot though.
TheLethalCoder
Durch die Nutzung unserer Website bestätigen Sie, dass Sie unsere Cookie-Richtlinie und Datenschutzrichtlinie gelesen und verstanden haben.
Licensed under cc by-sa 3.0 with attribution required.