A program / script which outputs ONLY its own source code

Discussion in 'Scripting' started by Mutoid, Jan 10, 2016.

  1. Mutoid

    Mutoid MDL Member

    Sep 23, 2015
    182
    24
    10
    #1 Mutoid, Jan 10, 2016
    Last edited: Jan 10, 2016
    Really not sure where to post this .... " Coding Life " ? ... " Serious Discussion " ?

    Anyway , post festive season .... and things can be a bit dull , so here is a little challenge .

    Write a program / script which when run gives as the output ONLY its own source code ,
    .... and clearly , this is NOT the same as merely listing the code :)

    In some ways it is like an inverse of the classic " Hello World " type of thing.

    Use any language you like ( but as far as I know , it's only actually possible in a few )

    It's tricky , and more difficult than it first appears !

    But then with so much stuff online these days , maybe it's not that much of a challenge any more.

    Any initial thoughts from anyone ? .... post them here

    .... the ideas / strategies may be more interesting than actual working code !
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. Michaela Joy

    Michaela Joy MDL Crazy Lady

    Jul 26, 2012
    3,507
    3,692
    120
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Mutoid

    Mutoid MDL Member

    Sep 23, 2015
    182
    24
    10
    #3 Mutoid, Jan 16, 2016
    Last edited: Jan 16, 2016
    (OP)
    That's a good find Michaela Joy .
    I remembered the quine concept from Hofstader's wonderful book " Godel , Escher Bach "
    but I didn't know of that website when I posted , and I had no idea that it could be done in so many languages.
    I guess it makes my little "challenge" a bit pointless :)

    I was starting to think that nobody else was interested .... after all , it achieves nothing practical
    .... just another bit of "navel gazing " really , but thanks for replying !
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. ofernandofilo

    ofernandofilo MDL Member

    Sep 26, 2015
    211
    128
    10
    #4 ofernandofilo, Jun 12, 2016
    Last edited by a moderator: Apr 20, 2017
    Hum, like this?

    Just save the below code with the ext: .bat or .cmd
    Code:
    @echo off
    :: This is a CheatingQuineBatchScript
    for /F "delims=" %%L in (%0) do echo %%L
    
    Or

    Code:
    @echo off
    :: This is a CheatingQuineBatchScriptWithPause
    for /F "delims=" %%L in (%0) do echo %%L
    pause
    
    If you don't want to navegate with the CMD.

    * edit: "Quines, per definition, cannot receive any form of input, including reading a file, which means a quine is considered to be 'cheating' if it looks at its own source code.", from: en .wikipedia .org/wiki/Quine_(computing)


    Oh, I see now. It's much harder, :D

    cheers!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. moku1

    moku1 MDL Novice

    May 31, 2013
    1
    0
    0
    ioccc .org/1994/smr.hint
    Sorry to ruin the fun.
     
  6. Michaela Joy

    Michaela Joy MDL Crazy Lady

    Jul 26, 2012
    3,507
    3,692
    120
    Quines are actual programs. Not empty files.

    So, no fun ruined.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...