30
\$\begingroup\$

or: Build a vertical quine

Inspired by Take a stand against long lines.

Your task is to build a vertical quine with as short a line length as possible.

Scoring

Shortest line length (excluding newlines) wins, with criteria as a tie-breaker.

Line length is determined as the longest line in your program excluding the line break character.

For example:

$_=
Q.
P

has a line length of 3 and a byte count of 8, whilst:

Q
$
_
P

Has a line length of 1 and a byte count of 7 (assuming no trailing newline).

Rules

Quines must meet the community definition of a quine.

Standard loopholes are forbidden.

\$\endgroup\$
2
  • \$\begingroup\$ Does the rule of the challenge this is inspired from apply here as well? ("All line breaks must be meaningful. Line breaks that can be removed and adjacent lines directly concatenated without an impact on the output, must be removed.") \$\endgroup\$ Feb 19, 2018 at 13:27
  • 6
    \$\begingroup\$ @KevinCruijssen No, I wanted this challenge to have a bit more freedom to encourage shorter line lengths! It was the one thing I wanted to change in the other challenge! \$\endgroup\$ Feb 19, 2018 at 13:30

18 Answers 18

32
\$\begingroup\$

Lenguage, line length 0, ≈ 1.01 × 10805 bytes

The source code consists of

10124204951141713202533972929121310016060433092338061822344361345785088607872212687519180665846846689047959498775873817205954910072327976407177053174071436371843670134990737172675632938993247496933911137703773908536875512359091727633452506044935740750830240213878294804481182083555147915724921824921475110508228264569693355158523956426011218344830576542194309867719995259333487662608933990607888012376767799159279952780093033761421596267435996052643805835600325453580090964941176722519904997142820547696122795384058768166716813179490118821654787005844786013890425692181280317909786461426684986082270532414940905922244777135016193088362341771414388821075092853157152933099269703875111747946164773211049512395358715902962437487134522781505709420586981997748912591875626029183292826655753251235587052422561943

linefeeds, which encodes the brainfuck program that follows.

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

The source code is mostly identical to @jimmy23013's radiation-softened Lenguage quine, minus the . at the end, with ++++++++++.[-] replacing . to print linefeeds instead of null bytes, and the corresponding changes to the data section on line 1.

\$\endgroup\$
4
  • \$\begingroup\$ I knew it was inevitable! I did want an inclusive question though. I wonder if anyone can beat this... \$\endgroup\$ Feb 19, 2018 at 16:15
  • \$\begingroup\$ Lord, this language is the definition of why code-bowling isn't well-received, that's a cool one for sure... Can't believe "Hello World" would require "about 1.75*10**76 yottabytes in ASCII" \$\endgroup\$ Feb 21, 2018 at 15:40
  • \$\begingroup\$ I've asked on meta about accepting a theoretical answer. \$\endgroup\$ Mar 23, 2018 at 6:59
  • 1
    \$\begingroup\$ You can golf more than 99% of the code by using ]++++++++ ++.--> \$\endgroup\$
    – jimmy23013
    Jun 22, 2018 at 15:26
29
\$\begingroup\$

JavaScript, line length 1, 960 956 928 bytes


[
t
,
r
,
u
,
e
,
f
,
a
,
l
,
s
]
=
!
0
+
[
!
1
]
;
[
,
n
,
d
,
,
q
,
i
]
=
t
.
a
+
t
V
=
[
]
[
f
+
i
+
n
+
d
]
;
[
,
,
,
c
,
,
,
o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+e+r+t+y+a+P+q+P+a+P+q+z)`
[t,r,u,e,f,a,l,s]=!0+[!1];[,n,d,,q,i]=t.a+t
V=[][f+i+n+d];[,,,c,,,o,,_,,,,,y,z]=V+0
F=V[E=c+o+n+s+t+r+u+c+t+o+r]
P=(1+e+2+3-4+t)[2]
f=F(r+e+t+u+r+n+_+a+t+o+(0+{})[3])()(3*4+[][E][n+a+(0[E]+0)[9+2]+e])[1]
F(a,a+l+e+r+t+y+a+P+q+P+a+P+q+z)`

Explanation

Whew. Settle in for a ride here, because this is gonna be a treacherous journey...

I spent a long time trying to figure out how to solve this challenge with length 1—no built-ins (directly, anyway), keywords, or even arrow functions—before realizing that it is easily possible with JSF***, which can evaluate any JavaScript code while avoiding any multi-byte tokens. But a JSF solution would easily be thousands of bytes long, if not tens or hundreds of thousands. Thanksfully, we aren't limited to just ()[]+!—we have all of ASCII at our disposal!

