# Write a program that uses all printable non-alphanumeric ASCII symbols

In particular, use each of these symbols at least once in your source code:

! " # $% & ' () * + , - . / : ; < = > ? @ [ \ ] ^ _  { | } ~  Symbols inside comments, string literals, regexps (or any other kinds of literals etc.) don't count (but their delimiters such as /**/ or "" do count). The program should not perform any action. It just has to compile and do nothing when run. If for some reason some of the symbols cannot be used in the language of your choice, explain that rigorously (what and why must be excluded). Update: A few answers used symbols withing regular expressions. I'd consider this a bit problematic, it's the same thing as putting them into string literals or comments (that's why I put etc. in that requirement). Please try without this. I also updated the requirement above. Update: Shortest code wins (tagged as code-golf). As suggested, we'll most likely need some tie-breaker criteria. I suggest that if there is a tie, the winning one is the one in which the ASCII symbols appear as much ordered as possible. Formally: Filter out the first occurrence of each of the listed symbols from a program. This will result in a permutation on the listed symbols. The program with less inversion number of its permutation wins. Update: I'd be happy to see some/more solutions in regular/mainstream languages, such as C(++), Java, Scala, Haskell, etc. • Can we have a literals exception for characters that do not appear in any keyword, syntax or operator in a particular language? That is neither @% nor the backtick can appear in c except as part of a literal (in sufficiently new versions of c % can appear in digraphs). (and # only appears in preprocessor directives, but we'll just have to live with that)? That is, I'm asking for Matt's approach to be made explicitly legal. – dmckee --- ex-moderator kitten Nov 7 '12 at 21:26 • shortest code wins? i suspect there will need to be a tie-breaking criteria too – ardnew Nov 7 '12 at 22:52 • In Javascript, the characters #, @, and  are not legal outside of any sort of literal – Peter Olson Nov 8 '12 at 16:13 • This is basically a competition of "find a language that can use all of these characters as syntax". Pretty crappy code gold in my opinion – Earlz Nov 8 '12 at 16:34 • Yea I agree with @Earlz, I think it would be better if it had to do something useful, in the lease amount of code, that way people couldn't just fluff to get all the characters in but it wouldn't be ardnew's solution. Cause as it stands you can't get shorter then that, plus any language in which some of the characters are not valid outside of literals - as has been pointed out by several people - are instantly disqualified. Which means there are only a few not only acceptable answers but correct answers period. – Ryan Nov 8 '12 at 20:41 ## 21 Answers ## Brainf*ck, 32 characters !"#$%&'()*+.-/:;>=<?@[\]^_{|}~,


Prints a smiley face (if your console can output ASCII symbol 1)

Yay, a Branf*ck solution that beats Golfscript! :P

If you insist on no output, just exchange the + and . :

!"#$%&'()*.+-/:;>=<?@[\]^_{|}~,  • Hm... I'd rather say it does hide characters in comments, but oh well. – ceased to turn counterclockwis Nov 8 '12 at 14:17 • @leftaroundabout : They are not technically comments because you can't use them to comment out valid instructions. They are handled as whitespace. By the way, I agree with you that this is a shameless stretching of the rules. – vsz Nov 8 '12 at 15:54 • @vsz There's nothing wrong with bending the rules. – Gareth Nov 8 '12 at 17:18 • Inversion number of this solution is 24, so it's the winner according to the rules. I have some doubts about that, as ignoring characters is very close to comments, but I'd say it's my bad, I didn't think of this possibility when writing the question. – Petr Pudlák Nov 10 '12 at 10:18 • @BodoThiesen Indeed that's quite old, I guess that might also qualify for a winning solution, although this one is better, even though it stretches the rules a little. – Petr Pudlák Dec 5 '16 at 19:20 ## Perl, 32 chars no hiding symbols in comments, string literals, or regular expressions. uses all symbols precisely once. $<@"^[(\{_},)]/+-~%'?&|:!*.=>;#


### Description

i have tried to indicate operator precedence with indentation: the right-most expressions are evaluated before those to their left

        $ # scalar variable$ named 
