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\$
13
  • \$\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\$ Commented Sep 30, 2020 at 12:22
  • 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
  • 1
    \$\begingroup\$ @WeirdGlyphs Any default output that is not explicitly restricted in the challenge \$\endgroup\$ Commented Jan 24 at 10:05

4 Answers 4

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\$ 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\$ Commented Oct 1, 2020 at 13:55
  • 2
    \$\begingroup\$ Even Batch counts, since the actual output ("ECHO is on.") doesn't matter. \$\endgroup\$ Commented Oct 3, 2020 at 18:23
  • 2
    \$\begingroup\$ I wonder if help would work in more languages/shells - it always has output and usually doesn't require a parameter. \$\endgroup\$ 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\$
5
  • \$\begingroup\$ Isn't int() valid in python? \$\endgroup\$ 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
  • 1
    \$\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\$ Commented May 18, 2022 at 2:43
  • 2
    \$\begingroup\$ System.out.println() is Java, not JavaScript \$\endgroup\$ Commented Feb 19, 2023 at 12:22
  • \$\begingroup\$ @noodleperson Also, System.out.print() is valid, so I highly doubt that this is a valid answer. \$\endgroup\$ Commented Jan 23 at 12:56
0
\$\begingroup\$

2 languages, 2 bytes

jq

[] 

Running jq with the -n flag ("--null-input / -n: Don´t read any input at all. Instead, the filter is run once using null as the input.") which seems to be the reasonable way to use jq for this challenge.

Outputs []

Removing either character makes a syntax error. Removing both causes a different compilation error.

JavaScript (browser REPL)

[] 

Outputs []. Depending on the REPL, it might not actually be possible to make a program attempt to run with characters removed.

Comments

Ok, this seems like an interesting but very difficult challenge. My problem is I don't really know any languages other than JavaScript these days.

I tried to make something in JS/My-Basic or JS/SQLite but no luck.

Strangely JS and My-Basic often had opposite problems. My-Basic is fine assigning undefined variables to each other (a=b) but doesn't like random expressions (3+2).

But in general it seems very difficult to make anything which is more than a single keyword. Anything you add to make one language compile is by definition going to be superfluous in another. The best bet seems to be two languages which have very similar syntax in some way but which are considered separate enough for the challenge.

\$\endgroup\$
0
\$\begingroup\$

Alternative answer

It's a bit hard to tell whether this is valid or not, but maybe this works in F# and OCaml.

fun _->infinity

It's a lambda that you have to assign to something and run. I don't think it's possible to call a function without passing something, but the something is ignored, so I don't know if that counts as using input.

F# (.NET Core), 17 bytes

 fun _->infinity 

Try it online!

OCaml, 17 bytes

 fun _->infinity 

Try it online!

\$\endgroup\$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.