JavaScript, 62 61 37 bytes
Thanks to @Doᴡɴɢᴏᴀᴛ for the help!
Original [37 bytes]:
f=_=>'f='+'_'.repeat((10+f).length)+f
Child [74 bytes]:
f=______________________________________=>'f='+'_'.repeat((10+f).length)+f
Grandchild [148 bytes]:
f=________________________________________________________________________________________________________________=>'f='+'_'.repeat((10+f).length)+f
Alternate (with printing to console, and as a full program):
Original [61 bytes]:
f=_=>console.log(`f=${'_'.repeat((0+f).length+5)+f};f()`);f()
Child [122 bytes]:
f=______________________________________________________________=>console.log(`f=${'_'.repeat((0+f).length+5)+f};f()`);f()
Grandchild [244 bytes]:
f=________________________________________________________________________________________________________________________________________________________________________________________=>console.log(`f=${'_'.repeat((0+f).length+5)+f};f()`);f()
How it works!
1. f=_=>
Define function f as console.log(...)
2. ;f()
Run function f.
3. (in function f)
Notes
console.log
is necessary instead of alert
because alert
doesn't seem to play well with really long strings (at least on my machine/browser configuration)
- The
_
's are inserted into the name of the (unused) parameter of function f, to ensure that they are included in the stringification of f.
- Main improvement (aside from getting rid of the
console.log
) of the first solution over the second: adding 10
to the function instead of 0
to cast it to string makes it one byte longer, eliminating the need to add 1 to the length afterwards, saving a byte.
How about accessing the file by reading itself/accessing the place where the code is contained? – Conor O'Brien – 2016-01-15T23:36:57.927
@CᴏɴᴏʀO'Bʀɪᴇɴ that's not allowed as that would violate rules I believe. – Downgoat – 2016-01-15T23:37:37.203
It's not a quine built-in. e.g.
document.getElementById("code")
or something. – Conor O'Brien – 2016-01-15T23:38:24.073@CᴏɴᴏʀO'Bʀɪᴇɴ oh whoops, I left out a few words :| I meant to say "that would violate our quine rules, I believe" – Downgoat – 2016-01-16T00:24:35.287
Oh, I see. I didn't think this was a quine challenge. – Conor O'Brien – 2016-01-16T00:27:18.130
2@Doᴡɴɢᴏᴀᴛ the quine rules are recommended by the tag wiki but don't apply automatically – Martin Ender – 2016-01-16T00:27:45.330
I accidentally wrote a program that did this while working on the growing quine challenge – quintopia – 2016-01-16T00:31:08.503
1
Related: http://codegolf.stackexchange.com/questions/21831/program-that-creates-larger-versions-of-itself-quine-variant
– PyRulez – 2016-01-16T01:35:50.2102Related. Related. Related. – Martin Ender – 2016-01-16T11:39:33.597