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

You have been hired for your tech knowledge as a Secret Agent's sidekick to ensure that the good guy can get his job done and the world can be saved.

This is your last mission before retiring with a high paycheck and the gratitude of the whole world. But before you have to disarm the Evil Genius' Big Overly Massive BOMB (seems that the evil genius is an smart ass who likes recursive acronyms). Anyways you and your buddy are in the very core of the Evil Genius secret base, ready to disarm the BOMB that could wipe the continent out. In your previous mission you managed to get the disarm code that to your astonishment is just "PASSWORD_01". You connect your keyboard to the BOMB and when you are ready to go the Evil Genius' henchmen enter in with a barrage of bullets. Unfortunately one of these bullets impacts on your keyboard. "Finish the job while I distract those d*ckheads!" says your buddy and then begins to fire his gun. But how could you finish the job with only half a keyboard?


  1. Write a program that outputs in any way you want the string PASSWORD_01 (uppercase).
  2. Since your keyboard has been hit by a bullet, you can only use these keys:

    1 2 3 4 5

    Q W E R T

    A S D F G

    < > Z X C

    Ctrl Shift Tab Space

    Using the Shift key, your keyboard allows you to use these characters:

    ! " · $ %

  3. You don't have any other hardware than the keyboard and the screen (a mouse for example), neither a file with the password written in your computer.

  4. You don't have an Internet connection.

  5. You can assume you have the interpreter shell / source editor opened before the bullets came in. Sadly you have not written anything in it before the keyboard was hit.

  6. You don't have a virtual keyboard. In fact the BOMB has a TOO_FUNNY detector that will make it explode if you try to use the Standard loopholes.

  7. Since your buddy is waiting for you to finish soon to scape of the Secret Base you will have to write the smallest code possible (so it's and !).

Good luck because the count down has begun!

HELP MODE: Also a KEY (only one Key you want from the keyboard, but not the Shift + Key or any other combination) has miraculously survived too. EG: You can use =, or 0 or /… This extra key cannot be any of the letters in PASSWORD_01 (so you cannot add P or R). Name that key in your answer. You have a penalization of 10 characters for use this key regardless of how many times you use the key.

share|improve this question
Can I change the layout of the keyboard to DVORAK? – n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳ Jun 11 '14 at 10:54
Do we get the enter key at least? – Ourous Jun 11 '14 at 11:51
Whitespace, here is your big chance! – german_guy Jun 11 '14 at 13:08
Why couldn't the password have been stewardesses? – codebreaker Jun 11 '14 at 18:07
Joke answer: I'm a spy, I switch to the backup keyboard hidden in my watch. – Nzall Jun 11 '14 at 20:50

12 Answers 12

up vote 32 down vote accepted

CJam - 24 + 10 (() = 34


No additional key - 39

211 131%c"ASSW"211 132%c"RD"321 113%cT1

Try it at

share|improve this answer
Background music: – aditsu Jun 11 '14 at 13:52

bash, vim and dc (343)

I'm sitting at a bash prompt which has been configured by the Evil Genius, and of course he has VISUAL=vim in the default environment. Using the default bash binding for edit-and-execute-command (C-x C-e) bash invokes $VISUAL and will execute its buffer contents on exit (ZZ). I type in the following sequence (Note: kbd-mode are commands issued in normal mode and control sequences):

  1. C-xC-e
  2. acat<<<45C-c4C-aaa

    Now the vim buffer contains cat<<<49a. Continuing ...

  3. 45C-c3C-aaa

  4. 54C-c41C-aaa
  5. 55C-c13C-aaa

    Now the vim buffer contains cat<<<49a48a95a68a. Continuing ...

  6. 51C-c31C-aaa

  7. 55C-c24C-aaa
  8. 44C-c43C-aaa
  9. 42C-c41C-aaa
  10. 42C-c41C-aaa
  11. 54C-c11C-aaa
  12. 55C-c25C-aaa>s

    Now the vim buffer contains cat<<<49a48a95a68a82a79a87a83a83a65a80a>s

    Get out of insert mode, save and exit

  13. C-cZZ

    The s file now contains a dc script that generates the desired string on the stack, now we need to add print commands.

  14. C-xC-eadc<<<55C-c25C-aaa>>sC-cZZ

    Repeat the above command 9 times.

  15. C-xC-eadc<<<55C-c25C-aaa>>sC-cZZ

  16. C-xC-eadc<<<55C-c25C-aaa>>sC-cZZ

  17. C-xC-eadc<<<55C-c25C-aaa>>sC-cZZ

  18. C-xC-eadc<<<55C-c25C-aaa>>sC-cZZ

  19. C-xC-eadc<<<55C-c25C-aaa>>sC-cZZ

  20. C-xC-eadc<<<55C-c25C-aaa>>sC-cZZ

  21. C-xC-eadc<<<55C-c25C-aaa>>sC-cZZ

  22. C-xC-eadc<<<55C-c25C-aaa>>sC-cZZ

  23. C-xC-eadc<<<55C-c25C-aaa>>sC-cZZ

  24. C-xC-eacat<<< f >>s

    Execute the dc script:

  25. C-xC-eadc sC-cZZ



Contents of the s file:

share|improve this answer
I was thinking to do a vim script because of the Ctrl character; good thinking to pair it with dc! Also, excellent solution :) – nneonneo Jun 12 '14 at 0:28
+1 This should be the winner IMO – Digital Trauma Jun 12 '14 at 0:43
How long did it take you to write all those <kbd></kbd> tags? – justhalf Jun 13 '14 at 17:13
@justhalf: I wrote it in vim with <Leader>k bound like this map <Leader>k i<kbd></kbd>^[F>a, so it wasn't as bad as it looks :-). – Thor Jun 13 '14 at 23:25
Now it's apparent that Agent Thor knows his tool thoroughly. You deserve the retirement, sir! – justhalf Jun 14 '14 at 1:46

Ruby, 57 + 10 (*) = 67


This answer uses * and % to build the ASCII values of the missing characters (and 0 as Fixnum) and pushes them into $* (ARGV). This array is then used in combination with a format string to generate the correct password, which is printed with $><< ($> is stdout).

Ruby, 62 + 10 (.) = 72, no linebreak

$>.<< "%cASSW%cRD%c%d1".% %w%%<<311%231<<214%135<<321%113<<1%1

Roughly the same principle as the above version, except that here the array is built from an empty array literal (%w%%). Some fiddling with . is needed to get the desired operator precedence.

share|improve this answer
"This is your last mission before retiring with a high paycheck and the gratitude of the whole world." Congratulations, we all thank you :) – Timtech Jun 11 '14 at 14:01
The ultimate proof that Perl is one of the biggest inspiration of Ruby. – Pierre Arlaud Jun 11 '14 at 14:11
How did you do the linebreak? – Cephalopod Jun 11 '14 at 16:21
@Arian The same way nneonneo runs his Python code after typing it into the REPL ... I'll add a version without linebreak. – Ventero Jun 11 '14 at 21:26
Does the evil genius have ruby installed? – Mhmd Jun 13 '14 at 10:24

Whitespace (148 + 10 = 158)

Enter key needs to be used here.

SS+1010000L // Push code of P
TLSS        // Output character
SS+1000001L // Push code of A
TLSS        // Output character
SS+1010011L // Push code of S
SLS         // Duplicate top stack
SS+1010111L // Push code of W
SS+1001111L // Push code of O
SS+1010010L // Push code of R
SS+1000100L // Push code of D
SS+1011111L // Push code of _
SS+0L       // Push 0
TLST        // Output number
SS+1L       // Push 1
TLST        // Output number
LLL         // End program

My notation's explanation:

  • S, +, 0 are spaces.
  • T, 1 are tabs.
  • L is new line.
  • // starts comment.

Each line is a command in whitespace language.


share|improve this answer
Ah man... I was just working on that :( – Teun Pronk Jun 11 '14 at 13:09
Me too, but I gave up on this knowing someone would be faster – german_guy Jun 11 '14 at 13:11
I thought 'L' wasn't available? – 500 - Internal Server Error Jun 12 '14 at 14:18
@500-InternalServerError: Actually L stands for new line character. Check the Demo for the real code. What I posted is a readable version. – n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳ Jun 12 '14 at 15:07
Ah, I get it now. – 500 - Internal Server Error Jun 12 '14 at 15:17

Python (2200 395 + 10)


I needed the + character (costing +10), which can be obtained from the numpad (or on certain key layouts).

Yeah, the BOMB probably went off while I was typing that.

The basic approach is to construct ever larger character sets by using exec and "%c"%(number). There are four execs nested inside each other. Gradually, my digit set progresses up from

  1. 12345
  2. 1234567 (6 = ASCII 54, 7 = ASCII 55)
  3. 123456789 (8 = ASCII 56, 9 = ASCII 57)
  4. 0x0123456789abcdef

so that in the final iteration it is possible to express any character (so that the innermost version can actually run any program at all).

Around 50% of the program is just quote characters ("%c"%34 is a double quote), because the nested nature of the exec statements demands "escaping" quote characters aggressively.

share|improve this answer
If you use the "+" from the numeric keypad, you are independent from the keyboard language. – celtschk Jun 12 '14 at 20:31
@celtschk: Good point! I will edit that in. – nneonneo Jun 12 '14 at 20:32
Rather than constructing digit sets with nested execs, couldn't you get numbers using arithmetic? Ex. exec '%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c'%(112,114,51+54,55+55,1+115,32,4+35,25+5‌​5,11+54,31+52,31+52,32+55,24+55,31+51,13+55,41+54,3+45,4+45,4+35) – Kevin Jun 17 '14 at 12:09
Because you can't get both parens. (I did consider this!) – nneonneo Jun 17 '14 at 13:37
Additionally, Python doesn't have a lot of operators that bind more strongly than %. ** is one, but it tends to be fairly useless for constructing most terms. – nneonneo Jun 17 '14 at 13:39

Insomnia 39 35 31 29

This language comes up when I was looking around for a language that encodes its instructions with single ASCII character. The language actually operates on the decimal ASCII code of the character, so it is still quite flexible with half of the keyboard destroyed.

Drop it down further to 29 characters, which is possible after reducing memory usage and increases the search space:

FdFzt%dF<rGdt>tt Gtreeet t%4s

I decided to run my tweaked up program on the full set of allowed characters, and cut the solution down to 31 characters:

FdFGt dtreeC>tt FFdx<Fdtr ztq4s

I used a program to search for this solution. It is one among many solutions returned by my program, all with the same size.


Old version constructed by hand. I remember staying up till morning to do this.


Here is the Insomnia interpreter for testing.

share|improve this answer
+1 for the "staying up till morning" match with your programming language choice. – justhalf Dec 4 '14 at 2:36

Vim + PHP on Some Window Managers

65 keys in 44 strokes, with a 10-point penalty for using =.


A breakdown:

  • Alt+Tab appears to work like Esc with Vim, or perhaps with this terminal emulator. Thanks for teaching me something new!
  • aEACE<Alt+Tab>: Enter append mode and insert “EACE”. Exit.
  • z=5<Alt+Tab>: Perform spelling correction. Select 5, “PEACE”. Exit. (Esc seems to work as Enter here!)
  • $xxxxaASSWRD<Alt+Tab>: Go to the end of the line. Delete 4 characters and add ASSWRD, resulting in PASSWRD. Back to normal mode. (No, 4x won’t work.)
  • z=1<Alt+Tab>: PASSWORD is probably going to be the first correction for this. Select it.
  • $a$aA<Alt+Tab>: Go to the end of the line, and add a $aA. Back to normal mode.
  • ==: Format this line of PHP nicely, changing the camelCase $aA to $a_a. This also moves the cursor back to the start of the line.
  • wxx: Go forward a word; the cursor is now before $. Delete two characters – the $ and the a – to make PASSWORD_a.
  • $r1: Go to the end of the line and replace the current character (i.e. a) with 1, resulting in PASSWORD_1.
  • ^X: Decrement the integer under the cursor, resulting in PASSWORD_0.
  • a1: Finally, append 1, for PASSWORD_01!
share|improve this answer
I can't replicate == command, it just toggles large indentation mode in my vi setup (debian 7, v7.3.547) – Cengiz Can Jun 19 '14 at 14:34

Brainfuck (553) [invalid]

So here we go, coded in Brainfuck using this interpreter. I additionally used the + key, so that's 543+10 = 553 characters, still room for improvement:


EDIT: I am sorry, this answer is invalid since the '+' is made with Shift+1 on a swiss keyboard.

share|improve this answer
Where did you get that +? – Timtech Jun 11 '14 at 12:37
@Timtech The '+' is made using [shift]+[1], and i did not use '-' – flawr Jun 11 '14 at 12:40
[Shift]+[1] = ! – Teun Pronk Jun 11 '14 at 12:41
@TeunPronk Oh sorry, forgot that there is a difference in the special chars on swiss keyboards. – flawr Jun 11 '14 at 12:43
@TeunPronk Yes but I already used '.' as the help mode key. – flawr Jun 11 '14 at 13:16

Perl, (31+10 / 41+10 / 64+10)

(^ key used, 3 ways)

exec"easswsrdcqw"^"5    <  <AF"                   # exec "PASSWORD_01"

  • Valid if running as a system command qualifies as "output."

exec"QQZSqeasswsrdcqw"^"422<Q5    <  <AF"         # exec "echo PASSWORD_01"
  • Valid if I'm allowed to use external/OS commands. (Run here)

exec"EQAXqwQqQZQxqeasswsrdcqwxqq"^q!5434QZ4S534$S5    <  <AF$SS! 
                  # exec "perl -e\"die\\\"PASSWORD_01\\\"\""
  • Valid if I can execute Perl via the system. (Run here) <-- this one uses print instead of die

The scripts use Perl's bitwise string XOR operator ^, which does an XOR on the character bits of the two strings. This lets me recreate the missing characters for PASSWORD_01, and create the characters for the system command.

I made the three variants depending on how lenient the rules are. I assume that since variants 2 and 3 actually output the words on Ideone, the solutions are valid. I removed the little story I had here since I figured no one would read it, but you can read it in the edits if you're curious!

share|improve this answer

oOo code (300)


Easy. (Linefeeds are optional, and just here to make the code "more readable") Code generator used:

o=lambda b,c:"".join(i.upper()if j else i for i,j in zip(__import__('itertools').cycle(c),map(int,"".join((3-len(i))*'0'+i for i in(bin('><[]-+.,'.index(i))[2:]for i in b)))))

The same code in a less silly encoding:

share|improve this answer

bash + vim (56)

Borrowing the Ctrl-XCtrl-E bash trick from Thor's solution, here is how I would do it in bash+vim:

C-XC-E starts default editor (usually vim)

a starts insert mode

.space ASSW

C-Vx4f inserts O


C-Vx5f inserts _


C-3 is equivalent to escape (not just in vim, but anywhere in a terminal)

C-X subtracts 1 from the 1 i just typed

a insert mode again

1 C-3

buffer content is now . ASSWORD_01

<< unindent line (a no-op, since line is not indented) and move cursor to 1st column


C-X start word completion

C-V complete with ex command

C-V 9 more times selects the entry Print

C-3 back to normal mode

XXXxx deletes rint (there's a space after the t that Stackexchange doesn't show)

< < back to column 1

s delete ., start insert mode

e c C-X C-V ex command completion once again, entry echo already selected because of the ec i just typed

space C-3 buffer content now echo PASSWORD_01

Z Z save buffer, close vim, bash executes file content, i.e. echo PASSWORD_01

By the way: C-3 has many useful brethren: C-J is Enter, C-I is Tab, C-H is Backspace, C-2 is C-@ (i.e. a null-byte). And for emacs users it is nice to know that Escape followed by another key is equivalent to Alt + that key. So, even without Escape and Alt you can still type Meta-x like this: C-3x

share|improve this answer

Python (162 chars + 10)

Solved it in Python, using the "=" as an extra keyboard key. There are multiple statements, though, so I am not sure whether the "Enter" key would be a violation (since theoretically I could just hit "run" on an IDE and run all of those statements at once, without using an enter key".

exec """t="q%c=%%%%s%%c" %% 44 """ % 43
exec "q=5<<4%c" % 44
exec t % "203 % 124"
exec t % "235 % 140"
exec t % "6<<3"
"%cASSW%cRD%c%c1" % q


Anyway, I'm starting to really like Python!

share|improve this answer
since theoretically I could just hit "run" on an IDE and run all of those statements at once, without using an enter key Not sure what you are talking about - before you hit run, the line separator must be there. Or am I missing something? – n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳ Jun 18 '14 at 9:09

protected by professorfish Oct 18 '14 at 8:03

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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