I decided to start by golfing the essential building blocks of JSF—the characters that can be built up into strings to "unlock more features," so to speak. We can't use strings directly to get characters, as that would require lines of length 3. So instead, we steal a trick from JSF, getting a few chars from literals that can be built up with single-byte tokens:

JSF***   Used here   Value        Chars unlocked
!![]     !0          true         true
![]      !1          false        fals
[][[]]   t.a         undefined    ndi

From these we can expand outward, starting with [].find, which is a Function object. Converting this to a string function find() { ... gives us access to c, o, space (_), and parentheses (y and z). Perhaps more importantly, we now have access to its constructor, the Function function—which, inceptional as it may sound, gives us the ability to execute code by building a string, passing it to Function(), and then calling the function generated.

I should probably mention the overall method used by the program itself. As of 2015, JavaScript has this really cool feature called "tagged templates," which not only allows unescaped newlines in strings, but also lets us call a function with a string literal directly (in a way; myFunc`abc`; is roughly equivalent to myFunc(["abc"])). If we put the function call as the last thing in the program, the general structure will look like this:

code;func`code;func`

All func has to do then is output its argument, followed by a backtick, then its argument again, and a second backtick. Assuming we have the argument in a and a backtick stored in f, we can accomplish this with the code alert(a+f+a+f). However, at the moment, we are missing + and the backtick itself. + (stored in P) isn't hard; we steal another trick from JSF, building the string 1e23, converting to a number, then back to a string, giving "1e+23".

Getting a backtick is a bit more complicated. At first, I tried obtaining String.fromCharCode, but finding a C turned out to be nearly as difficult. Fortunately, atob is easy enough to obtain (Function("return atob")(); b is generated from 0+{}, which gives [object Object]) and can give any ASCII char, if a proper magic string is found. A short script gave me 12A as one of the options, which can conveniently be found in 12Array (a bit shorter to generate, thanks to [].constructor[n+a+m+e]; m is found in 0 .constructor+0: "function Number() { ...").

Finally, we stick everything together. We assign the backtick to variable f, but since we can't use it directly in the function string, we instead set variable q to the letter f and use that instead. This makes our final string a+l+e+r+t+y+a+P+q+P+a+P+q+z, or "alert(a+f+a+f)". We then feed this to Function(), feed the our finished code to the result, and voila, we have a JavaScript quine with no more than one char per line!


My head feels terrible at the moment, so please inquire about any mistakes I've made or things I've missed in this explanation, and I'll get back to you after I've had some rest...

\$\endgroup\$
9
  • \$\begingroup\$ Nice! Although really not a JS programmer, I can guess the gist of this from what I've read about JSFuck, but I'd like an explanation especially of that f= line. \$\endgroup\$ Feb 20, 2018 at 2:08
  • 1
    \$\begingroup\$ @ØrjanJohansen Sorry, I've been trying to write an explanation for the whole thing, but it's not going very well so I'll just answer your question quickly: it's a convoluted way to set f to a single backtick. The line itself is equivalent to f=atob("12Array")[1]. The other trick is that q is actually set to the letter f in the first line, so that in the F(...) line, I can use it to put the letter f in the evaluated string, since variable f is no longer set to that letter. The a+l+e+r+t+y+a+P+q+P+a+P+q+z is equivalent to "alert(a+f+a+f)". \$\endgroup\$ Feb 20, 2018 at 2:57
  • \$\begingroup\$ Great, now I understand it! You might mention what 0+{} and 0[E] stringify to in order to get b and m. \$\endgroup\$ Feb 20, 2018 at 4:50
  • \$\begingroup\$ Nice indeed! Much smaller than my attempt, although we used a simar approach! \$\endgroup\$ Feb 20, 2018 at 6:22
  • \$\begingroup\$ @DomHastings So long the link doesn't even work ;-) \$\endgroup\$ Feb 20, 2018 at 22:35
15
\$\begingroup\$

Haskell, line length 6, 400 343 336 bytes

{main=
putStr
$s++(s
>>=(++
":\n")
.show)
++
"[]}";
s='{':
'm':
'a':
'i':
'n':
'=':
'\n':
'p':
'u':
't':
'S':
't':
'r':
'\n':
'$':
's':
'+':
'+':
'(':
's':
'\n':
'>':
'>':
'=':
'(':
'+':
'+':
'\n':
'"':
':':
'\\':
'n':
'"':
')':
'\n':
'.':
's':
'h':
'o':
'w':
')':
'\n':
'+':
'+':
'\n':
'"':
'[':
']':
'}':
'"':
';':
'\n':
's':
'=':
[]}

Try it online! I'm not aware of a way around putStr, thus the line length of 6. The outer curly braces allow to get rid of the otherwerwise required indention after a newline within a single declaration.

\$\endgroup\$
12
\$\begingroup\$

><>, 22 bytes, line length 1

/
v
o
a
o
^
}
-
d
:
"

