15
\$\begingroup\$

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).

\$\endgroup\$
17
  • \$\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
    Aug 16, 2014 at 19:21
  • \$\begingroup\$ related but probably sufficiently different. \$\endgroup\$ Aug 16, 2014 at 19:23
  • \$\begingroup\$ @FUZxxl I've permitted punctuation marks but excluded underscores. \$\endgroup\$
    – abligh
    Aug 16, 2014 at 19:32
  • 1
    \$\begingroup\$ For the purposes here, are A and a considered different "characters"? \$\endgroup\$ 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\$ Aug 17, 2014 at 18:37

3 Answers 3

14
\$\begingroup\$

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:

PROGRAM S;{$H+}USES SYSUTILS;CONST P='PROGRAM S;{$H+}USES SYSUTILS;CONST P=';A='A';AA=''';';AAA='A=''';AAAA='''';AAAAA='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.';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.

Outputs program A.

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

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)

A

Cycles between A and N:

~>> echo "A" | rot13
N
~>> echo "A" | rot13 | rot13
A
\$\endgroup\$
4
  • \$\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
    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
    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
    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
    Aug 16, 2014 at 19:54
5
\$\begingroup\$

GolfScript, 13 bytes

1{\~\".~"}.~

The output is

-2{\~\".~"}.~

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.

\$\endgroup\$
4
  • \$\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
    Aug 18, 2014 at 16:42
  • 2
    \$\begingroup\$ Everything but 1 and 2 is punctuation. \$\endgroup\$
    – Dennis
    Aug 18, 2014 at 16:44
  • \$\begingroup\$ OK, the rules were changed since I last read them. \$\endgroup\$
    – isaacg
    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
    Aug 18, 2014 at 16:59

Your Answer

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

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