Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

You are to write a sequence of 10 programs p1 p2 ... p10 that satisfy the following properties:

  • pK prints pK+1 for K from 1 to 9
  • p10 prints p10
  • When the first K programs are concatenated, the resulting program p1...pK prints p1...pK.
  • Each program pK must be larger in byte size than the previous program pK-1.
  • All programs must be in the same language.
  • Built-in quining functions (e.g. Q in many languages) are allowed.

Your score is the sum of the byte counts of the 10 programs. Since there are only ten programs, you must make your codes as short as possible. Good luck.

share|improve this question
"Each program pK must be larger in byte size than the previous program pK-1" - huh, why this strange requirement? – nicael Jan 3 at 21:30
@nicael Because it's a growing quine sequence. – Cᴏɴᴏʀ O'Bʀɪᴇɴ Jan 3 at 21:31
Why does p10 print itself and not p11? That makes the problem a bit harder. – SuperJedi224 Jan 4 at 0:28
@SuperJedi224 Because simply there is no p11. – Cᴏɴᴏʀ O'Bʀɪᴇɴ Jan 4 at 0:31
This challenge would have been a lot more interesting if built-in quining functions had been forbidden. – Dennis Jan 4 at 17:42
up vote 15 down vote accepted

Seriously, 245 bytes:

All ten programs concatenated:









There are invisible characters that become visible when executed, a strange property of byte 7F. The trailing newlines on each program are significant. In fact, Seriously automatically appends newlines to its output whether you want it to or not. This just counts the number of newlines in the output, and as soon as that number exceeds 8, it deletes the last character of output. As such, p1..pK will print p1..pK for all K>4.

Q                                  Push source code.
 9uc                               Push \n
    Qc                             Push the number of times it appears in source code.
      8<                           Check if it appears more than 8 times.
        WX     0WX                 If so, run the included code.
          #dX                      Convert string to list, dequeue and discard a newline.
             εj                    Join list back into string.
                  .                Print and halt. (Invisible byte here.)
share|improve this answer
Interesting! It is indeed possible. – Cᴏɴᴏʀ O'Bʀɪᴇɴ Jan 3 at 21:32
can i haz explanation leik wat each char duz – Seadrus Jan 3 at 21:40
It should be noted that this uses the quining built-in Q which pushes the source code of the program. – Martin Ender Jan 3 at 22:59
(And further noted that the total length would be somewhere in the vicinity of 150 bytes longer without said built-in.) – quintopia Jan 3 at 23:01
Built-in quining functions are allowed for this challenge. – Cᴏɴᴏʀ O'Bʀɪᴇɴ Jan 3 at 23:41

Javascript ES6, 1935 bytes

Ten programs:

a=_=>{t=`a=${a};a()`;setTimeout(_=>alert(t.length>200?t:";".repeat(82)+'a=_=>{/*  */u=";".repeat(82)+"a="+a+";a();";this.t?t+=u:alert(u.length<198?u.replace((\\s)+g,"$0$1"):u)};a();'))};a()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;a=_=>{/*  */u=";".repeat(82)+"a="+a+";a();";this.t?t+=u:alert(u.length<198?u.replace((\s)+g,"$0$1"):u)};a();
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;a=_=>{/*   */u=";".repeat(82)+"a="+a+";a();";this.t?t+=u:alert(u.length<198?u.replace((\s)+g,"$0$1"):u)};a();
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;a=_=>{/*    */u=";".repeat(82)+"a="+a+";a();";this.t?t+=u:alert(u.length<198?u.replace((\s)+g,"$0$1"):u)};a();
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;a=_=>{/*     */u=";".repeat(82)+"a="+a+";a();";this.t?t+=u:alert(u.length<198?u.replace((\s)+g,"$0$1"):u)};a();
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;a=_=>{/*      */u=";".repeat(82)+"a="+a+";a();";this.t?t+=u:alert(u.length<198?u.replace((\s)+g,"$0$1"):u)};a();
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;a=_=>{/*       */u=";".repeat(82)+"a="+a+";a();";this.t?t+=u:alert(u.length<198?u.replace((\s)+g,"$0$1"):u)};a();
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;a=_=>{/*        */u=";".repeat(82)+"a="+a+";a();";this.t?t+=u:alert(u.length<198?u.replace((\s)+g,"$0$1"):u)};a();
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;a=_=>{/*         */u=";".repeat(82)+"a="+a+";a();";this.t?t+=u:alert(u.length<198?u.replace((\s)+g,"$0$1"):u)};a();
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;a=_=>{/*          */u=";".repeat(82)+"a="+a+";a();";this.t?t+=u:alert(u.length<198?u.replace((\s)+g,"$0$1"):u)};a();
share|improve this answer
This is beautiful to look at. – Cᴏɴᴏʀ O'Bʀɪᴇɴ Jan 4 at 1:27
All those extra semicolons just to ensure that program 2 is longer than program 1... – SuperJedi224 Jan 4 at 1:27
Could you maybe use the regex (\S)+ and the substitution $0$1 to save some bytes? – Martin Ender Jan 4 at 15:25
@MartinBüttner Probably, I'll try this afternoon – SuperJedi224 Jan 4 at 15:44

