New answers tagged

0

Burlesque, 10 bytes #QupIN#Qvv Try it online! Turns out the lazy way worse than doing it generally because I can't get a quote within a quote nicely. "IN_+"'"_+IN #Q #Push the code onto the stack up #Convert to string IN #Intersection #Q #Make sure a #Q is captured vv #Drop the resulting push


0

Burlesque, 27 bytes #Qup~-"#Q"j?+wd\[Ppm{pPjFi} Try it online! Returns list of indices with -1 for each not present. #Q #Push remaining code to stack up #Turn to string ~- #Remove brackets "#Q"j?+ #Add the "#Q" to the beginning wd\[ #Remove all spaces Pp #Push to virtual stack m{ #Map (apply to each char in input) pP #Pop ...


0

Python 2, 49 48 bytes -1 byte thanks to Jo King c='print map(("c=%r;ex"%c).find,input())';exec c Try it online! Python 3, 53 52 51 bytes -1 byte thanks to Jo King c='print(*map(("c=%r;ex"%c).find,input()))';exec(c) Try it online!


1

Python 2, 38 37 bytes -1 bytes thanks to Jo King s='print"s=%r;exec s"%(s+"#")';exec s Try it online! Python 3.8 (pre-release), 39 bytes exec(s:='print("exec(s:=%r)"%(s+"#"))') Try it online!


0

Gol><> and APL, 10 bytes and 13 bytes 'r3d*:::}H Try it online! Which outputs: '''r3d*:::}H' Try APL online! Which simple prints the code as a string (with the ' escaped with another ')


1

Jelly, 13 bytes “Ṿ;⁾v`+/ŒṘ”v` Try it online! RAD '“Ṿ;⁾v`+/ŒṘ”v`' Try it online! A Jelly quine that wraps itself in single quotes, such that the resultant RAD program simply prints the original Jelly program back out. If the old rule about new languages still applies to older challenges, this is non-competing.


2

Jelly, 13 bytes + 8 = score 21 “Ṿ;⁾v`+/ŒṘ”v` Try it online! RAD '“Ṿ;⁾v`+/ŒṘ”v`' Try it online! A Jelly quine that wraps itself in single quotes, such that the resultant RAD program simply prints the original Jelly program back out. Thanks to @JoKing for golfing the language name for the second program!


3

><> and Gol><>, 18 bytes + 3 + 6 = 27 '3d*:5-0@o~r{?H>o< Try it online! and "3d*:5-0@o~r{?H>o< Try it online! Both output the same program, but with the first character flipped between ' and ". Neither program is equivalent to itself in the other language, since the behaviour of @ differs.


1

GAS x64 for Linux (verified working on GCC 9.2.0): 13 12 instructions, 148 136 129 byte data section, 298 274 260 source Self-imposed rules/assumptions: No standard library (including printf) allowed. This contaminates the assembly. Faults are ok as long as it outputs the quine to stdout. No main allowed. Puts extra garbage in the program. No .incbin ...


0

Java 10, 128 bytes s->{var t="s->{var t=%c%s%1$c;t=t.format(t,34,t);return t.equals(s)?2020:0+s;}";t=t.format(t,34,t);return t.equals(s)?2020:0+s;} Try it online. Explanation: quine part of the explanation: var t contains the unformatted source code %s is used to input this String into itself with t.format(...) %c, %1$c, and the 34 are used to ...


2

05AB1E, 28 bytes "34çìD«QiŽ7ìëû"34çìD«QiŽ7ìëû Try it online or verify a few more test cases. Explanation: "34çìD«QiŽ7ìëû" # Push this string 34ç # Push 34, and convert it to a character: '"' ì # Prepend it in front of the string D« # Append a copy of the string to itself ...


2

C (gcc), 190 196 194 192 180 176 bytes Thanks to Jo King for pointing out a bug. Trailing newline seems accepted in some other answers, so will use that to fix a bug pointed out by NieDzejkob. (Also -12 bytes thanks to the same.) -4 bytes thanks to @ceilingcat. Assumes little-endian, ASCII, sizeof(int) >= 4, all the good stuff. Outputs the input ...


0

J, 56 bytes ".a=.}:0 :0 echo@>2020[^:(]-:'".a=.}:0 :0',LF,a&[)1!:1[3 Try it online! A full program. Unless provided with itself prints each character on a separate line.


47

awk, 4 bytes The structure of an awk program is pattern { action }. If pattern evaluates to true, { action } is performed. If { action } is omitted, the default is to output the current input record. Code: 2020 As 2020 always evaluates to true, the program always prints it's input, therefore satisfying properties 1. and 2. When the input is the program ...


6

Ruby -n, 45 bytes Based on one of the classic Ruby quines, _="_=%p;puts _%%_";puts _%_. Prints 2020 if the input is the source, otherwise prints the Ruby representation of the input (encapsulated in quotes, various characters like " and \ are escaped, etc.) _="_=%p;p$_==_%%_ ?2020:$_";p$_==_%_ ?2020:$_ Try it online!


2

Raku, 47 bytes <say "<$_>~~.EVAL"eq($!=get)??2020!!@$!>~~.EVAL Try it online! Outputs 2020 if the input matches the program, otherwise the input surrounded in brackets.


7

Python 3.8 (pre-release), 81 60 59 57 bytes -21 Thanks to Jo King Outputs 2020 if the input matches the program, otherwise the input concatenated to itself 5 time (eg. abc becomes abcabcabcabcabc) exec(a:='i=input();print(5*[i,404][i=="exec(a:=%r)"%a])') Try it online! Python 3.8 (pre-release), 77 67 65 bytes -10 Thanks to Jo King Outputs 2020 if the ...


2

Jelly, 16 bytes “Ṿ;⁾v`³⁽¥ŒṾ⁼?”v` Try it online! A full program that takes a string as its input. It outputs an unevaluated Jelly version of the input unless provided with itself, in which case it outputs 2020. Thanks to @JonathanAllan for pointing out a flaw in my original version! Explanation “Ṿ;⁾v`³⁽¥ŒṾ⁼?”v` | Evaluate as Jelly code the following, ...


11

JavaScript (ES6), 23 bytes Returns either the input string with a leading \$0\$, or \$2020\$ if the input is the program. f=s=>s=='f='+f?2020:0+s Try it online! JavaScript (Node.js), 76 bytes Generates a unique BigInt by using each byte of the input string, then applies a XOR to the result in such a way that \$f(f)=2020\$. f=s=>(g=s=>Buffer(s)....


0

tq, 8 bytes New high-level language! (Technically inspired by Jo King's Symbolic Raku quine.) etq'etq' Explanation 'etq' # Define the second item of the list # As a string q # Surround the string with quotes t # For the first item of the list, # Access the last (tail) item in the list, e # and evaluate the ...


0

Symbolic Raku, 36 bytes $_={$_~"<$_>)"}(<$_={$_~"<$_>)"}(>) Try it online! Explanation: $_= # Set the output to { }( ) # The result of the code block < > # With this string: $_={$_~"<$_>)"}( # The first ...


1

Keg, 32 28 23 22 21 bytes CKQNVNKKDG`(⑨,)`‘H%c¡ Try it online! This prints: CKQNVNKKDG(⑨,)HelloWorld Which prints: HELLOWORLD


Top 50 recent answers are included