Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The ASCII characters from decimal code 33 to 126 are:


Notice that in most fonts, 25 of these characters have "holes" in them: (a genus greater than 0 you might say)


The other 68 "unholed" characters are:


Your task is to write the shortest program possible using only the unholed characters that outputs each of the holed characters exactly once in any order.

Since Space, Tab and newlines (Line Feed and/or Carriage Return) are empty space they may appear in your program or its output. They still count towards the number of characters. Other ASCII characters may not be used (and certainly not non-ASCII characters).


  • You do not have to use all of the unholed characters nor only one of each.
  • The output may not contain unholed characters.
  • The Whitespace language may be used.
  • Output should go to stdout or can go to a file. There should be no input.

Bonus: Just for fun, try printing all the unholed characters using the holed characters. I'm skeptical that it can be done in an existing language.

share|improve this question
+1 for the title. We do love stuff like this. – Jacob Jul 29 '14 at 7:35
Where is the Perl solution?! – Pierre Arlaud Jul 29 '14 at 9:48
Well, no solution in Haskell or C; if it's a program you want, then you need to spell main. – Rhymoid Jul 29 '14 at 10:22
Bonus can be done using whitespace. – Joshua Jul 29 '14 at 19:50
How did no one ever notice that I forgot ~?? – Helka Homba Mar 13 '15 at 4:50

14 Answers 14

up vote 18 down vote accepted

Pyth, 43 35 characters


Try it here.

Prints the characters in order except that 9 is at the beginning, newline separated.

String contains all characters 7 greater than the ones needed, except that 9 would become @, so it is special cased. Algorithm thanks to @Howard.


tT                print(10-1)                T=10, t(x)=x-1 if x is an int.
Fk"<string>"      for k in "<string>":
C-Ck7             print(chr(ord(k)-7))       Note that C is overloaded as ord and chr.
share|improve this answer

GolfScript, 37 36 characters

[":=<?)-/! YX[]VIHKx{}|~vih"{25^}/]+

Try the code here.

The string contains the forbidden characters xor'ed with 25. Fortunately all characters are mapped to valid ones.

share|improve this answer

Brainfuck 119

share|improve this answer
uh, the -- at the start... Are you cycling back to 254 on the initial register there? – WallyWest Jul 29 '14 at 6:43
Yup :) Makes the loop to 36 shorter (in order to get to 35) – Teun Pronk Jul 29 '14 at 6:45
Well, it certainly beats my 275... well done... – WallyWest Jul 29 '14 at 7:03
@Calvin's Hobbies I'm fairly certain no input is allowed, sorry. OP might want to clarify, though. – isaacg Jul 29 '14 at 7:07
@isaacg I know, thats why my main code doesnt take input and the last example isn't a serious one :) – Teun Pronk Jul 29 '14 at 7:08

Bonus - dc, 179 characters

Oh good, another restricted character set challenge where P is allowed.


Since dc is apparently obscure enough to require explaining (strange to me considering the weird stuff around here!) here's an overview:

It's primarily an RPN calculator with arbitrary-precision arithmetic. But for this challenge, I'm making use of the P command, which interprets a number as a series of characters in base 256 and prints them. Examples: 65 P prints A (ASCII code 65). 16706 P prints AB (16706=65*256+66).

Aside from that, the only other interesting feature is that it recognizes all of the hexadecimal digits 0-9A-F even when they are not contained in a hexadecimal number. Decimal input is the default, so the input token 999 means 9 hundreds + 9 tens + 9 and ABC means 10 hundreds + 11 tens + 12 making it equivalent to 1122.

