10
\$\begingroup\$

This challenge, if you accept it, is to write three functions or programs A, B, and C:

  • A is a quine that outputs all of A,B and C (which is also the whole content of the code in your submission).
  • B takes a parameter F and checks whether it is such a quine (outputting FBC), or doing something different.
  • C takes a parameter G and checks whether G possibly works like B (checking whether F outputs FGC). It is impossible to decide whether a function is a quine checker, so let's do something simpler:
    • It must return truthy if G is valid for B.
    • It must return falsey if G returns falsey for all valid quines, or G returns truthy for all valid non-quines.
    • It can return anything, crash or not terminate, etc, if it is any of the other cases.

Note that B is possible. A and F doesn't have any input, so you can just run them and check the result.

Rules

  • There should be some way to tell which parts are A, B and C from the output of A. For example: each has one line, or they are recognized as three functions in the interpreter.
  • Each function should run with only the definition of itself, not your complete code.
  • You can use a function/program or its source code, or a pair of both as the input of B (or G) and C.
  • You can redefine truthy/falsey to a subset of those values. You can also consistently require F returning some type you choose, like a single string.
  • You can require A, B, F and G, if they are called with valid parameters, consistently don't have some types of other inputs or side effects you choose, such as accessing global variables, or reading stdin, etc.
  • You can also assume F and G, if they are called with valid parameters, always terminate.
  • F should work in the same condition as A. So it cannot depend on B or C or another variable's existence, unless that variable is defined in its own part in its output.
  • No functions or programs can read its own source code.
  • This is code-golf, shortest code (which is the output of A) in bytes wins.
\$\endgroup\$
7
  • \$\begingroup\$ B is still impossible in general because F might not terminate, as well as in practice in many languages because it requires combinations of abilities like temporary redirection of stdout and either function-to-string or exec. The best you can hope for is probably a half-working solution in a LISP. \$\endgroup\$ Commented Apr 16, 2015 at 7:47
  • \$\begingroup\$ How would you check G with all quines and non-quines? I'm currently working on a Mathematica solution. \$\endgroup\$ Commented Apr 16, 2015 at 10:35
  • \$\begingroup\$ @PeterTaylor "You can also assume F and G, if they are called with valid parameters, always terminate." And "output" can mean return, not necessarily print to stdout. \$\endgroup\$
    – jimmy23013
    Commented Apr 16, 2015 at 15:04
  • \$\begingroup\$ @LegionMammal978 It is impossible to check all quines and non-quines. But the task of C is something simpler, where you only need to check one quine and one non-quine. \$\endgroup\$
    – jimmy23013
    Commented Apr 16, 2015 at 15:08
  • 1
    \$\begingroup\$ @PyRulez I think this is in the spirit of this challenge, so I'm going to allow it. But the function cannot access its own source code. \$\endgroup\$
    – jimmy23013
    Commented Apr 18, 2015 at 3:20

1 Answer 1

1
\$\begingroup\$

CJam, 254 bytes

An example answer, not golfed.

{{['{\"_~}{{[1$'{@\"_~}"{{["_~}"2$+'{@"_~}"]s`"{{['{\\"\+"]s}_~}"+~1$~{L}@~!&}_~}_``1>W<"\"]s\~=}_~}"@]s}_~}{{[1$'{@"_~}{{[\"_~}\"2$+'{@\"_~}\"]s`\"{{['{\\\\\"\+\"]s}_~}\"+~1$~{L}@~!&}_~}"]s\~=}_~}{{["_~}"2$+'{@"_~}"]s`"{{['{\\"\+"]s}_~}"+~1$~{L}@~!&}_~}

The 3 functions are:

{{['{\"_~}{{[1$'{@\"_~}"{{["_~}"2$+'{@"_~}"]s`"{{['{\\"\+"]s}_~}"+~1$~{L}@~!&}_~}_``1>W<"\"]s\~=}_~}"@]s}_~}
{{[1$'{@"_~}{{[\"_~}\"2$+'{@\"_~}\"]s`\"{{['{\\\\\"\+\"]s}_~}\"+~1$~{L}@~!&}_~}"]s\~=}_~}
{{["_~}"2$+'{@"_~}"]s`"{{['{\\"\+"]s}_~}"+~1$~{L}@~!&}_~}

A and F take no parameters and return a string. B, G and C take a CJam block as parameter and return 1 for truthy, or 0 for falsey.

\$\endgroup\$

Your Answer

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

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