16
\$\begingroup\$

As the title says, you are to create a pristine program in as many languages as possible. A pristine program, taken from here, is:

Let's define a pristine program as a program that does not have any errors itself but will error if you modify it by removing any contiguous substring of \$N\$ characters, where \$1 \le N < \text{program length}\$.

For example, the three character Python 2 program

`8`

is a pristine program (thanks, Sp) because all the programs resulting from removing substrings of length 1 cause errors (syntax errors in fact, but any type of error will do):

8`
``
`8

and also all the programs resulting from removing substrings of length 2 cause errors:

`
`

If, for example, `8 had been a non-erroring program then `8` would not be pristine because all the results of substring removal must error.

You are to write, in as many languages as possible, a pristine program.

  • Your program must produce a non-empty output when unaltered.

    • This output can be anything you like, can vary depending on different inputs, or anything else, so long as, when run, unaltered and with no/empty input, it produces a non-empty output (note that 0, or your language's null value is non-empty).

    • The output may not be to STDERR (or your language's equivalent), as this would fall under the definition of an "erroring program" below.

    • The output does not have to consistent across languages, or when executed twice in the same language.

  • Your code must work in a minimum of two distinct languages and must be at least 2 bytes long

  • Different versions of a language do not count as different languages. Therefore, Python 2 and Python 3 are considered the same language.

  • Your program must be pristine in all languages used

  • An error is defined as anything that causes the program to either entirely fail to run or to terminate with a nonzero exit code after a finite amount of time.

  • This is , so the answer with the most languages wins

    • In case of a tie breaker, the longest solution, in bytes, wins

I would also be interested in proofs of impossibility for certain pairs/groups of languages. If you find a particularly interesting proof, please leave it in the comments (or, preferably, a link to the full write up), and I'll invite you to post as an answer so I can award it a bounty if I agree that its especially interesting. Please do not post these proofs unless I have said I will award it a bounty, I don't want all the answers to be filled by such proofs and actual answers be buried. Proofs posted without me asking you to will not be considered valid

\$\endgroup\$
11
  • \$\begingroup\$ Sandbox \$\endgroup\$ Commented Sep 30, 2020 at 12:22
  • \$\begingroup\$ Does a warning such as a PHP warning count 1. as an error? 2. if not, as an output? (PHP warnings when enabled are displayed in the output) \$\endgroup\$
    – Kaddath
    Commented Sep 30, 2020 at 12:22
  • \$\begingroup\$ @Kaddath I'll go by the original definition of pristine programs, and say that warnings (for all languages) don't count as errors. If the warnings are naturally piped to STDOUT (or nearest equivalent), then I think that counts as output \$\endgroup\$ Commented Sep 30, 2020 at 12:25
  • 2
    \$\begingroup\$ @user the proofs are completely subjective. I‘m not surprised that there‘s certain conditions where it becomes trivial, I‘m more interested in non-trivial examples (say Python, C and Java). Ultimately, the proof bit is 100% subjective, and is only there to provide a reward for people who may have decided to do it in a group of languages, which then they prove are impossible, especially if the group of languages is non-trivial to prove impossible \$\endgroup\$ Commented Sep 30, 2020 at 16:36
  • 1
    \$\begingroup\$ @Jonah I'll be both permissive and strict (to my own rules), and say, yes a newline is nonempty, as it outputs a specific character (even if we can't "see" that character). The same applies to a space character, and any other whitespace \$\endgroup\$ Commented Oct 1, 2020 at 1:01

2 Answers 2

7
\$\begingroup\$

6 languages

Bash, 4 bytes

echo

Try it online!

Zsh, 4 bytes

echo

Try it online!

fish, 4 bytes

echo

Try it online!

tcsh, 4 bytes

echo

Try it online!

ksh, 4 bytes

echo

Try it online!

J, 4 bytes

echo

Try it online!

Kicking things off with a boring one. If I understand the rules, I think it's legal though.

The shells are clear enough and output a newline. Removing any contiguous substring will result in "command not found".

In J, echo is a built in function, and prints its argument with a newline appended. J doesn't have 0-argument functions, so you have to call it with something. However, anything works, including the empty string '', which is the conventional choice for calling a function when the argument doesn't matter.

\$\endgroup\$
8
  • 1
    \$\begingroup\$ I'm not surprised that such a trivial solution exists, and, if I understand the TIO links correctly, this is a perfectly valid answer. I'd be interested to see how many languages this can be extended to though. From my understanding, a lot of the shell languages (zsh, etc.) are pretty similar to Bash, so it might be fairly easy to add more languages \$\endgroup\$ Commented Oct 1, 2020 at 1:19
  • 3
    \$\begingroup\$ You forgot the totally forgettable csh. \$\endgroup\$
    – Noodle9
    Commented Oct 1, 2020 at 12:36
  • 1
    \$\begingroup\$ @DomHastings I think that for PHP it requires a param and a ; I tried to elaborate and answer based on print and the required param caused me a problem (as it was not required in the other languages I wanted to use) \$\endgroup\$
    – Kaddath
    Commented Oct 1, 2020 at 13:55
  • 1
    \$\begingroup\$ Even Batch counts, since the actual output ("ECHO is on.") doesn't matter. \$\endgroup\$
    – Neil
    Commented Oct 3, 2020 at 18:23
  • 1
    \$\begingroup\$ I wonder if help would work in more languages/shells - it always has output and usually doesn't require a parameter. \$\endgroup\$
    – Miriam
    Commented Oct 6, 2020 at 18:56
1
\$\begingroup\$

3 languages, 5 bytes

Ruby

print

Python 2

print

Perl 5

print

2 languages, 20 bytes

Scala

System.out.println()

Javascript

System.out.println()

This does about the same thing that the answer by Jonah does, except because a lot less languages use print, it features 3 or 2 languages. Still felt like answering however.

These all print the empty string.

\$\endgroup\$
4
  • \$\begingroup\$ Isn't int() valid in python? \$\endgroup\$
    – pajonk
    Commented Feb 11, 2022 at 13:23
  • \$\begingroup\$ @pajonk you are right. I'll delete that since I have a new one to replace it with. \$\endgroup\$ Commented Feb 11, 2022 at 13:29
  • \$\begingroup\$ int is valid in python. Try it online!. And also perl. Try it online!. p is valid in ruby. Try it online! What implementation are you using for Javascript? I haven't seen one that has System.out.println() to begin with. \$\endgroup\$
    – Chris
    Commented May 18, 2022 at 2:43
  • 1
    \$\begingroup\$ System.out.println() is Java, not JavaScript \$\endgroup\$ Commented Feb 19, 2023 at 12:22

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