The ability to use the digits ABD in decimal partially makes up for the inability to use 12357, and the choice of ordering and grouping does the rest. (If I need some numbers x,y,z and they aren't representable with allowed digits, then I try representing x*256*256+y*256+z instead.)

The program can probably be made slightly shorter by using larger groups. I didn't go past 3 bytes per number.

share|improve this answer
@DigitalTrauma the other way around was the Bonus at the end of the problem statement. – Wumpus Q. Wumbley Jul 29 '14 at 16:44
Ha! I missed that! Excellent! +1 – Digital Trauma Jul 29 '14 at 16:46
Can you explain this? And is there a place we can run this? – Helka Homba Jul 29 '14 at 17:08
A place you can run it? dc isn't some silly language designed for making hard-to-read programs, it's a serious calculator. Run it on any unix machine (or cygwin). – Wumpus Q. Wumbley Jul 29 '14 at 17:15
@Calvin'sHobbies If you have access to just about any Linux or Unix machine (including OSX), simply save as a text file e.g. bonus.dc, then run dc bonus.dc. dc is one of the oldest languages out there and has been a permanent fixture in *nix for literally decades. Its not well-known though, probably due to its arcane and not-very-readable RPN syntax. Great for some code-golf challenges though ;-) – Digital Trauma Jul 29 '14 at 19:45

Bash+coreutils, 56 bytes

tr \(-y \!-r<<<'*+,-7;=?GHIKVWXYhiklnvwx'
tr C-F 7-:<<<E

As luck would have it, adding 7 to the ascii value of the holed characters yields all unholed characters (with the exception of "9"). So we just do this transformation in reverse, then a similar transformation (subtract 12 from "E") to get the "9".


share|improve this answer
I like how the first line subtracts 7 from a bunch of characters, and it contains a -7 conspicuously displayed between punctuation characters, and those 2 facts have nothing to do with each other. – Wumpus Q. Wumbley Jul 29 '14 at 19:56
@WumpusQ.Wumbley I hadn't even noticed that :) – Digital Trauma Jul 29 '14 at 20:03

Perl - 49 Bytes

symlink".",':=<?)-/! YX[]VIHKx{}|~vih'^chr(25)x25

This is pretty much a Perl version of Howard's solution. XORing the string with 25. The output is a file with the name #$%&04689@ABDOPQRabdegopq. I got the idea to use symlink and the file name as the output format because everything else is banned.

Here's another Perl solution I came up with. It can probably be improved a lot and it is pretty long, so I'm leaving in a readable format for now.

    if(chr(y/1/1/)!~/[!"'()*+,-.\/12357:;<=>?CEFGHIJKLMNSTUVWXYZ[\\\]^_`cfhijklmnrstuvwxyz{|}~]/) {
        symlink".",chr y/1/1/;

This one outputs many files, the name of each one is one of the characters. I couldn't figure out how to append strings without using a forbidden character.

for, while, map, say, print, eval, s///e, and any variable name cannot be used (variables start with @ or $ in Perl) which made this difficult.

Hopefully file names are okay as an output format because I'm pretty sure every other way to output information uses one of the banned characters.

share|improve this answer
I'm going to give you a +1 for creativity! Very clever use of code! – WallyWest Jul 23 '15 at 22:19

MATLAB, 36 bytes

SO CLOSE.... Only 1 byte more than the current winner (isaacg)! Which, on further inspection, already did what I set out to do too. Well, no harm in reinventing the wheel...

I know this is an old challenge, but I only realized that after I got interested in it.


If only I could get MATLAB to understand that I want a string without a separate ''... suggestions, anyone?

share|improve this answer

Brainfuck 303 275


Brainfuck, the ultimate unholed esoteric language (apart from Whitespace) ;)

share|improve this answer
Please delete old fragments, don't strike-through. – isaacg Jul 29 '14 at 6:43
I see you used the quote thingies (dont know real name) for your code snippets. Might be easier to select your code and press Ctrl+K :) – Teun Pronk Jul 29 '14 at 6:50
@isaacg Done. TeunPronk, done! – WallyWest Jul 29 '14 at 7:11
Or just hit the spacebar 4 times if it's only a line or two. @TeunPronk This? ` That's a backtick. (Also called a grave accent, although "quote thingies" is a new one for me :P) – Doorknob Jul 29 '14 at 7:41
@Doorknob Then we both learned something today although what you learned is wrong anyhow :P – Teun Pronk Jul 29 '14 at 7:42

JS - 196 - try it

share|improve this answer
Gosh, this is crazy. It seems Js is one of the most abusable language=) – flawr Jul 29 '14 at 22:21
Abusable yes, but this is a mere speck compared to my entry... Sorry @bebe but I've out-JS'd you this time... – WallyWest Jul 29 '14 at 23:02
@WallyWest i declare war. – bebe Jul 29 '14 at 23:31
217: h=1-1;j=3+3;k='\\x';m=!i+k;c=m[1];f=m[i=2+2];l=k+3;n=k+j;r=k+i;this[f+'v'+c+'l']‌​(c+'l'+f+'rt("\\x23\\x2'+i+k+25+k+2+j+l+h+l+i+l+j+l+2*i+l+3*3+r+h+r+1+r+2+r+i+r+'f\\‌​x5'+h+k+51+k+52+c+n+2+n+i+f+n+7+n+'f\\x7'+h+k+'71")') - inlined l, shortened m, declared i on first use, created a few extra vars for repeated patterns (you could possibly improve this by tweaking the order of chars outputed, but that's beyond my patience :P). – Alconja Jul 30 '14 at 1:03

GolfScript, 89 characters

71 22+,{33+}/]''+'!"\'()*+,-./12357:;<=>?CEFGHIJKLMNSTUVWXYZ[\]^_`cfhijklmnrstuvwxyz{|}'-

Simply builds an array of all ASCII characters and subtracts the non-"holed" characters from them.

71 22+,  # Builds array of 0..93
{33+}/]  # Converts to 33..126
''+      # Convert ASCII codes to string
'stuff'- # Subtracts "stuff" (the non-holed characters) from the string
share|improve this answer

