95
\$\begingroup\$

Write a program or function that, when given a string, filters out as many distinct bytes as it can and returns the cleaned string. However, since your program hates them, none of these bytes can be present in your own code.

Your score will be the number of distinct bytes your program filters out from the input, with the higher the better. This is a max score of 255 (since your program has to be a minimum of one byte). The tiebreaker is the length of your code, with lower being better.

For example, if your program filters out the bytes 0123456789, it receives a score of 10, but your program itself cannot contain these bytes.

Rules

  • Bytes mean octets.
  • You also have the option to take input as a list of integers, with values ranging from 0 to 255. These correspond to the equivalent bytes.
    • Your output should be in the same form as your input
  • No reading your source code
  • Your code must be non-empty
  • Yes, I know there's going to be a Lenguage/Unary answer. But at least golf it please? ;)

Edit Rule:

  • You may choose to ignore a byte, for example if it is indistinguishable from the terminating byte for a string or for EOF. However, this means you can't use it in your submission, nor does it count for your score. If you choose to do so, your max score will be 254, but you don't have to handle that byte being in your input.
\$\endgroup\$
9
  • \$\begingroup\$ If the code accepts a Unicode string must we filter byte-by-byte - for example if the current highest voted entry (Japt by Luis felipe De jesus Munoz) entry is fed "Ŧ" (U+0166) should it yield "f" (U+0066)? Or is there a guarantee that we only receive the first 256 Unicode characters in the input? \$\endgroup\$ Feb 25, 2019 at 13:51
  • 1
    \$\begingroup\$ Is it OK if the function doesn't work if the string contains null bytes (\0)? As C uses null terminated strings, a function cannot know whether it's the end of the string or just a null byte. \$\endgroup\$
    – wastl
    Feb 25, 2019 at 15:18
  • 1
    \$\begingroup\$ seems to be just begging for an answer in brainfuck \$\endgroup\$
    – Jasen
    Feb 26, 2019 at 5:41
  • 1
    \$\begingroup\$ @cmaster For people who cannot see deleted posts: There are a couple of brainfuck attempts, both failing because they cannot distinguish a NUL byte from EOF. \$\endgroup\$ Mar 5, 2019 at 1:11
  • 3
    \$\begingroup\$ @ØrjanJohansen I've added a rule that can let you ignore a byte (for EOF purposes). This shouldn't be too abusable, since it also decreases your max score, and it makes the question more inclusive. \$\endgroup\$
    – Jo King
    Mar 5, 2019 at 5:06

36 Answers 36

68
\$\begingroup\$

Japt -P, score: 255 (2 bytes)

ff

f => filter, second f => everything but 'f'

Try it online!


Japt, score: 255 (2 bytes)

From @Shaggy

oo

o => remove everything but, second o => 'o'

Try it online!

\$\endgroup\$
4
  • 11
    \$\begingroup\$ The right language for the job :) \$\endgroup\$ Feb 25, 2019 at 12:06
  • 6
    \$\begingroup\$ oo would also work, without the -P flag. \$\endgroup\$
    – Shaggy
    Feb 25, 2019 at 12:15
  • 1
    \$\begingroup\$ Guys, we have a winner! \$\endgroup\$
    – Adám
    Feb 25, 2019 at 12:52
  • 1
    \$\begingroup\$ This is now the most upvoted Japt solution on the site. \$\endgroup\$
    – Shaggy
    Mar 11, 2019 at 17:08
39
\$\begingroup\$

Python 2, score 249, 1732 bytes