<               # numeric less-than inequality <
@"            # array variable @ named "
#   (array evaluated in scalar context)
^                 # bitwise XOR ^
[(\{_},)]     # array reference []
#   containing array ()
#     containing reference \
#       to anonymous hash reference {}
#         with one key "_"
#           and no value (nothing following comma ,)
#             (reference evaluated in scalar context)
/               # numeric division /
+-~%'         # unary addition +
#   and unary negation -
#     and bitwise complement ~
#       on hash variable % named '
#         (hash evaluated in scalar context)
?                   # ternary conditional operator ?:
&|                # code reference variable & named |
:                   # ternary conditional operator ?:
! *.              # logical negation !
#   on typeglob variable * named .
#     (typeglob evaluated in scalar context)
=>                  # fat comma => for compound expression
#   (evaluates LHS as string, RHS is empty)
;                     # end of expression ;
#                     # start of comment #

• Correct me if I'm wrong, but did you just make a scalar called <@"^[(\{_},)]/+-~%'?&|:!*.=>? – Mr. Llama Nov 8 '12 at 17:25
• @GigaWatt no, this is a sequence of several different expressions. i will add a description of how it is evaluated – ardnew Nov 8 '12 at 18:37
• @GigaWatt: No; in Perl, the symbolic identifiers are all single characters. Of that sort of thing, I think this program only uses $, @", %', and *. (a scalar, array, hash, and typeglob, respectively), though it's awfully hard to be sure . . . – ruakh Nov 8 '12 at 18:42 • Either you're a genius, or any random byte sequence is a valid Perl program. Or both. – ugoren Nov 8 '12 at 20:37 • Although according to my own rules I had to award the Brainfuck solution, this one is my favorite (same size, but inversion number 279). – Petr Pudlák Nov 10 '12 at 10:22 ## Whitespace, 32 !"#$%&'()*+,-./:;<=>?@[\]^_{|}~


all non whitespace characters are ignored, so this is actually an empty program

• one could argue therefor that all non-whitespace characters are comments and this is invalid :) – NRGdallas Jan 11 '13 at 21:34

## Python 65

a=lambda x:0.
@a#
def _():{['"$?',]};a<a!=a+a%a&a^a-a*a|~a>a/a\  I used the characters ? and $ inside a string literal. These characters are not legal outside string literals or comments.

• This contains invalid syntax. Specifically, {['"$?',]} isn't valid, as it creates a dictionary with a key with no associated value. You can make it valid with two more characters like so: {['"$?',]:0} – Strigoides Nov 10 '12 at 14:47
• @Strigoides nope, it makes a set not a dict. but even if that was the case (dict key with no value) it runs, which was the requirement, not valid syntax. (you need python >= 2.7 for it to work) – Matt Nov 10 '12 at 18:33
• I see, I was using python 2.6 when I tested it. – Strigoides Nov 11 '12 at 10:11

# PHP, 32 chars

Probably a bit of a troll, this PHP program is also a QUINE, and uses all symbols in the exact order they are listed.

!"#$%&'()*+,-./:;<=>?@[\]^_{|}~  Executed from the command line, the output will simply be the contents of the file, as there is no <?php to invoke the interpretor. $ cat > a.php
!"#$%&'()*+,-./:;<=>?@[\]^_{|}~$ php a.php
!"#$%&'()*+,-./:;<=>?@[\]^_{|}~  • IMHO this violates Symbols inside comments, string literals, regexps (or any other kinds of literals etc.) don't count, as the whole program is a single literal. – Petr Pudlák Nov 8 '12 at 17:10 • Also, the program required by the task should output nothing, and there is only one quine which outputs nothing. – Paŭlo Ebermann Dec 8 '16 at 21:15 • It doesn't even get parsed by PHP so this is pretty much invalid – Rob May 28 '18 at 12:25 • @RobQuist of course it gets parsed, it's busy hunting that elusive T_OPEN_TAG token right til the bitter end – Leigh May 29 '18 at 10:11 # Perl 6 (43 chars) Let's define a infix operator with a rather unusual name: sub infix:<!"#$%&'()*+,-./:;=?@[]^_´\|~>{}


It's not a literal nor a literal in a RE or anything hidden in a comment. You don't believe me? Running the following program will output "2":

sub infix:<!"#$%&'()*+,-./:;=?@[]^_´\|~>($a, $b){$a + $b } say 1 !"#$%&'()*+,-./:;=?@[]^_´\|~ 1;


