This challenge is similar to Can you Meta Quine?

A quine is a program that produces itself on STDOUT. This challenge is to produce a program A which when run produces a program B on STDOUT. Program B when run produces program A on STDOUT. Programs A and B must be written in (and run in) the same language. The linked question constrained A != B. That looked too easy. So for this question, we insist A and B are antiquines, using the following rules:

  1. Programs A and B may not use any of the same characters, save for whitespace and statement separators, and punctuation characters.
  2. Programs A and B must each contain at least one character that is neither whitespace nor a statement separator, nor a punctuation character.
  3. For the purpose of rules 1 and 2, the term 'whitespace' excludes any symbol or sequence of symbols which itself is a statement, operator or symbol that is interpreted (as opposed to a separator). Therefore in the Whitespace language, there is no whitespace.
  4. A statement separator is a syntactic element conventionally used within the language to separate statements. This would include the newline in python, or the semicolon in Java, perl or C.
  5. A punctuation character is an ASCII character which is neither whitespace nor in the POSIX word character class (i.e. an underscore is not punctuation for this purpose) - i.e ispunct() would return true, and it's not _.
  6. Program A when run must produce a program (Program B) on its STDOUT, which when run in turn produces Program A.
  7. Programs A and B must be in the same programming language.
  8. The programming language used must actually be a programming language. Unless you make a good case otherwise, I'll suggest it must be Turing complete.
  9. At least one of A and B must execute at least one statement within the language.

This is code golf, so the shortest answer wins, the score being the length of program A in bytes (i.e. the length of program B is not relevant).

  • \$\begingroup\$ Can you please add "punctuation" to the list of exceptions in the first clause? It's impossible to solve this task in many languages (especially those that require you to you curly braces in the main function) otherwise. \$\endgroup\$
    – FUZxxl
    Commented Aug 16, 2014 at 19:21
  • \$\begingroup\$ related but probably sufficiently different. \$\endgroup\$ Commented Aug 16, 2014 at 19:23
  • \$\begingroup\$ @FUZxxl I've permitted punctuation marks but excluded underscores. \$\endgroup\$
    – abligh
    Commented Aug 16, 2014 at 19:32
  • 1
    \$\begingroup\$ For the purposes here, are A and a considered different "characters"? \$\endgroup\$ Commented Aug 17, 2014 at 17:33
  • 1
    \$\begingroup\$ It would be better if you provided a complete list of ASCII characters that match rule 5. \$\endgroup\$ Commented Aug 17, 2014 at 18:37

3 Answers 3


Pascal (731 characters)

Program A:

program s;{$h+}uses sysutils;const p='program s;{$h+}uses sysutils;const p=';a='a';aa=''';';aaa='a=''';aaaa='''';aaaaa='begin write(lowercase(p+aaaa+p+aa+aaa+a+aa+a+aaa+aaaa+aa+aa+a+a+aaa+aaa+aaaa+aa+a+a+a+aaa+aaaa+aaaa+aa+a+a+a+a+aaa+stringreplace(stringreplace(stringreplace(stringreplace(aaaaa,aaaa,aaaa+aaaa,[rfreplaceall]),''lower''+''c'',''tm''+''p'',[]),''up''+''c'',''lower''+''c'',[]),''tm''+''p'',''up''+''c'',[])+aa+aaaaa))end.';begin write(upcase(p+aaaa+p+aa+aaa+a+aa+a+aaa+aaaa+aa+aa+a+a+aaa+aaa+aaaa+aa+a+a+a+aaa+aaaa+aaaa+aa+a+a+a+a+aaa+stringreplace(stringreplace(stringreplace(stringreplace(aaaaa,aaaa,aaaa+aaaa,[rfreplaceall]),'lower'+'c','tm'+'p',[]),'up'+'c','lower'+'c',[]),'tm'+'p','up'+'c',[])+aa+aaaaa))end.

Outputs program B:


Outputs program A.

  • 4
    \$\begingroup\$ I am enjoying the (mis)use of case translation. \$\endgroup\$
    – abligh
    Commented Aug 17, 2014 at 23:49

ROT13 (not competing anymore after rule update)

Not sure if this counts as a language, but I certainly didn't make it up for the challenge. Usually answers for certain utilities such as sed are accepted as well. However, it's a judgement call, so if it doesn't count I'll remove it (is there a meta discussion somewhere on what counts as a language? Edit: There is now)


Cycles between A and N:

~>> echo "A" | rot13
~>> echo "A" | rot13 | rot13
  • \$\begingroup\$ I think this doesn't work, as rot13 is simply taking input on STDIN, not executing a program. If you are arguing that it is a zero length program, that fails to satisfy rule 2. The program (with sed) is what's passed in sed -e. If this was acceptable, then cat would be a quine, and tac would be a quine and antiquine. However, nothing is producing the source to cat, tac or for that matter rot13. \$\endgroup\$
    – abligh
    Commented Aug 16, 2014 at 19:42
  • 1
    \$\begingroup\$ @abligh If rot13 is the language used, why should I have to print the source code for rot13? Also, if I run Golfscript, Python or anything else, I will likely just pass the source code to it via stdin or file, so there isn't really any difference. In this case rot13 is the interpreter. \$\endgroup\$
    – Ingo Bürk
    Commented Aug 16, 2014 at 19:45
  • 1
    \$\begingroup\$ rot13 as a programming language does not appear to satisfy any reasonable definition of 'programming language', and it's not interpreting anything. I will amend the question to make that clearer. \$\endgroup\$
    – abligh
    Commented Aug 16, 2014 at 19:49
  • 1
    \$\begingroup\$ Fine with me. I'll leave this answer as not competing anymore and start a meta discussion. Nice challenge, by the way. Can't wait to see "real" solutions! \$\endgroup\$
    – Ingo Bürk
    Commented Aug 16, 2014 at 19:54

GolfScript, 13 bytes


The output is


which generates the initial program.

The byte count include the trailing LF, since the output of the output will contain it.

Try it online.

How it works

1       # Push 1.
{       # Start code block.
  \~\   # Apply logical NOT to the second topmost element of the stack.
  ".~"  # Push that string.
}       # End code block.
.~      # Duplicate the code block and execute the copy.

GolfScript prints the stack's contents upon termination.

  • \$\begingroup\$ Please read the problem statement again - Programs A and B may not use any of the same characters, save for whitespace and statement separators, and punctuation characters. \$\endgroup\$
    – isaacg
    Commented Aug 18, 2014 at 16:42
  • 2
    \$\begingroup\$ Everything but 1 and 2 is punctuation. \$\endgroup\$
    – Dennis
    Commented Aug 18, 2014 at 16:44
  • \$\begingroup\$ OK, the rules were changed since I last read them. \$\endgroup\$
    – isaacg
    Commented Aug 18, 2014 at 16:46
  • 1
    \$\begingroup\$ Yup, that works. I'd phrased the rules to prevent whitespace being used as statements, but forgot the same loophole would be present for punctuation. So loophole legally exploited. \$\endgroup\$
    – abligh
    Commented Aug 18, 2014 at 16:59

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.