c="%c%%c%%%%c%%%%%%%%c"
ex=c==c
ee=c==""
exec"e=%x%%x"%ex%ex
exec"e%%%%%%%%=%x%%x%%%%x"%ee%ex%ee
exec"ee=%x%%x"%e%ee
exec"ee%%%%=%x%%x"%ex%e
exec"e=%x%%x"%ee%e
exec"ec=ex%cex"%e
exec"xe=ec%cec"%e
exec"xx=xe%cxe"%e
exec"xc=xx%cxx"%e
exec"ce=xc%cxc"%e
exec"cc=ce%cce"%e
exec"eee=xx%cec"%e
exec"cee=ce%cec"%e
exec"exe=ce%cex%%cxe"%e%e
exec"xxe=ce%cxx"%e
exec"cxe=ce%cex%%cxx"%e%e
exec"ece=ce%cec%%cxe%%%%cxx"%e%e%e
exec"xce=ce%cex%%cxe%%%%cxx%%%%%%%%cxc"%e%e%e%e
exec"cce=cc%cex%%cce"%e%e
exec"eex=cc%cex%%cec%%%%cce"%e%e%e
exec"xex=cc%cex%%cxe%%%%cce"%e%e%e
exec"cex=cc%cec%%cxe%%%%cce"%e%e%e
exec"exx=cc%cxx%%cce"%e%e
exec"xxx=cc%cex%%cxx%%%%cce"%e%e%e
exec"cxx=cc%cec%%cxx%%%%cce"%e%e%e
exec"ecx=cc%cxe%%cxx%%%%cce"%e%e%e
exec"xcx=cc%cec%%cxe%%%%cxx%%%%%%%%cce"%e%e%e%e
exec"ccx=cc%cex%%cec%%%%cxe%%%%%%%%cxx%%%%%%%%%%%%%%%%cce"%e%e%e%e%e
exec"eec=cc%cxc%%cce"%e%e
exec"xec=cc%cec%%cxc%%%%cce"%e%e%e
exec"cec=cc%cex%%cec%%%%cxc%%%%%%%%cce"%e%e%e%e
exec"exc=cc%cxe%%cxc%%%%cce"%e%e%e
exec"xxc=cc%cex%%cxe%%%%cxc%%%%%%%%cce"%e%e%e%e
exec"cxc=cc%cec%%cxe%%%%cxc%%%%%%%%cce"%e%e%e%e
exec"ecc=cc%cxx%%cxc%%%%cce"%e%e%e
exec"""x=""
"""
exec"x%c=c%%xex%%ecc%%xex%%eex"%e
exec"x%c=c%%cee%%cee%%ece%%cxx"%e
exec"x%c=c%%ccx%%xxx%%xcx%%xxe"%e
exec"x%c=c%%eex%%exx%%xec%%xxe"%e
exec"x%c=c%%xex%%cxc%%cce%%ecx"%e
exec"x%c=c%%xxe%%eex%%cxe%%cxe"%e
exec"x%c=c%%cex%%ccx%%xec%%ce"%e
exec"x%c=c%%eex%%ce%%xxx%%xcx"%e
exec"x%c=c%%ce%%eex%%ecc%%ece"%e
exec"x%c=c%%cec%%eec%%ecx%%xxx"%e
exec"x%c=c%%exc%%xxe%%cxe%%cxe"%e
cx="""eec
xec
xxx
xcx
exc
cee
cee
ece
cxx
ccx
xxx
xcx
xxe
xex
ce
cex
ccx
xec
ce
xex
ce
xxx
xcx
ce
xxx
xcx
eec
xxc
exc
xxe
cxe
xxx
cex
ce
xex
ce
xxx
xcx
cee
cee
cee
eee
xex
ecc
xex
eex
cee
xce
exe
cee
cee
cee
cxe"""
exec"exec%cx"%ce

Try it online!

Removes everything but exc%=" and newlines. The code generation is xsot's. I doubt it's optimized, so there are lots of bytes to save here!

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

Haskell, score 249 250, 1088 335 bytes

(!:)((=:):(!=))=(((!):(!):(!):(!):(!):(!):(!):(!):(!):(!):(:):(!):(!):(!):(!):(!):(!):(!):(!):(!):(!):(!):(!):(!):(!):(!):(!):(!):(!):(!):(!):(!):(!):(:):(!):(!):(!):(!):(!):(!):(:):(:):(!):(!):(!):(!):(!):(!):(!):(!):(!):(!):(!):(!):(!):(!):(!):(!):(:):(!):(!):(:):(=!))!!(=:))(=:)((!:)(!=))
(!:)(=:)=(=:)
(=:)!(!=)=(!=)
(=!)=(!):(=!)

Defines a function !: that takes a list of integers and filters out all except 10,33,40,41,58,61, the ASCII-codes of \n ! ( ) : =.

Try it online!

How it works: First let's rename the functions and parameters to sane names:

f (x:xs) = (listOfFunctions !! x) x (f xs)                   -- (!:)
f x = x

listOfFunctions = d:d:d:d:d:d:d:d:d:k:d:d ... : infiniteDs   -- inlined
infiniteDs = d : infiniteDs                                  -- (=!)

k      = (:)                                                 -- inlined
d x xs = xs                                                  -- (!)

The main idea is to have a list of two different functions (listOfFunctions), one to keep an element (k) and one to drop it (d). The list is indexed by the current element from the input list (x) and the function it picks determines whether to keep or drop the element. At index 0 we have d, because we want to drop 0s, the first k is at index 10, because we want to keep 10s (newlines). Both k and d take two parameters: x and the result of a recursive call with the rest of the list (xs). k prepends x to the recursice call and d just returns the recursive call.