But I'm quite sure you nitpickers will extend the rules further to exclude redefinition of the language itself to make us perl lubbers unhappy. :(

• I'd say this is ok, using symbols in an identifier seems reasonable. – Petr Pudlák Nov 8 '12 at 5:28

a@""#%&*+/?^b|a'<-a!!0=(\_->ab[]);main=do{print$1}  We can make this a bit shorter ## 45 a'@""#%&*+/?!<|^b=(\_->1b[]);main=do{main}  however this program doesn't terminate, and uses more characters ('!','<','|') in the newly-defined infix. # k (33 chars) Very easy in k. Unfortunately " must be paired. (@:'!""#$%&*+-\./;<=>?^_{}[]|,~)


{!""$%&()*+,-./<=>?@[\]^_|~};:'#  " has to be paired. It took a bit of trial and error to get it to output nothing - most other positions of the :' result in some output. ## J, 33 characters ''&][?!"$>{}:<;,|^~*/\%+-@.#(=_)


' needs to be doubled to avoid syntax errors.

My first answer was missing some symbols.

## C, 48 chars

Kind of cheating.

#define _ ~''*+,-./:<=>?[]|\
@%^$&! main(){"";}  • Definitely pushing the bounds of "cheating" as most of them appear in an uncalled macro. How about #define Q(_) "##_##" ... char*c=Q(~''*+,-./:<=>?[]|\);. Nothing in a string, it just gets converted to one... It would be longer, of course. – dmckee --- ex-moderator kitten Nov 8 '12 at 15:49 • @dmckee, I don't think your suggestion is more honest than mine. In both cases, the problematic characters don't end up in code. I could move most of them to code (as I did with "";), but $@ and backtick seem hopeless. – ugoren Nov 8 '12 at 16:06
• No doubt about it, mine is also foul, underhanded and sneaky. But it's fun, too. – dmckee --- ex-moderator kitten Nov 8 '12 at 16:20
• @dmckee, fun is what it's about. BTW, you need #define Q(_) #_. The preprocessor would treat "##_##" as a string literal. – ugoren Nov 8 '12 at 21:32

# Postscript - 32 chars

{!"#$&'()*+,-./:;=<>?@[\]^_|~}%  Results in an object on the stack, but otherwise has no effects. Postscript allows almost any char in an identifier except for <>()[]{}/ which are special syntax forms and % which introduces a comment. The program is tokenized as { % start a procedure object !"#$&'             % an identifier
()                 % an empty string
*+,-.              % an identifier
/:;=               % a symbol
<>                 % an empty hex string
?@                 % an identifier
[\]                % an array
^_~|              % an identifier
}                  % close the procedure object
%                  % a comment


## C# (91 characters)

#define a
class a{static int @Main(){return(char)1.1*""[0]/1%1-1+1!=1?1:~1^1>>1<<1&1+'\0';}}


As far as I know, The $character is not a valid character outside string literals, so I didn't use it in my answer. EDIT : Thanks to Peter Taylor, I shortened the code. • #if A...#endif is shorter than #region...#endregion. And "x"[0]+ is shorter than [System.STAThread]. – Peter Taylor Nov 8 '12 at 18:13 ## PowerShell (52 characters) $_+=(@(1.1,1)[0]-1)*1/1%'1'::ToInt|&{!"">~\1}<#^#>;


I had to put the ^ character as a string literal because as far as I know, the ^ character is not a legal PowerShell character outside string literals. Correct me if I am wrong.

The only way I have found to fit in the : character is to use the :: operator to make a call to a static method.

### Scheme, 41 characters

(define !$%&*+,-./:<=>?@[\]^_{|}~ "#'");  This takes advantage of Scheme's incredible tolerance for characters in variable names. In this program I create a variable with the name !$%&*+,-./:<=>?@[]^_{|}~ which Scheme happily accepts.

# Tcl 37 chars

