Skip to main content
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

Exploit comment symbols

A simple way to create a two-language polyglot is to have the code divided in two parts as follows:

  1. The first part does the actual work in language A, is harmless in language B (no errors), and ends in a language-A comment symbol, which hides the second part to language A.
  2. The second part does the actual work in language B.

Thus

  • Language A sees the first part, which does the job, and then a comment.
  • Language B sees a useless first part and then the second part, which does the job.

The only difficult part here is finding a set of statements (first part) that do the job in language A while not giving errors in language B. Some suggestions for this:

  • Most stack-based languages allow displaying only the top of the stack at the end of the program (sometimes this is even default, as in 05AB1E).
  • Some languages ignore undefined statements (for example Golfscript).

A simple example that uses these guidelines can be found herehere. Languages A and B are MATL and 05AB1E respectively.

Exploit comment symbols

A simple way to create a two-language polyglot is to have the code divided in two parts as follows:

  1. The first part does the actual work in language A, is harmless in language B (no errors), and ends in a language-A comment symbol, which hides the second part to language A.
  2. The second part does the actual work in language B.

Thus

  • Language A sees the first part, which does the job, and then a comment.
  • Language B sees a useless first part and then the second part, which does the job.

The only difficult part here is finding a set of statements (first part) that do the job in language A while not giving errors in language B. Some suggestions for this:

  • Most stack-based languages allow displaying only the top of the stack at the end of the program (sometimes this is even default, as in 05AB1E).
  • Some languages ignore undefined statements (for example Golfscript).

A simple example that uses these guidelines can be found here. Languages A and B are MATL and 05AB1E respectively.

Exploit comment symbols

A simple way to create a two-language polyglot is to have the code divided in two parts as follows:

  1. The first part does the actual work in language A, is harmless in language B (no errors), and ends in a language-A comment symbol, which hides the second part to language A.
  2. The second part does the actual work in language B.

Thus

  • Language A sees the first part, which does the job, and then a comment.
  • Language B sees a useless first part and then the second part, which does the job.

The only difficult part here is finding a set of statements (first part) that do the job in language A while not giving errors in language B. Some suggestions for this:

  • Most stack-based languages allow displaying only the top of the stack at the end of the program (sometimes this is even default, as in 05AB1E).
  • Some languages ignore undefined statements (for example Golfscript).

A simple example that uses these guidelines can be found here. Languages A and B are MATL and 05AB1E respectively.

added 54 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

Exploit comment symbols

A simple way to create a two-language polyglot in is to have the code divided in two parts as follows:

  1. The first part does the actual work in language A, is harmless in language B (no errors), and ends in a language-A comment symbol, which hides the second part to language A.
  2. The second part does the actual work in language B.

Thus

  • TheLanguage A sees the first part, which does the actual work in language A, is harmless in language B (no errors)job, and ends inthen a language-A comment symbol, which hides the second part to language A.
  • TheLanguage B sees a useless first part and then the second part, which does the actual worh in language Bjob.

So language A sees the first part, which does the job, and then a comment. Language B sees a useless first part and then the second part that does the job.

The only difficult part here is finding a set of statements (first part) that do the job in language A while not giving errors in language B. Some ideassuggestions for this are:

  • Most stack-based languages allow displaying only the top of the stack at the end of the program (sometimes this is even default, as in 05AB1E).
  • Some languages ignore undefined statements (for example Golfscript).

See aA simple example that uses these guidelines can be found here. Languages A and B are MATL and 05AB1E respectively.

Exploit comment symbols

A simple way to create a two-language polyglot in is to have the code divided in two parts as follows:

  • The first part does the actual work in language A, is harmless in language B (no errors), and ends in a language-A comment symbol, which hides the second part to language A
  • The second part does the actual worh in language B.

So language A sees the first part, which does the job, and then a comment. Language B sees a useless first part and then the second part that does the job.

The only difficult part here is finding a set of statements (first part) that do the job in language A while not giving errors in language B. Some ideas for this are:

  • Most stack-based languages allow displaying only the top of the stack at the end of the program (sometimes this is even default, as in 05AB1E)
  • Some languages ignore undefined statements (for example Golfscript).

See a simple example here. Languages A and B are MATL and 05AB1E respectively

Exploit comment symbols

A simple way to create a two-language polyglot is to have the code divided in two parts as follows:

  1. The first part does the actual work in language A, is harmless in language B (no errors), and ends in a language-A comment symbol, which hides the second part to language A.
  2. The second part does the actual work in language B.

Thus

  • Language A sees the first part, which does the job, and then a comment.
  • Language B sees a useless first part and then the second part, which does the job.

The only difficult part here is finding a set of statements (first part) that do the job in language A while not giving errors in language B. Some suggestions for this:

  • Most stack-based languages allow displaying only the top of the stack at the end of the program (sometimes this is even default, as in 05AB1E).
  • Some languages ignore undefined statements (for example Golfscript).

A simple example that uses these guidelines can be found here. Languages A and B are MATL and 05AB1E respectively.

Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

Exploit comment symbols

A simple way to create a two-language polyglot in is to have the code divided in two parts as follows:

  • The first part does the actual work in language A, is harmless in language B (no errors), and ends in a language-A comment symbol, which hides the second part to language A
  • The second part does the actual worh in language B.

So language A sees the first part, which does the job, and then a comment. Language B sees a useless first part and then the second part that does the job.

The only difficult part here is finding a set of statements (first part) that do the job in language A while not giving errors in language B. Some ideas for this are:

  • Most stack-based languages allow displaying only the top of the stack at the end of the program (sometimes this is even default, as in 05AB1E)
  • Some languages ignore undefined statements (for example Golfscript).

See a simple example here. Languages A and B are MATL and 05AB1E respectively