Try it online!

-6 bytes thanks to Emigna.

\$\endgroup\$
0
12
\$\begingroup\$

CJam, line length 1, 16 13 bytes

"
_
p
"

_
p

Try it online!

It's a small miracle that inserting newlines into the standard quine {"_~"}_~ even shorter standard quine "_p"␊_p does the right thing. (Thanks, Martin!) The trailing newline is necessary.

Explanation (with • as newline)

"•_•p•"        Push that string.
       ••      Do nothing.
         _     Duplicate the string.
          •    Do nothing.
           p   Pop it and print it with quotes and a newline: "•_•p•"•
            •  Do nothing.

On termination, what's left on the stack is printed (•_•p•), yielding total output "•_•p•"••_•p•.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ All I have to say is ... •_• \$\endgroup\$
    – corsiKa
    Feb 20, 2018 at 17:51
6
\$\begingroup\$

Haskell + CPP, line length 2, 705 237 bytes

m\
a\
i\
n\
=\
p\
u\
t\
S\
t\
r\
$\
(\
:\
"\
\\
\\
\\
n\
"\
)\
=\
<\
<\
s\
+\
+\
s\
h\
o\
w\
 \
s\
;\
s\
=\
"\
m\
a\
i\
n\
=\
p\
u\
t\
S\
t\
r\
$\
(\
:\
\\
"\
\\
\\
\\
\\
\\
\\
n\
\\
"\
)\
=\
<\
<\
s\
+\
+\
s\
h\
o\
w\
 \
s\
;\
s\
=\
"\

Try it online! Using the flag -CPP which enables the C pre-processor allows us to use a backslash at the end of a line to continue it on the next line.

The actual code is main=putStr$(:"\\\n")=<<s++show s;s="<data>".

Edit: A casual -468 bytes thanks to Ørjan Johansen!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ It saves a lot of escaping to change that to main=putStr$(:"\\\n")=<<s++show s;s="<data>". Try it online! \$\endgroup\$ Feb 19, 2018 at 18:45
5
\$\begingroup\$

Rust, line length: 5, bytes: 301 299

Try it online

Despite how it looks, this isn't an esoteric programming language, there is just a lot of format line noise.

Vertical length of 5 was chosen to be able to use print. I don't think there is a way to print that would have shorter vertical length, declaring C functions uses extern keyword, stdout is 6 bytes long, write is 5 bytes long, no_main is 7 bytes long (main is usually a function ;)).

fn
main
(){
let
t=(
r#"fn
main
(){
let
t=("#
,r#")
;
print
!(
r#"{}
r#"{
}"{}
,r#"{
}"{},
r#"{
}"{}
{}{}{
}{
}""#,
r#"
,t.0,
t.0,
'#',
t.1,
'#',
t.2,
'#',
t.1,
'#',
t.2,
'}'
)"#
)
;
print
!(
r#"{}
r#"{
}"{}
,r#"{
}"{},
r#"{
}"{}
{}{}{
}{
}"#
,t.0,
t.0,
'#',
t.1,
'#',
t.2,
'#',
t.1,
'#',
t.2,
'}'
)}
\$\endgroup\$
4
  • \$\begingroup\$ Isn't it horizontal length? \$\endgroup\$
    – anatolyg
    Feb 20, 2018 at 0:09
  • \$\begingroup\$ @anatolyg fixed \$\endgroup\$
    – 0..
    Feb 20, 2018 at 5:27
  • \$\begingroup\$ Raw string nesting without syntax highlighting makes this impossible to interpret. I don't think cargo fmt would even help here... \$\endgroup\$
    – CAD97
    Feb 20, 2018 at 5:36
  • \$\begingroup\$ @CAD97 If what you want is syntax highlighting, play.rust-lang.org highlights this correctly which is why I used it instead of TIO for "Try it online" link. \$\endgroup\$
    – 0..
    Apr 7, 2018 at 9:18
4
\$\begingroup\$

05AB1E, Line length: 1, Byte count: 43

2
"
D
3
4
«
ç
¶
ì
ý
Ô
"
D
3
4
«
ç
¶
ì
ý
Ô


Try it online!

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

Japt, line length 1, 20 bytes

Based off the standard Japt quine by ETHproductions.

"
i
Q
 
²
"
i
Q
 
²

Try it here!

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

JavaScript (ES6), line length 3, 17 bytes

f=
_=>
`f=
${f
}`
\$\endgroup\$
2
\$\begingroup\$

Red, line-length: 10, 49 bytes