set {!#$%&'()*+,-./:<=>?@[]^\_|~} ""  Defines a variable !#$%&'()*+,-./:<=>?@[]^\_|~ with an empty string

# C: 83 56 characters

#undef a
_;main($){$/=-+~!0|0^0%1,1<.0>0?'':*&"@"[0];}\


At-signs and backticks are not a part of the allowed C-syntax, so I have put them between quotation marks.

• Why the parenthesis in (b)? It's strange syntax and a waster of characters. – ugoren Apr 21 '13 at 12:45
• If you use the struct for the dot, 0.0 is much shorter. – ugoren Apr 21 '13 at 12:46
• How could I not think of that (0.0)? The parenthesis is a leftover from when they actually saved one character, but now they are indeed unnecessary. Thanks @ugoren! – Fors Apr 21 '13 at 16:09
• I think main(_,$) will save a character. – ugoren Apr 22 '13 at 11:18 • And with gcc, you can write x?:y, but it isn't standard C. – ugoren Apr 22 '13 at 11:22 ### Common Lisp, 33 characters #+()'|!"$%&*,-./:;<=>?@[\]^_{}~|


The main part of the above evaluates (or rather, would evaluate if not for the #+() in front of it) to the symbol named:

!#$%&()*+,-./:;<=>?@[\]^_{}~  The #+() is to avoid output. I'm not sure if the |foo| syntax for symbols counts as a literal, but symbols are used as variable/function names in Common Lisp, and there are a few answers already using the necessary characters in those. Smalltalk (Squeak 4.x dialect) 38 chars Implement this method in Object, the syntax is valid if Preferences Allow underscore assignment (which is the default setting) %&*+/<=>?@\!~y""^Z_([:z|{#'',$;-y}]).


declare Z as global var in pop-up menu if interactive

Explanations:

• %&*+/<=>?@!~ is a binary selector (an operator)
• y is the parameter (the operand)
• "" is an empty comment
• ^ means return
• Z is a global variable
• _ is an assignment
• () delimits a sub-expression
• [:z|] delimits a block of code with one parameter z
• {} delimits an Array
• #'' is a Symbol literal made of an empty String (first element of the Array)
• , is a binary message sent to above Symbol
• $ is a Character literal used as argument of above message • ; is for chaining a second message sent to the same Symbol receiver #'' • the second message is - • y is used as the second message argument • . is for separating next instruction (here it's a final period) Damn, who said Smalltalk was readable? Note that I didn't cheat, the only non valid character  is put into a literal Character. EDIT see below, this was a false assertion (at least in Squeak) But we can make it down to 34 chars with this trick %&*+,-/<=>?@\!~|y""^[{#(:_;$')}].


This time:

• #() delimits a literal Array
• which contains 4 literal Symbols : _ ;  and 1 literal Character $' Strictly speaking, we can consider this as cheating... It's not a literal String, but it is still a non empty literal... I still have to double comment quote "" (unless I make a literal Character with it$", but then I need to double the String quote '')
I still have to use a letter for the parameter (_ is not accepted even if we set Preferences allow underscore in selector to true).

What is nice is that we can even run the method, for example send the message to 1 with argument 2:

1%&*+,-/<=>?@\!~|2


EDIT Finally in 35 chars without cheating

!%&*+,-/<=>?@y""^[:x_|#()~$';\{}].  Notes: • Preferences allow underscore in selector enable using a block parameter named x_ •  is a valid character for binary selector contrarily to what I said • I also use$' to avoid doubling a quote

a=new(setClass("a",representation(b="list")));a@b=list(c_d=1:2);if(1!='\t'&.1%*%1^1>a@b$c[1]/1|F){~<-?}#  Clearly the longest submission, but to be able to use symbols @ and $ in R, we need to create an object that has slots (indexed using @) and named elements (indexed using $). The shortest solution I could think of was to create a new class of object (a=new(setClass("a",representation(b="list")))), which takes its toll. Otherwise, appart from the classics that don't need explanations (such as !=, # or 1:2), ~<-?  creates a new operator that does the same as operator ? (i. e. it calls the help page of the element it precedes). %*% computes the inner product of two matrices (here of 1^1 and .1). Symbol _ does nothing (AFAIK) in R but is routinely used in variable or function names, as it is the case here. ## TI-Basic, 36 :End:#$%&'()*+.-/;>=<?@[\]^_{|}~,!"

• This is not valid because the begin quote is often used for comments. – Tyzoid Dec 29 '13 at 22:19
• @Tyzoid I moved it to the end. – Timtech Dec 30 '13 at 11:15
• End ends a loop statement, not the program. I think you meant Return. – lirtosiast Jun 8 '15 at 1:34