26
\$\begingroup\$

In this question I will talk about programs as strings, this is strings of bytes, not characters. How your resultant program is rendered or displayed is not important to this challenge, only how it appears in memory matters.

A pristine program is a program \$S\$ that when run does not error, however it will error whenever a continuous substring of size \$n\$, where \$1\leq n < \left|S\right|\$, is removed.

A filthy program is the opposite, it is a program \$S\$ that when run does error, however whenever a continuous substring of size \$n\$, where \$1\leq n < \left|S\right|\$, is removed, it does not error.

For this challenge an error is non-empty output to STDERR.

Your challenge is to write a filthy program that uses as many unique bytes as possible. This means you will get one point for every unique byte that appears in your code with a larger score being better. The maximum score is thus 256.

\$\endgroup\$
  • \$\begingroup\$ Is it even possible to answer this in languages that involve brackets/parentheses? It would be possible to remove some substring from code so that there would be mismatched brackets. \$\endgroup\$ – JungHwan Min Jul 3 '18 at 14:49
  • \$\begingroup\$ @JungHwanMin If the language enforces balanced parentheses I would suspect that it would be impossible. \$\endgroup\$ – Sriotchilism O'Zaic Jul 3 '18 at 14:53
  • \$\begingroup\$ @CatWizard so a filthy program does not error when a continuous substring of characters (i.e. not continuous set of bytes) is removed, correct? \$\endgroup\$ – JungHwan Min Jul 3 '18 at 15:11
  • \$\begingroup\$ @JungHwanMin Sorry. It may or may not. We only care about continuous strings. \$\endgroup\$ – Sriotchilism O'Zaic Jul 3 '18 at 15:14
  • 3
    \$\begingroup\$ This script generates all the programs necessary to check \$\endgroup\$ – Conor O'Brien Jul 3 '18 at 22:49
16
\$\begingroup\$

Unary, 14 bytes

123456789ABCDE

This encodes the brainfuck program [, which errors due to unmatched brackets.

Removing bytes will result in >, <, +, -, ., , or the empty program, which are valid brainfuck programs.

\$\endgroup\$
  • \$\begingroup\$ This is the optimal solution, since any longer solution could be reduced to this solution, which errors \$\endgroup\$ – Jo King Jul 3 '18 at 23:17
  • \$\begingroup\$ This is also the only solution. \$\endgroup\$ – user202729 Jul 4 '18 at 8:52
13
\$\begingroup\$

R, 3 bytes

qrt

Try it online!

A name of an object is a valid program in R.

qrt is not the name of anything, so it returns an error.

q is the quit function

qr is the QR decomposition function

rt is the t distribution sampling function

qt is the t distribution inverse CDF

t is the transpose function

\$\endgroup\$
  • 2
    \$\begingroup\$ @pajonk but "r" is a continuous substring. Removing that leaves "qt" \$\endgroup\$ – Orphevs Jul 4 '18 at 10:16
  • 3
    \$\begingroup\$ There is exactly one filthy program in R of length 3, and this is it! (the only single char valid programs are 0-9cqtCDFIT, any program must therefore start with cm, qf, qr, qt, ts or Im. The length three possibilities are qrf,qrm,qrt,qts and tsd and only one of these is filthy (the others can't be extended either to make them filthy as there are no functions rm*,rf*,ts*,sd*) \$\endgroup\$ – JDL Jul 4 '18 at 13:14
  • \$\begingroup\$ @Orphevs my bad, misread the challenge. \$\endgroup\$ – pajonk Jul 5 '18 at 5:30
9
\$\begingroup\$

Jelly, 4 5 6 7 8 10 11 bytes

“a”;⁽PFð+µU

Try it online!

Verify it.

Tries to add a string with an integer.

Some of the possible subprograms:

“a” is a string literal.

“a is the same string literal.

is the empty string.

“a”; concatenates "a" with itself.

...too many to enumerate them all.

\$\endgroup\$
  • 1
    \$\begingroup\$ Fortunately Jelly still allows you to error. \$\endgroup\$ – user202729 Jul 4 '18 at 8:51
5
\$\begingroup\$

Python 2, 2 bytes

Unexpected character after line continuation character

\0

\ followed by any of 123456789 #
Try it online!

Invalid octal number

08

0 followed by any of 89
Try it online!

Unexpected Indent

 0

or \t followed by any of 123456789\
Try it online!

\$\endgroup\$
5
\$\begingroup\$

Polyglot, 3 bytes

1 2

Works in:

  • JavaScript
  • Ruby
  • R
  • Octave
  • GHCi
  • Julia

In JavaScript, throws SyntaxError: unexpected token: numeric literal or a similar error.

All other strings are valid numeric literals (1, 2, or 12).


In GHCi this throws

<interactive>:1:1: error:
    • Non type-variable argument in the constraint: Num (t1 -> t2)
      (Use FlexibleContexts to permit this)
    • When checking the inferred type
        it :: forall t1 t2. (Num t1, Num (t1 -> t2)) => t2

This is because it tries to apply 1 to 2 as a function, however it cannot. When any part of this is removed it simply becomes a numeric literal.

\$\endgroup\$
  • \$\begingroup\$ Polyglot: R, Octave, Ruby, the Pythons... \$\endgroup\$ – ngm Jul 3 '18 at 21:13
  • 1
    \$\begingroup\$ @ngm GHCi as well, however ` 2` errors in python. \$\endgroup\$ – Sriotchilism O'Zaic Jul 3 '18 at 21:29
  • \$\begingroup\$ I suspected that it was very generic. I've turned this into community wiki, so feel free to edit with all languages for which this works! \$\endgroup\$ – Arnauld Jul 3 '18 at 21:32
5
\$\begingroup\$

Python 2/3, 3 bytes

4\f2

OR

4\x0c2

Try it online!

In python "\f" is the same as "\x0c" and is a form feed character. This means that it indicates for a printer to go to the next line.

If a python expression starts or ends with \f, it is basically ignored so \f2 is a valid expression.

The 4 and 2 can be any number 0-9. However, for the first byte to be 0 is only valid in Python 2.7.15, as 02 was made a legal declaration of 2.

So the expression itself fails with a Syntax Error, because there are two numbers separated by a whitespace. However, any shortening either puts \f at the beginning or end, where it doesn't matter, or it creates 42 which is valid.

(It is worth noting that in IDLE this file opens looking like "42".)

Form feed explanation source: https://stackoverflow.com/a/26184126

\$\endgroup\$
  • 3
    \$\begingroup\$ This would be easier to understand if you used the actual code in the source without the \f. Here is a try it online link from which you can get a pre-formatted answer. \$\endgroup\$ – Sriotchilism O'Zaic Jul 3 '18 at 23:26
  • 1
    \$\begingroup\$ I have added it as a variant for clarification. Also, thank you for the suggestion of the link. \$\endgroup\$ – The Matt Jul 4 '18 at 0:07
4
\$\begingroup\$

Dyalog APL, 5 bytes (SBCS)

~≢0 1

Try it online! or test all the possible programs

There sure are better boring answers, but this is the best non-boring one I've found

SBCS is required as Dyalog Classic seems to always have output in STDERR, making it unusable.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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