s: [prin [
    "s:"
    mold s
    "do s"
]] do s

Try it online!

This in fact is a Rebol quine

Explanation: Red/Rebol's mold follows the coding style of putting 4 spaces offset.

s: [prin [     ; s is a block; print the following: 
    "s:"       ; literal "s:"
    mold s     ; the representation of the block itself - all between []
    "do s"     ; literal "do s"
]] do s        ; evaluate the block
\$\endgroup\$
2
\$\begingroup\$

RProgN, 3 bytes, line length 1

0
0

Try it online!

A copy of Dennis' answer here (go upvote him too)

This is a conforms to our current definition of a proper quine, as the first 0 encodes the second 0 and vice-versa.

\$\endgroup\$
2
  • 3
    \$\begingroup\$ It's much too bad we haven't come to a consensus on a better definition :-/ \$\endgroup\$ Feb 20, 2018 at 1:43
  • \$\begingroup\$ @ETHproductions Well, there's some support for this definition. \$\endgroup\$ Feb 21, 2018 at 9:44
2
\$\begingroup\$

RProgN 2, L = 1, B = 15 bytes

«
Ø
.
`
-
S
`
.

This is equivilent to the program:

«Ø.`
-S`
.

Breakdown

« first pushes a function representing implicitly the rest of the program to the stack, and then continues execution. Ø. appends an empty string to the function, which stringifies it. This will always stringify like the equivilent program, due to newlines being no-ops. `\n- Removes all newlines from the string, now looking like «Ø.`=S`.. S then converts it to a stack of single characters, and `\n. joins the stack by newlines, returning the expected program.

Try it online!

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

Underload, line length 1, 20 bytes

(
:
a
S
S
)
:
a
S
S

Try it online!

This is just the standard Underload quine with newlines appended. Requires an implementation like the TIO one which ignores unknown command characters.

The part in () is a string literal put on the stack, : duplicates it, a wraps the top stack entry in parentheses, and S prints.

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

Perl 5, 259 bytes


$
_
=
p
.
r
.
i
.
n
.
t
.
q
{

'
$
_
=
p
.
r
.
i
.
n
.
t
.
q
{
'
,
&
{
I
.
"
X
0
y
h
~
"
^
"
E
O
0

y
"
.
x
}
(
$
_
,
6
,
-
1
)
,
'
}
;
&
{
I
.
"
X
0
o
k
h
~
"
.
(
Y
|
p
)
^
"
E
O
0
|
f
s
o
"
}
'
}
;
&
{
I
.
"
X
0
o
k
h
~
"
.
(
Y
|
p
)
^
"
E
O
0
|
f
s
o
"
}

Try it online!

Verification.

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

Javascript (ES6 REPL), full-program, line-length: 3, byte-count: 31

(
f=
_=>
`(
f=
${f
}
)
()`
)
()

This is a port of @kamoroso94's answer to a self-contained full program.

If anybody finds a way to strip off some bytes without adding more to the line-length feel free to comment :)

\$\endgroup\$
2
  • \$\begingroup\$ Note that this still doesn't actually output anything, unless you run it in an REPL. I would call it JavaScript (ES6 REPL) \$\endgroup\$ Feb 19, 2018 at 15:51
  • \$\begingroup\$ oh shoot, way to used to chrome's console... \$\endgroup\$
    – Brian H.
    Feb 19, 2018 at 15:54
1
\$\begingroup\$

Pip, line length 1, 35 bytes


V
Y
"
[
`
V
Y
`
y
]
.
C
:
3
.
4
"

Try it online!

Based on the shortest known Pip quine, V Y"`V Y`.RPy". The main difficulty in squishing it to line length 1 is RP, which can't be split over two lines. But in this case, all RP (repr) does is wrap the string in double quotes, which we can do directly.

Here's an explanation based on a horizontal version:

V Y"[`V Y`y].C:3. 4"
  Y"               "  Yank this string into the variable y
V                     and eval it
                      The code that is eval'd:
    [      ]           Build a list containing:
     `V Y`              this Pattern object (used for regex, but here useful as a
                          string-like object that doesn't need double quotes)
          y             y, the whole string
               3. 4    Concatenate 3 and 4 to make 34 (since the 2-digit number won't work
                         in the vertical version)
             C:        Convert to ASCII character (: forces the precedence lower than .)
            .          Concatenate the " to the end of each list element
                      The resulting list is printed, concatenated together, with a
                        trailing newline
\$\endgroup\$
1
\$\begingroup\$

Befunge-98, 41 bytes

^
@
,
,
a
-
1
*
5
7
|
 
#
!
a
#
:
,
^
$
"

Try it online!

Really just a normal quine turned sideways, with some extra stuff to print newlines.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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