17
\$\begingroup\$

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.

asked Jan 3, 2016 at 21:26
\$\endgroup\$
7
  • \$\begingroup\$ "Each program pK must be larger in byte size than the previous program pK-1" - huh, why this strange requirement? \$\endgroup\$ Commented Jan 3, 2016 at 21:30
  • 6
    \$\begingroup\$ @nicael Because it's a growing quine sequence. \$\endgroup\$ Commented Jan 3, 2016 at 21:31
  • \$\begingroup\$ Why does p10 print itself and not p11? That makes the problem a bit harder. \$\endgroup\$ Commented Jan 4, 2016 at 0:28
  • \$\begingroup\$ @SuperJedi224 Because simply there is no p11. \$\endgroup\$ Commented Jan 4, 2016 at 0:31
  • \$\begingroup\$ This challenge would have been a lot more interesting if built-in quining functions had been forbidden. \$\endgroup\$ Commented Jan 4, 2016 at 17:42

4 Answers 4

14
\$\begingroup\$

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.)
answered Jan 3, 2016 at 21:32
\$\endgroup\$
5
  • 1
    \$\begingroup\$ Interesting! It is indeed possible. \$\endgroup\$ Commented Jan 3, 2016 at 21:32
  • 7
    \$\begingroup\$ can i haz explanation leik wat each char duz \$\endgroup\$ Commented Jan 3, 2016 at 21:40
  • 3
    \$\begingroup\$ It should be noted that this uses the quining built-in Q which pushes the source code of the program. \$\endgroup\$ Commented Jan 3, 2016 at 22:59
  • \$\begingroup\$ (And further noted that the total length would be somewhere in the vicinity of 150 bytes longer without said built-in.) \$\endgroup\$ Commented Jan 3, 2016 at 23:01
  • \$\begingroup\$ Built-in quining functions are allowed for this challenge. \$\endgroup\$ Commented Jan 3, 2016 at 23:41
9
\$\begingroup\$

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.

answered Jan 4, 2016 at 4:05
\$\endgroup\$
5
  • \$\begingroup\$ I don't think you need alert because of function output. \$\endgroup\$ Commented Jan 4, 2016 at 4:07
  • \$\begingroup\$ Oh I see, nevermind. \$\endgroup\$ Commented Jan 4, 2016 at 4:11
  • \$\begingroup\$ You can take out trailing semicolons, saving you 20 bytes. (Make sure to update the template string inside, too.) \$\endgroup\$ Commented Jan 4, 2016 at 4:32
  • 1
    \$\begingroup\$ @ՊՓԼՃՐՊՃՈԲՍԼ I think the semicolons are needed for concatenation, since I'm not actually including the newlines. \$\endgroup\$ Commented Jan 4, 2016 at 5:05
  • \$\begingroup\$ Nevermind again, then. \$\endgroup\$ Commented Jan 4, 2016 at 5:06
9
\$\begingroup\$

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();
answered Jan 4, 2016 at 1:26
\$\endgroup\$
4
  • 4
    \$\begingroup\$ This is beautiful to look at. \$\endgroup\$ Commented Jan 4, 2016 at 1:27
  • 4
    \$\begingroup\$ All those extra semicolons just to ensure that program 2 is longer than program 1... \$\endgroup\$ Commented Jan 4, 2016 at 1:27
  • \$\begingroup\$ Could you maybe use the regex (\S)+ and the substitution 0ドル1ドル to save some bytes? \$\endgroup\$ Commented Jan 4, 2016 at 15:25
  • \$\begingroup\$ @MartinBüttner Probably, I'll try this afternoon \$\endgroup\$ Commented Jan 4, 2016 at 15:44
2
\$\begingroup\$

ESMin 2, 214 chars / 334 bytes

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

Try it here (Firefox only).

Explanation

i) // quine function: get source code
 đ ⬭ď9) // are there 9 spaces in a row anywhere in the source?
 ?i): // if so, pass the source itself to implicit output
 ⬭+i) // 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.

answered Jan 4, 2016 at 4:35
\$\endgroup\$
3
  • \$\begingroup\$ Which encoding are you using? Seems to be 284 bytes on the ISO 8859-1 encoding. Tested here \$\endgroup\$ Commented Jan 4, 2016 at 6:34
  • \$\begingroup\$ I'm using UTF-8. \$\endgroup\$ Commented Jan 4, 2016 at 8:03
  • \$\begingroup\$ I forgot that it's ESmin 2, so I read the char count as "2,214 chars" :P \$\endgroup\$ Commented Jan 4, 2016 at 12:02

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.