The literal list of functions ends at index 61 (char =, the last k in the list) and is followed by an infinite number of d. This not only saves many explicit d, but also prevents us from having to end a finite list with [] which would require additional chars.

Edit: thanks to @Ørjan Johansen for +1 score and -753 bytes.

\$\endgroup\$
7
  • 1
    \$\begingroup\$ By putting functions in the list instead of Bools you can get rid of | for score 250, 335 bytes. Also defined a synonym for repeat (!) to shorten the list (drastically, since | was far larger than the second largest excluded character. \$\endgroup\$ Feb 26, 2019 at 2:33
  • \$\begingroup\$ Come to think of it, a function to abbreviate some of those long (!): sequences would probably also help. \$\endgroup\$ Feb 26, 2019 at 19:11
  • \$\begingroup\$ @ØrjanJohansen: yes, but a sublist must be finite, so you need a way to construct the empty list only with !():=. Extracting [] from an existing list, e.g. the input list, won't work because it has type [Int], but we need [a->[a]->[a]]. \$\endgroup\$
    – nimi
    Feb 26, 2019 at 19:47
  • \$\begingroup\$ Could you please explain how it works? ! is curry snd, and =! is a infinite list of these, but that's all I can understand from this. \$\endgroup\$
    – Michail
    Feb 26, 2019 at 21:39
  • 1
    \$\begingroup\$ @nimi I meant a function in addition to (=!), something like (!=)(=:)=(!):(!):(!):(!):(!):(=:) or (more high-level, can be passed ((!):) or a section of itself) (!)!=(=:)=(!)((!)((!)((!)(=:)))). Lots of options to tweak. Number of repetitions, what kind of second (or even third) argument if any, and even if it's more optimal for compression to use \n or ; (block lengths 10 22 6 16 2 vs. 33 6 16 1). \$\endgroup\$ Feb 27, 2019 at 1:59
21
\$\begingroup\$

JavaScript (ES6), score: 242 (142 bytes)

A rather naive approach using an array of bytes for I/O.

t=>t.filter(t=>'f'>'fffffffffffffffffffffffffffffffffffffffeeeffffeffffffffffffffeeffffffffffffffffffffffffffffefefffffffeeffeffefffffefe'[t])

Try it online!

How?

The 14 characters that are not filtered are '().=>[]efilrt. They are marked with an e in the lookup string. For characters above t (ASCII code 116) which are not defined in this string, 'f'>undefined is false.

\$\endgroup\$
7
  • 15
    \$\begingroup\$ I was hoping one of these would be exactly 144 bytes long. This deserves extra credit for being one gross solution. \$\endgroup\$ Feb 26, 2019 at 5:32
  • \$\begingroup\$ The description says "when given a string"... \$\endgroup\$
    – Yair Rand
    Feb 26, 2019 at 6:45
  • 2
    \$\begingroup\$ @YairRand And it also says "you also have the option to take input as a list of integers". \$\endgroup\$
    – Arnauld
    Feb 26, 2019 at 11:51
  • 1
    \$\begingroup\$ I think this solution is backwards - it sounds like ideally the only characters that should be output are the characters actually used in the code, while everything else is filtered out. The good news is that this solution can be quickly adopted to work that way, while shaving two bytes off: t=>t.filter(t=>'f'>'fffffffffffffffffffffffffffffffffffffffeeeffffeffffffffffffffeeffffffffffffffffffffffffffffefefffffffeeffeffefffffefe'[t]). Here's a TIO test statement: console.log(f([...Array(256).keys()]).map(c => String.fromCharCode(c))) \$\endgroup\$ Mar 2, 2019 at 1:58
  • 2
    \$\begingroup\$ @Arnauld I think you've scared off all the other decent JS contestants with your speedy supergolfs... \$\endgroup\$
    – user77406
    Mar 5, 2019 at 6:30
14
\$\begingroup\$

APL (Dyalog Unicode), score: 253, tiebreaker: 8 bytesSBCS

Anonymous tacit prefix function

∩∘'∩∘'''

Try it online!

 intersection of the argument

 and

'∩∘''' the three characters in the code (∩∘')

\$\endgroup\$
2
  • 5
    \$\begingroup\$ This looks vaguely like an emoticon for someone angrily holding up four fingers. \$\endgroup\$
    – Skyler
    Feb 26, 2019 at 20:04
  • 1
    \$\begingroup\$ @Skyler Oh well. \$\endgroup\$
    – Adám
    Feb 26, 2019 at 20:11
14
\$\begingroup\$

C (gcc), score 232 235 239 241 242, 260 407 352 249 243 249 bytes

fn(int*f,int*i,int*n,int**t){if(f==i)if(*t=n){}if((f==i)==('+'=='*')){if((*f==',')+(*f=='\'')+(*f=='(')+(*f==')')+(*f=='*')+(*f=='+')+(*f=='=')+(*f=='\\')+(*f=='f')+(*f=='i')+(*f=='n')+(*f=='t')+(*f=='{')+(*f=='}'))if(*n++=*f){}if(fn(++f,i,n,t)){}}}

Try it online!

A function taking a pointer to the beginning and end of an int array (where end is the first character not included), a pointer to a buffer and a pointer to another int pointer. It writes the result into the buffer and the end pointer of the result into the last pointer.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ In case it helps you, the challenge has been edited so that it is now permitted to ignore one particular byte value, say for NUL-terminated strings. It does reduce the score though. \$\endgroup\$ Mar 5, 2019 at 5:28
14
\$\begingroup\$

Regex, Score: 255, 2 bytes

\\

Matches the character \.

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ Which regex flavor is it? To my understanding this only matches the first char, but not all within the input. \$\endgroup\$
    – nimi
    Feb 27, 2019 at 16:19
  • \$\begingroup\$ @nimi Well, my link uses .NET, and there is no global flag for .NET regexes. \$\endgroup\$
    – Gymhgy
    Feb 27, 2019 at 16:36
13
\$\begingroup\$

Jelly, score 254 (4 bytes)

f⁾f⁾

Try it online!

⁾xy is shorthand for “xy” (a two-character string).

We filter the input string down to just the characters occurring in “f⁾”.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Heh, I had an answer prepared with f⁾⁾f but decided to ask the question about taking Unicode strings before posting. \$\endgroup\$ Feb 25, 2019 at 17:37
13
\$\begingroup\$

POSIX shell, score 249, 18 bytes

tr -cd \\\\\ cdrt-

Try it online!

Simple tr command that deletes all characters but -\cdrt and space. Four backslashes are needed because both the shell and the tr command use backslash escapes. The fifth backslash escapes the following space character.

If tr -cd was considered a programming language, one could write a single byte progam with score 255.

\$\endgroup\$
5
  • \$\begingroup\$ It is, I think. It's got regular expressions, which are pretty powerful. \$\endgroup\$
    – wizzwizz4
    Feb 25, 2019 at 18:05
  • 3
    \$\begingroup\$ @wizzwizz4 tr has character classes as used in regular expressions, but no full regular expressions themselves. \$\endgroup\$ Feb 25, 2019 at 22:57
  • \$\begingroup\$ I don't understand what the backslashes are for, here. I think it would work fine without them? \$\endgroup\$ Feb 26, 2019 at 2:17
  • 1
    \$\begingroup\$ @DavidConrad It does, but then it doesn’t preserve spaces. Then you need the 4 backslashes for a backslash. \$\endgroup\$
    – wizzwizz4
    Feb 26, 2019 at 7:11
  • 3
    \$\begingroup\$ I shaved off a byte, at the expense of POSIX-complience, with tr -cd \ cdrt\\-\ Try it online! \$\endgroup\$
    – wizzwizz4
    Feb 26, 2019 at 7:12
10
\$\begingroup\$

Ruby -p, score 248 (8 unique bytes / 483 bytes)

eval""<<11+11+11+1+1+1<<11+11+11+11+11+11+11+11+1+1+1+1+1+1+1<<11+11+11+11+1+1<<111+1+1+1+1+1<<111+1+1+1<<11+11+11<<11+11+11+1+1+1+1+1+1<<11+11+11+11+11+11+11+11+1+1+1+1+1+1<<11+11+11+11+11+11+11+11+11+1+1<<111+1+1+1+1+1+1+1<<11+11+11+11+11+11+11+11+1+1+1+1+1+1+1+1+1<<11+11+11+11+11+11+11+11+11+1+1+1+1+1+1+1+1+1<<11+11+11+11+1+1+1+1+1<<11+11+11+1<<11+11+11+1+1+1+1+1+1+1+1+1+1<<11+11+11+11+11+1+1+1+1+1<<11+11+11+1+1+1+1+1+1<<11+11+11+11<<11+11+11+1+1+1+1+1+1<<11+11+11+1+1+1+1+1+1

Try it online!

\$\endgroup\$
1
10
\$\begingroup\$

Python 2, Score 244 245 246, 13390 1575 bytes

Takes a list of integers

exec'%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c'%(111+1,111+1+1+1,11+11+11+11+11+11+11+11+11+1+1+1+1+1+1,11+11+11+11+11+11+11+11+11+1+1+1+1+1+1+1+1+1+1+1,111+1+1+1+1+1,11+11+11+11+11+11+11+11+1+1+1,111+1+1+1+1+1+1+1+1+1,11+11+1+1+1+1+1+1+1+1+1+1,11+11+11+11+11+11+11+11+11+1+1+1,11+11+11+11+11+11+11+11+11+11+1,111+1+1+1,11+11+1+1+1+1+1+1+1+1+1+1,111+1+1+1+1+1+1+1+1+1,11+11+1+1+1+1+1+1+1+1+1+1,11+11+11+11+11+11+11+11+11+1+1+1+1+1+1,11+11+11+11+11+11+11+11+11+1+1+1+1+1+1+1+1+1+1+1,11+11+1+1+1+1+1+1+1+1+1+1,11+11+11+11+11+11+11+11+11+1+1+1+1+1+1,11+11+11+11+11+11+11+11+11+1+1+1+1+1+1+1+1+1+1+1,111+1,111+1+1+1+1+1+1,111+1+1+1+1+1,11+11+11+1+1+1+1+1+1+1,11+11+11+1+1+1+1+1+1+1+1,11+11+11+11+11+11+11+11+11+1+1+1+1+1+1,11+11+11+11+11+11+11+11+11+1+1+1,11+11+1+1+1+1+1+1+1+1+1+1,111+1+1+1+1+1+1+1+1+1,11+11+1+1+1+1+1+1+1+1+1+1,11+11+11+11+11+11+11+11+11+1+1+1+1+1+1,11+11+11+11+11+11+11+11+11+1+1+1+1+1+1+1+1+1+1+1,11+11+1+1+1+1+1+1+1+1+1+1,11+11+11+11+11+11+11+11+11+1+1+1+1+1+1+1+1+1+1,11+11+11+11+11+11+11+11+1+1+1+1+1+1+1+1+1,111+1,11+11+11+1+1+1+1+1+1+1,11+11+11+11+11+11+11+11+11+11+1,111+1+1+1,11+11+11+11+11+11+11+11+11+1,11+11+11+1+1+1+1+1+1+1+1+1+1+1,11+11+11+1,11+11+11+11+11+11+11+11+11+1+1,111+1+1+1+1+1+1+1+1+1,11+11+11+11+11+11+11+11+1+1+1+1+1+1+1+1+1+1+1,11+11+11+1+1+1+1+1+1,11+11+11+1+1+1+1,11+11+11+1+1+1+1+1+1+1+1+1+1,11+11+11+1+1+1+1+1+1+1,11+11+11+1+1+1+1+1+1+1+1,11+11+11+11+1+1+1+1+1,11+11+11+1+1+1+1+1+1+1+1+1+1+1,11+11+11+1,11+11+11+1+1+1+1+1+1+1+1,11+11+11+11+11+11+11+11+1+1+1+1+1)

Try it online!

This evaluates to the following line of code:

print[x for x in input()if x in map(ord,"exc'%+()1,")]

Python 2 Score 248, \$ \sim 2^{52}\$ bytes

This answer is obviously a theoretical one. The structure is

exec'<2**51 times %>c<2**50 times %>c ... %%c%c'%<112 times -~>0%<114 times -~>0% ... %<41 times -~>0%<93 times -~>0

In theory this would execute the same as:

print[x for x in input()if x in map(ord,"exc'%-~0")]

Python 3, Score 240 241, 54 bytes

+1 thanks to Jonathan Allan.

lambda a:[i for i in a if i in b""" ":[]abdfilmnor"""]

Try it online!

\$\endgroup\$
1
10
\$\begingroup\$

Clean, score 247, 234 213 208 bytes

-5 bytes thanks to Ørjan Johansen

== =t
t['\'':t]=['\'': ==t]
t['\\':t]=['\\': ==t]
t[':':t]=[':': ==t]
t['[':t]=['[': ==t]
t[']':t]=[']': ==t]
t['t':t]=['t': ==t]
t['=':t]=['=': ==t]
t[' ':t]=[' ': ==t]
t['
':t]=['
': ==t]
t[tt:t]= ==t
t t=t

Try it online!

Uses a pattern-matching recursive function to remove characters. Doesnt even need StdEnv.

\$\endgroup\$
5
  • 2
    \$\begingroup\$ This can be directly translated to a Haskell function with 7 unique characters. Same score as my answer, but far less bytes (Try it online!). Nice! \$\endgroup\$
    – nimi
    Feb 25, 2019 at 21:43
  • \$\begingroup\$ @nimi That can use =\ instead of ===. \$\endgroup\$ Feb 26, 2019 at 1:08
  • \$\begingroup\$ I think you want to switch t and tt in the second last line. \$\endgroup\$ Feb 26, 2019 at 3:49
  • \$\begingroup\$ It saves bytes to rename == to t but keeping == as a synonym for it. \$\endgroup\$ Feb 26, 2019 at 3:55
  • \$\begingroup\$ @ØrjanJohansen Nice catch, thanks! \$\endgroup\$
    – Οurous
    Feb 26, 2019 at 4:00
10
\$\begingroup\$

Lenguage (with stty +brkint -ignbrk), score 255, 3890951 bytes

The program consists of 3890951 NUL bytes (making this one of the shortest Lenguage programs ever; 3890951 bytes is easily small enough to fit on my disk, so I actually ran this in a Lenguage interpreter). The OP wanted the Lenguage/Unary solution to be golfed, so here we go. (Note that Unary would be much longer because it requires the use of 0 rather than allowing the use of NUL.)

Note that Lenguage does not, despite what its documentation implies, act like brainfuck does; I/O works entirely differently (something that I noticed when testing this program). In particular, Lenguage refuses to take input from anything other than a terminal, so the bytes that are being filtered out are the raw bytes sent over the terminal connection (note also that as it's filtering out the raw bytes, you won't see the keys you type at all). In practice, this means that the program will absorb any sort of input sent to it except for the NUL byte (typically typed as Ctrl-@), which will be echoed literally (at which point, the vast majority of terminals will ignore it, as the NUL byte is the terminal equivalent of a NOP instruction). In order to verify that the program works, it's simplest to modify the Lenguage interpreter to output in decimal, leading to the echo being actually visible.

What happens at EOF? Well, if the terminal is sending a series of bytes, there's no way to send EOF; all 256 possible bytes are interpreted literally, and there's nothing else you can insert into the terminal stream. However, if you happen to be using an old-fashioned serial terminal, you can press the "break" button on your terminal to purposely send misencoded data, allowing for a 257th possible code; this "break" is the only plausible equivalent of an EOF, as it's sent out-of-band and indicates something other than valid data. If your terminal configuration has the "interrupt-on-break" flag set (and the Lenguage interpreter does not, as far as I can tell, alter that setting), sending the break signal will cause the Lenguage interpreter to crash, which conveniently acts as a way to implement the desired EOF behaviour. I'm not sure whether this is a default setting (because nobody actually uses serial terminals nowadays, it basically never comes up), so I mentioned it in the header as part of the specification of the language interpreter being used.

Explanation

  1110110101111100000111
001                       Initialise tape element 0 to -1
   110               111  While tape element 0 is nonzero:
      110   111              While tape element 0 is nonzero:
         101                    Read a byte from the terminal into tape element 0
               100           Output tape element 0
                  000        Add 1 to tape element 0

The inner loop will only exit when NUL is typed at the terminal; after this, we immediately echo the character typed (i.e. the NUL). Adding 1 at this point will ensure that tape element 0 is nonzero again, so the outer loop cannot exit at all (until a break input crashes the interpreter), and we'll fall back into the inner loop.

It's golfiest to use subtraction to enter the outer loop, but addition to continue looping around it; addition has a shorter encoding, but cannot appear at the start of the program (as the encoding would look like leading zeroes and thus be ignored).

\$\endgroup\$
3
  • \$\begingroup\$ Incidentally, I'm pretty sure I can run any Lenguage program < 4TB despite not having a disk that big. The interpreter doesn't care about files with holes in them. \$\endgroup\$
    – Joshua
    Mar 1, 2019 at 18:55
  • \$\begingroup\$ truncate isn't creating sparse files for me (maybe the filesystem doesn't support them?). However, as far as I can tell, the reference Lenguage interpreter reads the input file a line at a time (!), so if the program doesn't contain newline characters, a sufficiently long program will end up exhausting available memory. Of course, this could be fixed with a new interpreter. \$\endgroup\$
    – ais523
    Mar 5, 2019 at 3:29
  • \$\begingroup\$ Not truncate. Seek on a brand new file to one byte before the desired end and write a null byte. \$\endgroup\$
    – Joshua
    Mar 5, 2019 at 14:28
9
\$\begingroup\$

Perl 5 -p, score 251, 13 bytes

y/ycd\\\///cd

Try it online!

\$\endgroup\$
8
\$\begingroup\$

05AB1E, score: 252 253 ( 4  3 distinct bytes used; 8 bytes in total)

„ÃJ„„JJÃ

Try it online.

Explanation:

„ÃJ        # Push the String "ÃJ"
   „„J     # Push the string "„J"
      J    # Join them together: "ÃJ„J"
       Ã   # Only keep these three characters from the (implicit) input
           # (and output the result implicitly)

Note that the order of ÃJ and „J in the 2-char strings are important, because is also used for dictionary words, where every two characters is a dictionary word (except for a select few characters like letters, digits, -, and such). So „Jà would be 'a word' J, as well as a dictionary word à + the next character (in this case ), which apparently is the word "causing".

\$\endgroup\$
2
  • 8
    \$\begingroup\$ Crossed out 4 with spacing is still a crossed out 4 \$\endgroup\$
    – Jo King
    Feb 25, 2019 at 10:28
  • \$\begingroup\$ So as it stands, this is a tie? \$\endgroup\$ May 26, 2021 at 13:25
8
\$\begingroup\$

Perl 5, score 251 (5 distinct bytes, 8058 bytes total)

s<><<s<>e<><s^^^<<s^^^<<s^^^<<s^^^<<s^^^<<s^^^<<s^^^^s^^^<<s^^^<<s>><><<s>>><<s>>><<s>>>^s>>><<s>>><<s>>><<s>>><<s>>>^s>>><<s>>><e^s<^>e>ee<e^<see><>>>>^<^^<se^e^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^e^^^^^^^e^^>^^^^s^s^ss>^<^^^^s^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^s^^^^^^^^^^>^<^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^>^<^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^>>eeee^s<><<s<>e<><s^^^<<s^^^<<s^^^<<s^^^<<s^^^<<s^^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^es><>cdr through my converter.

\$\endgroup\$
8
\$\begingroup\$

Octave, Score 248 249 (50 bytes)

There had to be a better way... and there is!

@(a)a('l'=='a'==all('l'=='a'==(a==('@al()''=')')))

Try it online!

Filters out everything but @al()'=. The all function is superior over any, because it only uses two distinct bytes. Note that any(...) is equal to not(all(not(...))). So, we start with the program

@(a)a(~all(a~=('@al~()''=')'))

Instead of ~ (not) we can also write 0==. Of course, that would mean we have to filter out 0 as well. Instead, note that the following expression is also false (zero)

'l'=='a'

If MATLAB compatibility is not an issue, I can go to 47 bytes

@(a)a((l='l'=='a')==all(l==(a==('@al()''=')')))
\$\endgroup\$
7
\$\begingroup\$

Brachylog, score 249, 16 bytes

{∈"{∈\\\"&}ˢ"&}ˢ

Try it online!

Not entirely sure how this works with the rules, what with Brachylog having its own special code page and all, but I can still explain how it works:

{                Start of inline predicate.
 ∈"              Input is a member of the string literal containing:
   {∈            the opening bracket, the member-of character,
     \\\"        backslash, quote,
         &}      ampersand, the closing bracket,
           ˢ"    and the superscript s.
             &}  Unify the input to the inline predicate with the output from the inline predicate.
               ˢ Output everything from the input that made it through the inline predicate.
\$\endgroup\$
7
\$\begingroup\$

Whitespace, score: 253 (3 distinct bytes used, 97 bytes in total)

[N
S S N
_Create_Label_LOOP][S S S N
_Push_0][S N
S _Duplicate_0][T   N
T   S _Read_STDIN_as_character][T   T   T   _Retrieve][S N
S _Duplicate_input][S S S T S S T   N
_Push_9][T  S S T   _Subtract][N
T   S S N
_If_0_Jump_to_Label_PRINT][S N
S _Duplicate_input][S S S T S T S N
_Push_10][T S S T   _Subtract][N
T   S S N
_If_0_Jump_to_Label_PRINT][S N
S _Duplicate_input][S S S T S S S S S N
_Push_32][T S S T   _Subtract][N
T   S S N
_If_0_Jump_to_Label_PRINT][N
S N
N
_Jump_to_Label_LOOP][N
S S S N
_Create_Label_PRINT][T  N
S S _Print_character][N
S N
N
_Jump_to_Label_LOOP]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Try it online (with raw spaces, tabs and new-lines only). A nice bonus is that I can use this code to transform the highlighted code above to the raw Whitespace program (which I did in this TIO as example), for which I usually use Notepad++. :)

Explanation:

Pretty straight forward. Here the pseudo-code:

Loop indefinitely:
  Character c = STDIN as character
  if(c == SPACE or c == TAB or c == NEWLINE):
    Print c as character
  Go to the next iteration of the loop
\$\endgroup\$
6
\$\begingroup\$

C# (Visual C# Interactive Compiler), Score 245, 111 bytes

h=>h.Where(W=>W=='|'||W=='='||W=='>'||W=='h'||W=='e'||W=='r'||W=='W'||W=='\\'||W=='\''||W=='('||W==')'||W=='.')

Try it online!

C# (Visual C# Interactive Compiler), Score 243, 33 bytes

n=>n.Intersect("Iter\\\"c=>n().")

Naive solution using Intersect

Try it online!

\$\endgroup\$
6
\$\begingroup\$

Retina 0.8.2, 12 bytes, score: 250

[^]n\\\n[^]

Try it online! Filters out all characters except for newline, [, \, ], ^ and n. Although the characters [\]^ are consecutive, using a range would actually cost a byte and also reduce my score.

\$\endgroup\$
6
\$\begingroup\$

Japt, 249 score, 20 bytes

f"[ fq\"[\\\\\\]]" q

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ Luis managed to find the optimal solution but you could improve your score with oQ+"+oQ"Q or simply oo but that's just a variation on Luis' solution. \$\endgroup\$
    – Shaggy
    Feb 25, 2019 at 12:18
  • \$\begingroup\$ Haha, tbh I was rushing this one and ran out of time yesterday night, and imo any shorter and it's getting close to luis' solution :P \$\endgroup\$
    – ASCII-only
    Feb 25, 2019 at 22:49
5
\$\begingroup\$

Ruby -paF[^$_=F*'], score 250, 8 bytes

$_=$F*''

I'm not sure at all this is legal under the current site rules for command-line flags, since the "flag" here is sort of passing in code that includes forbidden bytes. The F flag defines an input separator regex consisting of all characters not in the code proper. The code proper sets the output to the concatenation of all input records.

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

Vyxal Dv, Score 254, 4 bytes

‛↔‛↔

Try it Online!

‛↔‛  # Two-char-string '↔‛'
   ↔ # Remove characters not in said string

This is valid because of the v flag, which takes input as Vyxal encoding.

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

PHP, score 234, 58 62 bytes

<?=preg_replace("_[^\"$(),;<=?[\]^\_\\\\aceglnpr]_","",$argn);

Run as pipe with -nF or try it online.

\$\endgroup\$
4
\$\begingroup\$

MATL, Score 252

t't''m)'m)

Try it online!

Explanation (for input input)

t         % Duplicate input. 
          % Stack: {'input', 'input'}
't''m)~'  % Push the string t'm)~ 
          % Stack: {'input', 'input', 't'm)~'}
m         % 'ismember' to filter
          % Stack: {'input', [0 0 0 0 1]}
)         % Index into input.
          % Stack: {'t'}
          % Implicit display.
\$\endgroup\$
4
\$\begingroup\$

brainfuck, Score: 248, 162 bytes

,[>---[----------->--<]>-[>->->->-->------->-->-------[<<]>-]>--->-->->--->------------->->-----------[<]<<[->>>->->->->->->->-<<<<<<<<<<]>>>[>]>[[>]<[->-<]>.>],]

Try it online!

Usually I don't answer my own questions, but people seem to have read my profle page, especially where it says If someone comments on a question "I wish there was a brainfuck solution", I feel obliged to provide one.

The bytes filtered out are -<>[],. and ignores the NUL byte, since it is indistinguishable from EOF. This is a bit longer than usual, since I'm deliberately avoiding using + to get a slightly better score. Even so, I might be able to golf the number generation part to save a few bytes.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Both the C and Lenguage submissions have already adapted pretty specifically to the need to distinguish NUL from EOF. Perhaps use a 16-bit BF with a different EOF convention? \$\endgroup\$ Mar 4, 2019 at 6:26
3
\$\begingroup\$

Pyth, score 249, 16 bytes

sf/"f/\"Tzs\\"Tz

Filters out every character except f, s, T, z, ", /, and \

Try it online!

\$\endgroup\$
3
\$\begingroup\$

K, score 246, 23 bytes

{x@&~x in"\"~ in@&{x}"}

{..} is a lambda with arg x

read as 'returns x at where not x in string'

String contains \"~ in@&{x} (the ten bytes used in the program)

\$\endgroup\$
3
\$\begingroup\$

sfk, score 239, 133 bytes

+xed -i -case ixixi x+x+x xexex xdxdx x-x-x xixix xcxcx xaxax xsxsx xbxbx xyxyx xtxtx x"x"x x\[x\[x x\]x\]x x\\x\\x "x x x" x[byte]xx

Try it online!

Performs replacements on the input (written as [delim][from][delim][to][delim]) changing all characters used in the program to themselves, which removes the character positions from consideration for input to the final replacement x[byte]xx which maps all bytes to the empty string.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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