54
\$\begingroup\$

Long-time lurker, first-time poster. So here goes.

In the Wikipedia page for quine, it says that "a quine is considered to be 'cheating' if it looks at its own source code." Your task is to make one of these "cheating quines" that reads its own source code.

This is , so the shortest code in bytes - in each language - wins. This means that a 5-byte Pyth script would not beat a 21-byte Python script - but a 15-byte Python script would.

You must use file I/O to read the source code, so the following JavaScript code, taken from the official Wikipedia page, is invalid:

function a() {
    document.write(a, "a()");
}
a()

It must access the source code of the file on disk.

You are not allowed to specify the file name. You must make it detect the filename itself.

Everyone clear? Go!

\$\endgroup\$
  • 1
    \$\begingroup\$ Is a trailing newlines not present in the original file allowed? \$\endgroup\$ – isaacg Oct 29 '15 at 22:04
  • 3
    \$\begingroup\$ @isaacg IMHO That's not a quine, since it is not the source code. \$\endgroup\$ – mınxomaτ Oct 29 '15 at 22:05
  • 3
    \$\begingroup\$ You should state a requirement that it determine the actual filename instead of assuming a hard-coded string for the source location. \$\endgroup\$ – feersum Oct 29 '15 at 22:26
  • 3
    \$\begingroup\$ I agree with @feersum though, that requiring a specific file name makes this challenge way to trivial. \$\endgroup\$ – mınxomaτ Oct 29 '15 at 22:33
  • 1
    \$\begingroup\$ Can we assume that (for compiled languages) the source code is in the same folder (i.e. we can just add ".cpp" or ".hs" to arg[0] to get the source). \$\endgroup\$ – HEGX64 Nov 1 '15 at 9:15

62 Answers 62

0
\$\begingroup\$

Perl 6 / POSIX shell, 16 bytes

run 'cat',$?FILE

Try it online!

\$\endgroup\$
0
\$\begingroup\$

R, 44 bytes

cat(scan(sub(".*=","",commandArgs()[4]),""))

Prints to stderr as well. If that's not allowed this works for 46 bytes:

cat(readLines(sub(".*=","",commandArgs()[4])))

Run these from the command line using Rscript.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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