JavaScript (ES6), 985

function f(x){x<0||x>8||f.a||x++;alert(f.a=' '.repeat(x)+`${f}f(${x});`.replace(/\d/,x))}f(0);
 function f(x){x<1||x>8||f.a||x++;alert(f.a=' '.repeat(x)+`${f}f(${x});`.replace(/\d/,x))}f(1);
  function f(x){x<2||x>8||f.a||x++;alert(f.a=' '.repeat(x)+`${f}f(${x});`.replace(/\d/,x))}f(2);
   function f(x){x<3||x>8||f.a||x++;alert(f.a=' '.repeat(x)+`${f}f(${x});`.replace(/\d/,x))}f(3);
    function f(x){x<4||x>8||f.a||x++;alert(f.a=' '.repeat(x)+`${f}f(${x});`.replace(/\d/,x))}f(4);
     function f(x){x<5||x>8||f.a||x++;alert(f.a=' '.repeat(x)+`${f}f(${x});`.replace(/\d/,x))}f(5);
      function f(x){x<6||x>8||f.a||x++;alert(f.a=' '.repeat(x)+`${f}f(${x});`.replace(/\d/,x))}f(6);
       function f(x){x<7||x>8||f.a||x++;alert(f.a=' '.repeat(x)+`${f}f(${x});`.replace(/\d/,x))}f(7);
        function f(x){x<8||x>8||f.a||x++;alert(f.a=' '.repeat(x)+`${f}f(${x});`.replace(/\d/,x))}f(8);
         function f(x){x<9||x>8||f.a||x++;alert(f.a=' '.repeat(x)+`${f}f(${x});`.replace(/\d/,x))}f(9);

I misunderstood the rules earlier, so my previous answer was incorrect.

This one uses function hoisting instead of variable hoisting, so it doesn't depend on program 10. In fact, I think it's a quine for any combination of two or more concatenated programs.

Disclaimer: it's really late right now, so everything above could be completely wrong.

share|improve this answer
I don't think you need alert because of function output. – Mama Fun Roll Jan 4 at 4:07
Oh I see, nevermind. – Mama Fun Roll Jan 4 at 4:11
You can take out trailing semicolons, saving you 20 bytes. (Make sure to update the template string inside, too.) – Mama Fun Roll Jan 4 at 4:32
@ՊՓԼՃՐՊՃՈԲՍԼ I think the semicolons are needed for concatenation, since I'm not actually including the newlines. – grc Jan 4 at 5:05
Nevermind again, then. – Mama Fun Roll Jan 4 at 5:06

𝔼𝕊𝕄𝕚𝕟 2, 214 chars / 334 bytes

ℹ)đ ⬭ď9)?ℹ):⬭+ℹ)
 ℹ)đ ⬭ď9)?ℹ):⬭+ℹ)
  ℹ)đ ⬭ď9)?ℹ):⬭+ℹ)
   ℹ)đ ⬭ď9)?ℹ):⬭+ℹ)
    ℹ)đ ⬭ď9)?ℹ):⬭+ℹ)
     ℹ)đ ⬭ď9)?ℹ):⬭+ℹ)
      ℹ)đ ⬭ď9)?ℹ):⬭+ℹ)
       ℹ)đ ⬭ď9)?ℹ):⬭+ℹ)
        ℹ)đ ⬭ď9)?ℹ):⬭+ℹ)
         ℹ)đ ⬭ď9)?ℹ):⬭+ℹ)

Try it here (Firefox only).


ℹ)                // quine function: get source code
  đ ⬭ď9)          // are there 9 spaces in a row anywhere in the source?
        ?ℹ):      // if so, pass the source itself to implicit output
            ⬭+ℹ) // otherwise, add a leading space to the source and pass to implicit output

The program counts the searches for 9 spaces in a row, which is the amount of leading spaces in the 10th program. If it finds a match, then the source code is outputted; otherwise, the source code, lead by a space, is outputted.

share|improve this answer
Which encoding are you using? Seems to be 284 bytes on the ISO 8859-1 encoding. Tested here – Downgoat Jan 4 at 6:34
I'm using UTF-8. – Mama Fun Roll Jan 4 at 8:03
I forgot that it's ESmin 2, so I read the char count as "2,214 chars" :P – Cᴏɴᴏʀ O'Bʀɪᴇɴ Jan 4 at 12:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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