Growing Quine Sequence

18

1

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.

Conor O'Brien

Posted 2016-01-03T21:26:06.653

Reputation: 36 228

"Each program pK must be larger in byte size than the previous program pK-1" - huh, why this strange requirement? – nicael – 2016-01-03T21:30:39.800

6@nicael Because it's a growing quine sequence. – Conor O'Brien – 2016-01-03T21:31:00.863

Why does p10 print itself and not p11? That makes the problem a bit harder. – SuperJedi224 – 2016-01-04T00:28:12.060

@SuperJedi224 Because simply there is no p11. – Conor O'Brien – 2016-01-04T00:31:49.890

This challenge would have been a lot more interesting if built-in quining functions had been forbidden. – Dennis – 2016-01-04T17:42:27.567

@Dennis Perhaps, but if I was sure that a solution indeed existed without quining functions, I would have banned them. Further, before I had clarified whether or not there use was allowed, an answer already used them. Since this is not a conventional quine challenge, it is not natural to assume that quining functions would be prohibited. – Conor O'Brien – 2016-01-04T18:15:15.963

@CᴏɴᴏʀO'Bʀɪᴇɴ What should happen if a null byte is contained in the source, since printing a null byte \x00 results in nothing being printed for that char? Is that acceptable as long as none of the programs contains only null bytes (or is that also acceptable)? Or must a program also "grow" by more than just a null byte? – mbomb007 – 2016-01-04T21:13:00.863

Answers

15

Seriously, 245 bytes:

All ten programs concatenated:

Q9ucQc8<WX#dXεj0WX.Q9ucQc8<WX#dXεj0WX.
Q9ucQc8<WX#dXεj0WX.

Q9ucQc8<WX#dXεj0WX.


Q9ucQc8<WX#dXεj0WX.



Q9ucQc8<WX#dXεj0WX.




Q9ucQc8<WX#dXεj0WX.





Q9ucQc8<WX#dXεj0WX.






Q9ucQc8<WX#dXεj0WX.







Q9ucQc8<WX#dXεj0WX.









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

quintopia

Posted 2016-01-03T21:26:06.653

Reputation: 3 899

1Interesting! It is indeed possible. – Conor O'Brien – 2016-01-03T21:32:59.557

7can i haz explanation leik wat each char duz – Seadrus – 2016-01-03T21:40:28.583

3It should be noted that this uses the quining built-in Q which pushes the source code of the program. – Martin Ender – 2016-01-03T22:59:13.423

(And further noted that the total length would be somewhere in the vicinity of 150 bytes longer without said built-in.) – quintopia – 2016-01-03T23:01:13.620

Built-in quining functions are allowed for this challenge. – Conor O'Brien – 2016-01-03T23:41:10.857

9

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();

SuperJedi224

Posted 2016-01-03T21:26:06.653

Reputation: 11 342

4This is beautiful to look at. – Conor O'Brien – 2016-01-04T01:27:09.737

4All those extra semicolons just to ensure that program 2 is longer than program 1... – SuperJedi224 – 2016-01-04T01:27:38.447

Could you maybe use the regex (\S)+ and the substitution $0$1 to save some bytes? – Martin Ender – 2016-01-04T15:25:02.530

@MartinBüttner Probably, I'll try this afternoon – SuperJedi224 – 2016-01-04T15:44:06.480

9

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.

grc

Posted 2016-01-03T21:26:06.653

Reputation: 18 565

I don't think you need alert because of function output. – Mama Fun Roll – 2016-01-04T04:07:21.453

Oh I see, nevermind. – Mama Fun Roll – 2016-01-04T04:11:49.460

You can take out trailing semicolons, saving you 20 bytes. (Make sure to update the template string inside, too.) – Mama Fun Roll – 2016-01-04T04:32:53.580

1@ՊՓԼՃՐՊՃՈԲՍԼ I think the semicolons are needed for concatenation, since I'm not actually including the newlines. – grc – 2016-01-04T05:05:09.127

Nevermind again, then. – Mama Fun Roll – 2016-01-04T05:06:31.977

2

2, 214 chars / 334 bytes

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

Try it here (Firefox only).

Explanation

ℹ)                // 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.

Mama Fun Roll

Posted 2016-01-03T21:26:06.653

Reputation: 7 234

Which encoding are you using? Seems to be 284 bytes on the ISO 8859-1 encoding. Tested here

– Downgoat – 2016-01-04T06:34:00.427

I'm using UTF-8. – Mama Fun Roll – 2016-01-04T08:03:04.110

I forgot that it's ESmin 2, so I read the char count as "2,214 chars" :P – Conor O'Brien – 2016-01-04T12:02:22.660