| Bytes | Lang | Time | Link |
|---|---|---|---|
| 075 | Swift 6 | 250505T125932Z | macOSist |
| 519 | TSQL SQL Server 2016 | 230629T054407Z | youcantr |
| 025 | Factor | 230628T163018Z | noodle p |
| 049 | C gcc | 170531T154954Z | cleblanc |
| 017 | Arturo | 230628T040825Z | chunes |
| 021 | Flip | 230628T032921Z | user1180 |
| 003 | Thunno 2 | 230627T185817Z | The Thon |
| 025 | Nibbles | 230313T180704Z | xigoi |
| 004 | Vyxal | 230312T115840Z | The Thon |
| 032 | PowerShell Core | 201120T005312Z | Julian |
| 2012 | k | 170618T044952Z | zgrep |
| 035 | MUMPS | 201119T150417Z | Joã |
| 006 | Pyth | 200907T000105Z | Scott |
| 066 | Nim | 201117T185518Z | xigoi |
| 004 | 05AB1E | 201117T181251Z | Makonede |
| 006 | Husk | 201117T080310Z | Dominic |
| 010 | APL Dyalog Extended | 200904T073819Z | Razetime |
| 005 | Pip | 200904T070618Z | Razetime |
| 005 | Japt | 200904T085423Z | Shaggy |
| 079 | Common Lisp | 170617T215537Z | Renzo |
| 008 | Charcoal | 170531T174640Z | Neil |
| 008 | Jelly | 170531T144320Z | Jonathan |
| 044 | PowerShell | 170601T212325Z | colsw |
| 039 | Python 3.5 | 170531T142810Z | Rod |
| 052 | Python 3 | 170601T160733Z | nocturam |
| 057 | C | 170531T170937Z | MD XF |
| 004 | Pyke | 170601T124343Z | Blue |
| 068 | Java 8 | 170601T111520Z | Kevin Cr |
| 045 | Retina | 170531T171245Z | Neil |
| 013 | APL | 170531T233625Z | user7008 |
| 032 | QBIC | 170531T230343Z | steenber |
| 021 | Julia | 170531T223408Z | Julian W |
| 072 | JavaScript ES6 | 170531T161758Z | Rick Hit |
| 017 | Ruby | 170531T151656Z | Mark Tho |
| 038 | Aceto | 170531T165316Z | L3viatha |
| 6049 | Clojure | 170531T184730Z | NikoNyrh |
| 017 | Pyth | 170531T184405Z | Jim |
| 020 | Octave | 170531T142447Z | rahnema1 |
| 005 | MATL | 170531T180334Z | DJMcMayh |
| nan | Bash | 170531T174559Z | marcosm |
| 020 | V | 170531T173804Z | DJMcMayh |
| 033 | shortC | 170531T171906Z | MD XF |
| 003 | Ohm | 170531T164855Z | FrodCube |
| 004 | 05AB1E | 170531T143653Z | Riley |
| 078 | Lua | 170531T162925Z | Blab |
| 074 | JavaScript ES6 | 170531T143838Z | Shaggy |
| 120 | brainfuck | 170531T160915Z | Doorknob |
| 071 | C# | 170531T154330Z | TheLetha |
| 053 | PHP | 170531T155119Z | Titus |
| 014 | Japt | 170531T145944Z | Tom |
| 002 | GS2 | 170531T153218Z | Dennis |
| 035 | Mathematica | 170531T151402Z | LegionMa |
| 039 | Perl | 170531T150750Z | Grimmy |
| 032 | Haskell | 170531T144733Z | nimi |
| nan | 170531T145129Z | Brad Gil | |
| 008 | CJam | 170531T144656Z | Business |
| 042 | PHP | 170531T142951Z | Jör |
| 050 | R | 170531T142449Z | Giuseppe |
| 005 | Brachylog | 170531T142420Z | Fatalize |
Swift 6, 75 bytes
let f={""+Set((32...126).map{.init(UnicodeScalar($0))}).subtracting($0+"")}
T-SQL (SQL Server 2016), 519 bytes
with X as(select 32a,char(32)b union all select a+1,char(a+1)from X where a<126),E AS(SELECT n FROM(VALUES(0),(0),(0),(0),(0),(0),(0),(0),(0),(0))E(n)),F AS(SELECT a.n FROM E a,E b),G AS(SELECT a.n FROM F a,F b),T AS(SELECT ROW_NUMBER()OVER(ORDER BY(SELECT NULL))n FROM G),I as(SELECT ASCII(SUBSTRING(t,n,1))a FROM T JOIN(select @i as t)S on T.n<=LEN(S.t)where n=0),R as(select b from X where a not in(select a from I))select STUFF((SELECT''+b FROM R FOR XML PATH(''),TYPE).value('(./text())[1]','VARCHAR(MAX)'),1,1,'')
... but this assumes the input string is in @i, therefore a runnable script will look like:
declare @i varchar(101) = 'Test';
with X as(select 32a,char(32)b union all select a+1,char(a+1)from X where a<126),E AS(SELECT n FROM(VALUES(0),(0),(0),(0),(0),(0),(0),(0),(0),(0))E(n)),F AS(SELECT a.n FROM E a,E b),G AS(SELECT a.n FROM F a,F b),T AS(SELECT ROW_NUMBER()OVER(ORDER BY(SELECT NULL))n FROM G),I as(SELECT ASCII(SUBSTRING(t,n,1))a FROM T JOIN(select @i as t)S on T.n<=LEN(S.t)where n=0),R as(select b from X where a not in(select a from I))select STUFF((SELECT''+b FROM R FOR XML PATH(''),TYPE).value('(./text())[1]','VARCHAR(MAX)'),1,1,'')
How it works
Use CTEs to split the input string into individual characters on separate rows in a result set; use a recursive CTE to generate a result set having individual characters on separate rows for all characters between ASCII values 32 and 126; select all rows from the latter where characters are not found in the former; use STUFF with FOR XML PATH to aggregate those characters (in lieu of the STRING_AGG function, which only arrived in SQL Server 2017).
Legible version
declare @input varchar(101) = 'Test';
with X as (
select 32a, char(32)b
union all
select a+1, char(a+1) from X where a < 126
),
E(n) AS(
SELECT n FROM (VALUES(0),(0),(0),(0),(0),(0),(0),(0),(0),(0))E(n)
),
E2(n) AS(
SELECT a.n FROM E a, E b
),
E4(n) AS(
SELECT a.n FROM E2 a, E2 b
),
cteTally(n) AS(
SELECT ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) n
FROM E4
),
INPUT_STRING as (
SELECT ASCII( SUBSTRING(term, n, 1)) as [ASCII Code]
FROM cteTally t
JOIN (select @input as term) S on t.n <= LEN(S.term)
where n = 0
),
DATA_RESULTS as (
select b from X where a not in (select [ASCII Code] from INPUT_STRING)
)
select STUFF( (SELECT '' + b FROM DATA_RESULTS FOR XML PATH (''),TYPE).value('(./text())[1]','VARCHAR(MAX)'), 1, 1, '' )
;
Why?
Because I can.
Can it be shorter?
Almost certainly!
Factor, 26 25 bytes
-1 byte by using ∖ from math.unicode instead of diff, as suggested by @chunes
[ 32 126 [a,b] swap ∖ ]
TIO uses an old build of Factor; on the latest version, [a,b] from math.ranges has moved to [a..b] from ranges.
Explanation
| Code | Explanation | Stack |
|---|---|---|
[ ... ] |
Quotation (anonymous function) | "Hello!" |
32 126 [a,b] |
Inclusive range from 32 to 126 | "Hello!" T{ range f 32 95 1 } |
swap |
Swap so range is below input | T{ range f 32 95 1 } "Hello!" |
∖ |
Set difference | " \"#$%&'()*+,-./012..." |
This works because in Factor, a string is basically a list of codepoints, and all sequences are sets.
C (gcc), 75 72 70 68 50 49 bytes
Thanks to Peter -1 byte
i;f(s){for(i=31;++i<127;index(s,i)?:putchar(i));}
Arturo, 17 bytes
$=>[--@` `..`~`&]
Takes and returns a list of characters.
$=>[ ; a function where input is assigned to &
-- ; set difference
@ ; reify range
` `..`~` ; the range of printable ascii characters
& ; input
] ; end function
Flip, 21 bytes
' |D '+1<D:|g DX: #
ATO is not working right now, but I tested this locally. Contains a raw \x7F byte.
This would have been easier if I hadn't removed the J builtin, which generates an inclusive range.
Explanation
Push printable ASCII onto stack:
' Push space character
Loop body:
D Duplicate the current char
' \x7f Push 127
< Less than?
: If so, mirror & do the following:
D Duplicate TOS
1
+ Add by 1
| Mirror the IP
Setwise difference w/ input:
g Read 1 char from the input
D Duplicate
: Pop, is it nonzero? (i.e. not at EOF)
If so, mirror:
X Remove all occurences of
this char in the stack.
| Mirror the IP back
# When loop done, print entire stack as a string.
Terminate program.
Thunno 2, 3 bytes
kcḍ
Explanation
kcḍ # Implicit input
ḍ # Symmetric set difference with...
kc # ...all printable ASCII characters
# Implicit output
Nibbles, 2.5 bytes
--_"\n"
Unfortunately, the printable characters built-in in Nibbles also includes the newline, so we have to explicitly exclude it.
Explanation
--_"\n"
- List subtract
- list subtract
_ printable characters
"\n" newline
input
PowerShell Core, 39 32 bytes
$a=$args
' '..'~'|?{$_-cnotin$a}
Added splatting and case sensitivity
Inspired by colsw's answer
k, 20 12 bytes
-8 bytes thanks to coltim.
^[`c$32+!94]
Explanation:
32+!94 /list of int values of all printable characters
`c$ /turn into characters
^[ ] /partial function application of "except"
What except ^ does is remove all instances of each of element in the right/second argument from the left/first argument.
MUMPS, 35 bytes
r r,! f i=32:1:126 w:r'[$c(i) $c(i)
Explanation
- Assign input to
rand write a newline (!) - Loop from 32 to 126 and if r doesn't contain (
'[) the character representation of the ASCII value ($char(), can be shortened to$c()), write the that character representation. - You can attach conditionals to commands with a colon. So
w:1>0 "True"is the same asif 1>0 write "True"
Pyth, 7 6 bytes
.-srd\-srd\
.-- Subtract the second string from the first:
srd\Create a range from space char to the delete char- implicitly read input
05AB1E, 4 bytes
žQsм
žQsм # full program
м # remove...
s # implicit input...
м # from...
žQ # all ASCII characters
# implicit output
APL (Dyalog Extended), 14 10 bytes
⍞~⍨' '…'~'
-4 bytes from Adám!(inclusive range)
Explanation
' '…'~' range of chars in visible ASCII range
⍨ flip the arguments of the function on the left
⍞~ Get all characters not in input
Pip, 5 bytes
PADCa
Removes all chacracters in the input from a predefined variable.
Pip, 9 bytes
PARM(X^a)
Converts the characters of the input to regex, and removes the characters from the printable ASCII builtin.
Japt, 5 bytes
;EkU1
Try it - includes all test cases
Note that quotation marks in input strings cannot be escaped in Japt and %s must be escaped with %%.
Common Lisp, 79 bytes
(defun f(s)(dotimes(x 95)(let((y(code-char(+ 32 x))))(or(find y s)(princ y)))))
Very straightforward code.
Charcoal, 18 15 10 8 bytes
Fγ¿¬№θιι
Try it online! Link is to verbose version of code. Edit: Saved 3 bytes by ranging over characters instead of integers. Saved a further 5 bytes when I discovered the undocumented γ variable which holds the printable ASCII characters. Saved a further 2 bytes when @ASCII-only fixed predefined inputs in verbose mode (the answer is still valid as it stands, it's only the try it online link that wouldn't have worked at the time).
Jelly, 8 bytes
Really, 8 bytes? Please, tell me I missed something!
32r126Ọḟ
How?
32r126Ọḟ - Main link: list of characters s
32r126 - inclusive range from 32 to 126 = [32,33,...,125,126]
Ọ - cast ordinals to characters = list of printable characters
ḟ - filter discard if in s
Alternatively
“ ~‘r/Ọḟ - Main link
“ ~‘ - code-page indexes = [32,126]
r/ - reduce by inclusive range = [32,33,...,125,126]
Ọ - cast from ordinals to characters = list of printable characters
ḟ - filter discard if in s
Since this challenge a new atom which yields all printable ASCII characters, ØṖ, has been introduced making the following work for 3 bytes:
ØṖḟ
PowerShell, 44 Bytes
[char[]](32..126|?{$_-notin[char[]]"$args"})
creates an array of the numbers 32 through 126 (printable char codes)
finds the char codes not present in the input $args and then converts them back to a char array.
apparently the 1..5 -gt 3 trick doesn't work for -in or -notin, which would save a few bytes.
Python 3.5, 39 bytes
lambda n:{*map(chr,range(32,127))}-{*n}
Try it online!
Turns input into a set, and remove it from the set containing all ascii characters
Python 3, 52 bytes
I feel like there ought to be a shorter way to grab all the unicode characters than this set comprehension, but I haven't found it yet.
lambda s:''.join({chr(i+34)for i in range(93)}-set(s))
C, 57 bytes
i=32;f(char*s){for(;i<127;i++)!strchr(s,i)?putchar(i):0;}
How it works:
- Initially sets
ito 32, the ASCII character code for the space (the first printable ASCII character). - The function
ftakes a strings, the "input". - Loops, incrementing
iuntil it reaches~(126), the last printable ASCII character. !strchr(s,i)checks ifiis not ins. Ifiis not ins, printi. Otherwise, do nothing.
I'm sure this can be golfed.
Retina, 48 45 bytes
^
95$*~¶
+T`p`_p`(.)(?=\1)
s`(.)(?=.*\1)|¶.*
Try it online! Includes test cases. Works by prepending a line of 95 ~s, translating them into the printable ASCII characters, then deleting duplicate characters and the original input. Edit: Saved 3 bytes by matching the characters to be translated individually.
APL, 13 bytes
⍞~⍨⎕UCS31+⍳95
Straightforward:
31+⍳95 ⍝ A vector 32 .. 126
⎕UCS ⍝ as characters
~⍨ ⍝ without
⍞ ⍝ those read from character input.
QBIC, 32 bytes
[32,126|X=chr$(a)~instr(;,X)|\?X
Time to implement chr$ and instr in QBIC...
[32,126| Loop from 32 to 126
X=chr$(a) Make X$ to be the character with Ascii value a (a is our loop counter)
~instr(;,X) If our input string (read from cmd line) contains cjar X$
| THEN (empty, no-op)
\?X ELSE, print char X$
Julia, 21 bytes
s->setdiff(' ':'~',s)
JavaScript (ES6), 73 72 bytes
f=(s,i=95)=>i?f(s,i-1)+(s.includes(c=String.fromCharCode(i+31))?'':c):''
This builds the string recursively, excluding characters found in the input.
Snippet:
f=(s,i=95)=>i?f(s,i-1)+(s.includes(c=String.fromCharCode(i+31))?'':c):''
console.log(f('Hello, World!'));
console.log(f('Hi'));
console.log(f(''));
console.log(f(' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'));
Ruby, 23 18 17 bytes
->s{[*' '..?~]-s}
Uses a lambda function as per @sethrin's comments.
Previous versions:
[*' '..?~]-s.chars
(' '..'~').to_a-s.chars
Aceto, 38 bytes
cC|d
dXpc
=`I&
LM-1I
d@7F&
€92-
r4*2
Explanation
We first read the input string and explode it (€, put the characters on the stack). Next, we push the numbers 34 (94*2-) and 127 (27F1-). The second value is then removed from the stack and memorized (M):
M-1
7F
€92-
r4*2
We then first set a catch mark so we can jump back to this place, and then duplicate the number on the stack (the 34). We load the 126 from the quick memory and test for equality, in which case we exit:
X
=`
L
d@
Otherwise, we duplicate the value again, convert it to a character of that number and check whether that character is already on the stack (dcC). If it is, we mirror to the right side:
cC|
d
Otherwise, we duplicate the value and convert it to a character again, print that character, increment the value and raise an exception, jumping back to the catch mark.
d
pc
I&
If we mirrored, we just increment and raise an exception, too (I&).
Clojure, 60 or 49 bytes
#(apply str(sort(apply disj(set(map char(range 32 127)))%)))
These "apply"s are killing me :/ Oh, if returning a list is fine then this is a bit shorter.
#(sort(apply disj(set(map char(range 32 127)))%))
Pyth, 17 bytes
Vr32 127I!}CNzpCN
The naive approach.
Explanation:
Vr32 127I!}CNzpCN
Vr32 127 For N in [32, 127[
CN Get the ASCII character for the code N
I!} z If it is in the input string...
pCN ...then print it
Octave, 22 20 bytes
Thanks to @Luis Mendo saved 2 bytes.
@(s)setxor(32:'~',s)
Other answer:
@(s)setdiff(' ':'~',s)
MATL, 5 bytes
6Y2X~
Thanks to Luis Mendo for golfing 8 bytes off!
Explanation:
X~ % The symmetric set difference
6Y2 % Between all printable ASCII
% And the input string (implicit)
% Implicitly display
Symmetric set difference will give every element that is present in exactly one of the two input sets. (but not both) This will always give the right answer, since the input set will always be a subset of the second set (all printable ASCII).
Original version:
32:126tGom~)c
Explanation:
32:126 % Push the range 32-126
t % Duplicate it on the stack
G % Push the input
o % Convert it to character points
m % Is member (0 for each char that isn't in input, 1 for each char that is)
~ % Logical NOT
) % Take the truthy elements of this array from the previous array (All Printable ASCII)
c % Display as a string
Bash, 47 43 40 bytes
printf %x {32..126}|xxd -r -p|tr -d "$1"
Generates hexa range, inverts hex dump to char an removes characters present in first parameter.
V, 20 bytes
òiÎflax
òcH ¬ ~@"<
Hexdump:
00000000: f269 ce66 1b6c 6178 0af2 6348 20ac 207e .i.f.lax..cH . ~
00000010: 1b40 223c .@"<
shortC, 33 bytes
i;AOi=31;++i<'~';strchr(*@,i)?:Pi
Conversions made in this program:
A->int main(int argc, char **argv) {O->for(@->argvP->putchar- Auto-inserted closing
));}
The resulting program looks like:
i;int main(int argc, char **argv){for(i=31;++i<'~';strchr(*argv,i)?:putchar(i));}
Ohm, 3 bytes
α@─
Note: you can also enter your input as a string (example), but it fails for the empty input case.
05AB1E, 5 4 bytes
-1 thanks to Emigna
žQsK
žQ # Push all printable characters
s # Swap input to the top
K # Push a with no b's (remove input characters from all printable character)
Lua, 78 bytes
s=io.read()for i=32,126 do c=string.char(i)io.write(s:find(c,1,1)and""or c)end
JavaScript (ES6), 74 bytes
I'm sure there's a shorter way to do this!
s=>[...Array(95)].map((_,y)=>s.includes(c=String.fromCharCode(y+32))?"":c)
Try it
let f=
s=>[...Array(95)].map((_,y)=>s.includes(c=String.fromCharCode(y+32))?"":c)
oninput=_=>o.innerText=f(i.value).join``
o.innerText=f(i.value="Hello, World!").join``
<input id=i><pre id=o>
brainfuck, 120 bytes
+[+[>+<+<]>]>-[[>>]+[<<]>>-],[<+++++[>------<-]>-[>[>>]+[<<]>-]>[>>]<[-]<[-<<]>,]++++++++[->++++<]>[>[-<.>]<[->>+<<]>>+]
Wrapped:
+[+[>+<+<]>]>-[[>>]+[<<]>>-],[<+++++[>--
----<-]>-[>[>>]+[<<]>-]>[>>]<[-]<[-<<]>,
]++++++++[->++++<]>[>[-<.>]<[->>+<<]>>+]
Explained:
+[+[>+<+<]>]>- initialize what we will now consider cell 0 to 95
[[>>]+[<<]>>-] initialize cells 2 4 etc 95*2 to 1; end on cell 0 at 0
,[ main input loop (for each char of input)
<+++++[>------<-]>- subtract 31 from the input
[>[>>]+[<<]>-] lay a trail of (input minus 31) ones in the empty spaces
>[>>]<[-]<[-<<]> use the trail to clear the appropriate "print" flag
,] keep reading input until it ends
++++++++[->++++<]> initialize the cell directly before flag 1 to 32
[ we'll let the accumulator overflow; no harm done
>[-<.>] print the accumulator if the flag is still set
<[->>+<<]>>+ shift over the accumulator and increment it
]
C#, 74 71 bytes
using System.Linq;s=>new int[95].Select((n,i)=>(char)(i+32)).Except(s);
Old version with creating a range for 74 bytes:
using System.Linq;s=>Enumerable.Range(32,95).Select(n=>(char)n).Except(s);
PHP, 53 bytes
for($k=31;$k++<126;)~strstr($argn,$k)?:print chr($k);
# or
for($k=31;$k++<126;)echo~strstr($argn,$k)?"":chr($k);
Run as pipe with -r.
GS2, 2 bytes
ç7
How it works
(implicit) Push the sting of all characters in STDIN on the stack.
ç Push the string of all printable ASCII characters.
7 Perform symmetric set difference.
(implicit) Print the result to STDOUT.
Mathematica, 35 bytes
20~CharacterRange~126~Complement~#&
Anonymous function. Takes a list of characters as input and returns a list of characters as output.
Perl, 39 bytes
s!.*!"pack(c95,32..126)=~y/$_//dr"!ee
Run with perl -pe.
Haskell, 32 bytes
f x=[y|y<-[' '..'~'],all(/=y)x]
Boring library function for set difference:
Haskell, 31 bytes
import Data.List
([' '..'~']\\)
Perl 6, 29 bytes
{[~] keys (' '..'~')∖.comb}
Note that the result is random because Sets are unordered.
Expanded:
{
[~] # reduce using string concatenation
# (shorter than 「join '',」)
keys # get the keys from the Set object resulting from the following
(' '..'~') # Range of printable characters
∖ # Set minus (this is not \ )
.comb # split the input into individual characters
}
There is also an ASCII version of ∖ (-), but it would require a space before it so that it isn't parsed as a subroutine call.
CJam, 8 bytes
'␡,32>q^
Where ␡ is a literal delete character.
'␡, e# The range of all characters up to ~.
32> e# Slice it to be the range of all characters from space to ~.
q^ e# Symmetric set difference with the input.
PHP, 42 Bytes
Input as array
Output as string
<?=join(array_diff(range(" ","~"),$_GET));
PHP, 53 Bytes
Input as string
Output as string
<?=join(array_diff(range(" ","~"),str_split($argn)));
replace <?=join with print_r for an output as array
R, 50 bytes
function(s)intToUtf8(setdiff(32:126,utf8ToInt(s)))
returns an anonymous function. Converts the input string to integers, computes the set difference between the printable range and the input values, and then converts them back to a string and returns it.
Brachylog, 5 bytes
ẹ;Ṭ↔x
Explanation
ẹ Split the input string into a list of chars
;Ṭ↔x Exterminate the chars from the string Ṭ of printable ASCII chars