Filthy and Unique

26

2

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.

Post Rock Garf Hunter

Posted 2018-07-03T14:33:07.900

Reputation: 55 382

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. – JungHwan Min – 2018-07-03T14:49:24.157

@JungHwanMin If the language enforces balanced parentheses I would suspect that it would be impossible. – Post Rock Garf Hunter – 2018-07-03T14:53:39.123

@CatWizard so a filthy program does not error when a continuous substring of characters (i.e. not continuous set of bytes) is removed, correct? – JungHwan Min – 2018-07-03T15:11:51.707

@JungHwanMin Sorry. It may or may not. We only care about continuous strings. – Post Rock Garf Hunter – 2018-07-03T15:14:30.000

What's the intention of the first paragraph of the question ("this is strings of bytes, not characters")? Is it to say individual bytes have to be removable and the program should still work? For eg., if I used π in my program, does it have to work when individual bytes of it (0xcf and 0x80) are removed? – sundar - Reinstate Monica – 2018-07-03T20:10:31.617

@sundar The intention of the first paragraph is to make clear that it doesn't matter what characters your program encodes, only what is actually encoded. If you use π in your program you are using two bytes, it doesn't matter that they only display as one character under some encodings, they are separate bytes, and are treated no different than for example a% which is also two bytes. – Post Rock Garf Hunter – 2018-07-03T20:13:33.807

Does leading or trailing whitespace count towards the bytes? – ngm – 2018-07-03T20:31:45.463

@ngm Yes it does. – Post Rock Garf Hunter – 2018-07-03T20:34:00.480

"For this challenge an error is a non-empty output to STDERR". Compiler errors count as well, right? – Jakob – 2018-07-03T20:48:33.920

@Jakob Yes, both compiler errors and runtime errors both count. – Post Rock Garf Hunter – 2018-07-03T20:53:33.377

3This script generates all the programs necessary to check – Conor O'Brien – 2018-07-03T22:49:54.627

@ConorO'Brien maybe there is a way to do that with Bash on TIO to test them automatically? I don't know Bash or if there is a try and except construct. – dylnan – 2018-07-04T04:11:33.383

@dylnan Bash can check for exit code, but that won't work for languages which doesn't use exit code to indicate error. However if it's possible to do it natively it's often faster. – user202729 – 2018-07-04T08:58:21.940

Answers

19

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.

Dennis

Posted 2018-07-03T14:33:07.900

Reputation: 196 637

This is the optimal solution, since any longer solution could be reduced to this solution, which errors – Jo King – 2018-07-03T23:17:25.023

This is also the only solution. – user202729 – 2018-07-04T08:52:02.920

13

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

ngm

Posted 2018-07-03T14:33:07.900

Reputation: 3 974

2@pajonk but "r" is a continuous substring. Removing that leaves "qt" – Orphevs – 2018-07-04T10:16:59.663

3There 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*) – JDL – 2018-07-04T13:14:11.937

@Orphevs my bad, misread the challenge. – pajonk – 2018-07-05T05:30:42.010

10

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.

dylnan

Posted 2018-07-03T14:33:07.900

Reputation: 4 993

1Fortunately Jelly still allows you to error. – user202729 – 2018-07-04T08:51:29.143

6

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.

Arnauld

Posted 2018-07-03T14:33:07.900

Reputation: 111 334

Polyglot: R, Octave, Ruby, the Pythons... – ngm – 2018-07-03T21:13:53.447

1@ngm GHCi as well, however 2 errors in python. – Post Rock Garf Hunter – 2018-07-03T21:29:56.530

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! – Arnauld – 2018-07-03T21:32:18.923

5

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!

Rod

Posted 2018-07-03T14:33:07.900

Reputation: 17 588

5

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

The Matt

Posted 2018-07-03T14:33:07.900

Reputation: 271

3

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.

– Post Rock Garf Hunter – 2018-07-03T23:26:34.143

1I have added it as a variant for clarification. Also, thank you for the suggestion of the link. – The Matt – 2018-07-04T00:07:07.567

4

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.

dzaima

Posted 2018-07-03T14:33:07.900

Reputation: 19 048