Befunge 98 - 69 bytes

"()+ijWI=*">:5j2 ,-5_"157:h">:5j2 ,-1_"=>?LMN^_lmn">:5j2 ,+3_"?"1+s <

Does it in 3 parts. One where unholed character values differ from holed character by 5. Then the ones that differ by 1, and finally a list of unholed characters that differ by 3 from holed ones. The terminate program instruction in Befunge is "@" (char value 64), so at the end I load "?" (char value 63) add 1 then put that in the code with the instruction 's'.

I could maybe golf it more by consolidating the three

>:5j2 ,(differ value)_

section, but probably not by much.

share|improve this answer

JavaScript 240 228

Initial submission:


Now, this is a great start, here's how it breaks down...

z=(!1+"")[1];        // assigns "a" to z, !1+"" === "false"
y=(!!1+"")[3];       // assigns "e" to y, !!1 === "true"
x={}+"";             // assigns "[object Object]" to x
w=x[1];v=x[2]        // assigns "o" to w, and "b" to v
u=z+"t"+w+v;         // creates the mystical "atob" command, yes, I'm gonna use it!
1[_="c\157nstruct\157r"][_] // sets up the primitive to a number object... this acts similar to the "window" primitive object so that I can play off functions...
z+'l'+y+'rt(         // starts creating an alert call
// Above line abuses atob command with a couple of nested instances of the command, also using hex and octal equivalents of characters

And then I thought... "There must be a simpler way..." and there is...

Revised submission: z=(!1+"")[1];y=(!!1+"")[3];x={}+"";w=x[1];v=x[2];u=z+"t"+w+v;this[y+"v"+z+"l"](z+'l'+y+'rt('+u+'("Iy\x51lJj"+'+(t=u+'("\x51\x51==")')+'+'+u+'("M"+'+t+'+"==")+"Nj"+'+u+'("Zw==")+"5\x51EFC\x52E\71\x51UVJhYm\x52lZ2\71wc\x51=="))')

Seeing I can use eval (by piecing it together, inspiration from @bebe; which is a lot quicker than using the constructor of a constructor of a number... ) I drilled it down to 228... I know it may not win this particular Golf Challenge, but this is just my way of showing how much you can abuse JavaScript, and still get the desired result...

share|improve this answer

Main - Insomnia, 50


It outputs:


Bonus - Insomnia, 268


It outputs:


I think it should be possible to reduce the length of the program if the output is rearranged, but I need to modify my search program to do this.

Just to show case another language which is capable of operate with a restricted number of characters. By the way, it can write just about any output with only 3 unique characters in the source.

Currently, this is the only language that can do both the main challenge and the bonus among all the existing answers.

Insomnia Interpreter.

share|improve this answer

Befunge 98 - 46 bytes

Befunge-ified version of isaacg's Pyth entry:

"xwvnlkihYXWVKIHG?=;7-,+*">:5j2 ,-7_"?"1+:,s <
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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