| Bytes | Lang | Time | Link |
|---|---|---|---|
| 028 | Vyxal D | 241017T000447Z | emanresu |
| 143 | Ruby | 211120T122917Z | lonelyel |
| 034 | Gol><> | 210729T155359Z | Jo King |
| 748 | Scala 3 languagepostfixOps | 210728T175332Z | user |
| 044 | Vyxal D | 210727T213735Z | a stone |
| 123 | Python 2 | 210726T223118Z | Jakque |
| 052 | Gol><> | 210727T083512Z | Bubbler |
| 303 | Haskell | 210727T072755Z | Wheat Wi |
Vyxal D, 28 bytes
`Id$ß14`Id$ß14`Id$ß14`Id$ß14
Try it Online! Both parts are identical:
`Id$ß14`Id$ß14
`Id$ß14` # String "Id$ß14"
I # Quote and append, creating this part's source code
d # Double, creating the full source
$ß # If the previous item on the stack is truthy (the first copy has pushed the source)
14 # Push 14 (cut point)
An eval-based approach comes out to the same length (both parts identical):
`q‛:Ė+d$[14`:Ė`q‛:Ė+d$[14`:Ė
` `:Ė # Evaluate the following string on itself:
q # Quote
‛:Ė+ # And append ":Ė", resulting in this part's source
d # Double, creating the full source
$[ # If the previous item on the stack is nonempty, i.e. source code pushed
14 # Push 14
It's possible there's a way to save 4 bytes on the first version (2 on the second) by using how 14 is the length of the halved part, but it seems unlikely.
Ruby, 143 bytes
$a=%q[a="$a=%q[#$a];eval$a";$><<a+"b='puts 63;exit';"+a];eval$ab='puts 63;exit';$a=%q[a="$a=%q[#$a];eval$a";$><<a+"b='puts 63;exit';"+a];eval$a
Outputs «63» and exits. First 63 bytes
$a=%q[a="$a=%q[#$a];eval$a";$><<a+"b='puts 63;exit';"+a];eval$a
and the rest
b='puts 63;exit';$a=%q[a="$a=%q[#$a];eval$a";$><<a+"b='puts 63;exit';"+a];eval$a
output the whole quine. I feel like when golfing it inevitably converged towards the existing python solution in the answers. Other approaches seem to all be bigger.
Gol><>, 34 bytes
'r2sslK5+:l)?H1sh"r2sslK5+:l)?H1sh
This is composed of two identical sections of code, except one uses ' and the other uses ". The combined program outputs 17 (which is only one byte away from being able to use a single instruction to push the number), which splits them into practically identical programs.
Try the first half online! And the second half!
Explanation:
'r2ss Push the code on the first line and add a " to the start
lK Push a copy of the stack
5+ Add 5 to the top " making it a '
:l)? If the length of the stack is less than 39
H Halt and output the stack contents
1sh Otherwise print 17
Scala 3 -language:postfixOps, 940 748 bytes
This is a chonky lizard.
@main def m:Unit=
val s="""@main def m:Unit=
val s=Q%sQ;var x=0;class main extends annotation.Annotation{def dval=print(420);def d=printf(s.replace(""+81.toChar,"\""*3),s,s)}
return
new main()dval
x=0
@main def n={val s=Q%sQ;printf(s.replace(""+81.toChar,"\""*3),s,s)}""";var x=0;class main extends annotation.Annotation{def dval=print(420);def d=printf(s.replace(""+81.toChar,"\""*3),s,s)}
return
new main()dval
x=0
@main def n={val s="""@main def m:Unit=
val s=Q%sQ;var x=0;class main extends annotation.Annotation{def dval=print(420);def d=printf(s.replace(""+81.toChar,"\""*3),s,s)}
return
new main()dval
x=0
@main def n={val s=Q%sQ;printf(s.replace(""+81.toChar,"\""*3),s,s)}""";printf(s.replace(""+81.toChar,"\""*3),s,s)}
x is 420.
Try the last (n-x) bytes online!
I'm sure I've done something silly here and can make it smaller, but it's really hard editing quines and seeing what's wrong, so I'll try golfing it more later.
First x bytes, prettified (... contains the entire program):
@main def m: Unit =
val s = """..."""
var x = 0
class main extends annotation.Annotation {
def dval = print(420)
def d = printf(s.replace("" + 81.toChar, "\"" * 3), s, s)
}
return new main().d
Last (n-x) bytes, prettified (... contains the entire program):
val x = 0
@main def n = {
val s = """..."""
printf(s.replace("" + 81.toChar, "\"" * 3), s, s)
}
Vyxal D, 44 bytes
`:qpd4NẎ[20|`:qpd4NẎ[20|`:qpd4NẎ[20|`:qpd4NẎ
Try it Online! Outputs 20.
Left Side:
`:qpd4NẎ[20|`:qpd4NẎ
Right Side:
[20|`:qpd4NẎ[20|`:qpd4NẎ
`...`:qpd4NẎ[20|`...`:qpd4NẎ
`...`:qp `...`:qp Standard Vyxal quine (of the first 24 bytes)
d d Double ^
4NẎ 4NẎ Remove the last 4 characters of ^ to make it a quine
[20| If the top of stack is true, push 20, otherwise the second quine.
The D flag allows the character Ẏ to be used in string literals
Python 2, 123 bytes
u="x='\\nu=%r;exec u'%u;print x+`'input(56)'`+x";exec u'input(56)'
u="x='\\nu=%r;exec u'%u;print x+`'input(56)'`+x";exec u
outputs 56 and crash.
Both
u="x='\\nu=%r;exec u'%u;print x+`'input(56)'`+x";exec u
and
'input(56)'
u="x='\\nu=%r;exec u'%u;print x+`'input(56)'`+x";exec u
return the original code.
Here is another version without any crashing of the program:
Python 2, 141 bytes
u="x='\\nu=%r;exec u'%u;print x+`'print 62;exit()'`+x";exec u'print 62;exit()'
u="x='\\nu=%r;exec u'%u;print x+`'print 62;exit()'`+x";exec u
Thanks to @ovs who helped me to improve my solution.
Gol><>, 52 bytes
"/+:zQash|2ss}a' 0'rlKH
0"/+:zQash|2ss}a' 0'rlKH
0
Try it online! Outputs 26.
The two halves (identical, 26 bytes):
"/+:zQash|2ss}a' 0'rlKH
0
Try it online! Outputs the original program.
The program path for half and full programs is identical. The only difference is that one more 0 is pushed while going through the 2nd column. If the sum of the top two values is 0, it prints 26 and halts (ash). Otherwise:
2ss} Push 34 and place it at the bottom of the stack
a' 0' Push a newline and ' 0' on the stack
rlK Reverse the entire stack and push a copy of the entire stack
H Print each char from top to bottom and halt
Haskell, 303 bytes
k="\nx=\"k=\"++show k++k++show k\nmain=putStr x where x=\"153\";main=putStr$\"k=\"++show q++q++show q\nq="
x="k="++show k++k++show k
main=putStr x where x="153";main=putStr$"k="++show q++q++show q
q="\nx=\"k=\"++show k++k++show k\nmain=putStr x where x=\"153\";main=putStr$\"k=\"++show q++q++show q\nq="
Prints 153.
k="\nx=\"k=\"++show k++k++show k\nmain=putStr x where x=\"153\";main=putStr$\"k=\"++show q++q++show q\nq="
x="k="++show k++k++show k
main=putStr x where
x="153";main=putStr$"k="++show q++q++show q
q="\nx=\"k=\"++show k++k++show k\nmain=putStr x where x=\"153\";main=putStr$\"k=\"++show q++q++show q\nq="