It is the year 87,539,319 and solitary space-walking is now commonplace, many people travel into space by themselves, propelled by nothing but a jetpack on their backs, programming their course with a personal computer and keyboard as they go.

You are one such person; you were out on a lovely, peaceful spacewalk, when, all of a sudden, you were ensnared by the gravity of a black hole!

As you plummet towards this black hole, spiraling ever faster inwards, you realise your one chance of survival is to broadcast a distress message, and hope a nearby ship comes to rescue you.

So, you break out your keyboard, and begin typing away a program.

Your program can be in any language, and must print HELP! to stdout (your PC broadcasts all stdout far into the depths of space.)

However, as you are near a blackhole, your keyboard is slowly being ripped to shreds!

Assume you are using a QWERTY keyboard like the one below, and that the blackhole is to your left;

QWERTY KEYBOARD LAYOUT

Remember, left and right shift are two different keys.

after every keypress, the left-most row of your keyboard (keys covered by left-most red line) is ripped off and flung into the black hole!

So, your first keypress could be any key on the keyboard, but from then onwards none of the leftmost Tab, Caps, Shift, Ctrl or ` keys may be used, at all. (r-shift and r-ctrl can still be used)

After the next keypress, the keys 1, Q, A,Z and Alt are flung into the abyss, and may not be used thereafter. After that, you lose Space, X, S, W, 2 and so forth.

Obviously, you want to complete your program as quickly as possible, so that rescue-time is increased; therefore, this is code-golf, and the shortest program in key presses wins!

Each answer should provide a list of keypresses, so, if my answer was this program (in the language squardibblyack)

!HELP\.

a keylist could look like:

Shift!HELP release shift \.

length: 8

I'm worried this challenge might be too difficult, but I'd love to see the kinds of answers submitted!

  • 12
    I'm downvoting this because it feels too constrained to have much creativity. – isaacg Apr 23 '15 at 17:44
  • 4
    Can we assume that using the python shell without print qualifies as STDOUT? – user80551 Apr 23 '15 at 20:02
  • 3
    What if my keyboard has a number pad? – mbomb007 Apr 23 '15 at 20:24
  • 4
    This could be slightly better with arrow keys. – user80551 Apr 23 '15 at 20:27
  • 6
    Is caps lock still effective if it's been pressed although the key has disappeared? – Josh Caswell Apr 23 '15 at 21:26

CJam, 11 keystrokes

The code is

"HELP*")9-

and the keylist is

Shift"HELP*") release shift 9-

and here is a demonstration of how it looks:

enter image description here

and here is how the code works:

"HELP*"              "This puts the string HELP* on stack";
       )             "This takes out the last character of the string and puts it
                      on the stack as a character";
        9-           "This simply reduces 9 from the ASCII code of * character
                      present on the stack which makes it an !";
                     "CJam automatically prints everything that is on stack";

Try the code here

  • 2
    Using the asterisk was pretty clever! I'd never thought of that. – theonlygusti Apr 23 '15 at 18:37
  • 2
    Well, I was unable to do this in GolfScript. It's a little too long. Converting from an integer to ascii is inefficient. "HELP*")9-[]+''+. I can't type the last four. – mbomb007 Apr 23 '15 at 21:23
  • 3
    I just knew CJam would have an answer... – Jerry Jeremiah Apr 23 '15 at 23:25
  • 9
    So one of the most future-proof languages in the world is apparently CJam. – Fors Apr 24 '15 at 12:41
  • 5
    Watch your finger when you hit the E, it looks like it might get taken into the abyss! – Canadian Luke Apr 24 '15 at 17:30

Python, 13 keystrokes (with creative interpretation of rules)

This entry assumes:

  • You have the interactive interpreter open already
    • (How are all these other people compiling and executing their code, anyway?)
  • You are using a keyboard that has cursor movement keys off to the right of the main area
  • Your terminal doesn't modify special keys with shift
  • The interactive interpreter printing 'HELP!' with quotes qualifies

Shift ! Left " E Left H Right L P End " Enter

>>> "HELP!"
'HELP!'

And I just realized that I accidentally stole @user80551 's idea. Oh well, time spent asking for permission is time spent not getting saved from a black hole, and "like the one below" doesn't imply identical to me.

Pyth, 11 keystrokes

Shift ! Left " E Left H Right L P Enter

"HELP!
  • Wow! That is ingenious! – theonlygusti Apr 24 '15 at 18:03
  • @Optimizer I've never used a terminal that selected text with shift, and I don't think I could even name one. I've used some that will send a different escape sequence that python can't understand, but many of them don't. – Random832 Apr 24 '15 at 18:51
  • @Random832 well, if you are assuming so much, then might as well do it in 11 bytes in Pyth... – Optimizer Apr 24 '15 at 18:59
  • @Optimizer Yeah, but I don't know Pyth. And getting both E and ! are the killer here, I don't know if Pyth would help. – Random832 Apr 24 '15 at 19:01
  • 1
    @vapcguy Not in the console window that the python interactive interpreter runs in. – Random832 Apr 25 '15 at 1:59

rs, 10 keystrokes (assumes the user is using Nano)

Or equivalent editor where Shift doesn't select text.

This isn't really a programming language, but if sed can be used on Code Golf, then rs can be used.

Right Shift ! Left E Left H Right L P Enter

HELP!

It just replaces the empty string with "HELP!", effectively printing it to the screen. Roughly equivalent to the sed script:

s/^/HELP!/

The cool part is that rs automatically puts ^/ in front of a replacement pattern where the delimiter (/) is not found. Handy for indenting code.

  • You forget that Enter is a stroke, too. 10 strokes. – vapcguy Apr 27 '15 at 20:26
  • 1
    @vapcguy Right. Fixed. – kirbyfan64sos Apr 27 '15 at 20:31

I believe the quickest this could be done in any script is Random's 11 with Pyth, since any language is going to require some character, like "p" or a quote mark or asterisk or something, then the word HELP!, and that E is going to go quick, meaning extra key presses for moving the cursor back before E to put in H, like he found, then forwards again for L and P.

If you have anything that requires a command word, like disp or echo, you'd have to do a space first before it gets torn off, the Shift and !, then use the Home key to start your word, and arrow keys as Random described for HELP. But you'll be fumbling your way around until you're just sucked in or lose the keys you need too quickly to do any of those. There's only a max of 14 characters, and that's assuming your last one is \ or |. You need 10 just to do HELP!:

SHIFT ! HOME E LT ARROW H RT ARROW L P ENTER

The defining " or * or P would get pressed just prior to the H. So 11 has got to be the quickest. Or 9 if we leave out the exclamation and capitalizing everything and don't have a symbol to type.

But no, me, being an internet historian in the year 87,539,319 and all, and being paranoid of aliens and the freak meteor shower, let alone black hole, I would not settle for that. Before I went out space-walking, I'd be prepared, with this article I would have found in my research to thank for that. I would load a text file that already has "HELP!" in it, and have a program that could write my coordinate position using the latest tracking satellite data we have into that file. That program I'd call "hlp.c", so it would go:

7 keystrokes:

c Home h l p . Enter

I realize I could make my file name shorter, but no one wants to broadcast their position by accident by typing H and Enter, especially if the program also alerts the authorities (a little like calling 911 when you don't have an emergency?) so let's go with a 3-letter filename, and we'll assume we have to still have file extensions with a . and minimum of 1 character. Also, naming it hlp instead of help means we avoid getting those nasty, built-in Help features when we're about to die in a black hole. I realize I could even possibly omit typing the .c by just doing h l p Enter, but this way I avoid those nasty Please supply file extension or Cannot find hlp errors when I'm about to get sucked into a black hole. "Garbage in, garbage out", after all, will still be a standard in the future.

So my graphic would look like:

enter image description here

And this would also be easy to remember, since the only "backwardsness" is typing c first. The rest is just like the file name.

  • 2
    First of all, if you're going with running a program (which already has the code in it) then it can be considered as a combination of several standard loopholes. Secondly, this is a code-golf, so you have to give the actual code, not an assumption that the code is already present in a file called hlp.c. Thirdly, you are supposed to provide the list of keystrokes for the program, not running the program. Fourthly, C programs ... – Optimizer Apr 25 '15 at 11:19
  • 1
    ... do not run like that. You need to first compile them and run them. So you will at least have to do help.exe (or help.out) in order to run the compiled code file. And lastly, if you are bending the rules and making use of the loopholes so much, why not simply have a file called h.c ? – Optimizer Apr 25 '15 at 11:21
  • The intent with a .c file was that it could be CSCRIPT, not actual C code that would require the compiler. Having h.c could mean when trying to type in the name of another file, with only 1 character in the name, that it is accidentally called instead of another file - I explained that already. Whatever code that was in the .c file, whether it was Console.Log("HELP!"), Console.WriteLine("HELP!"), etc., is largely irrelevant, especially since it was also going to include code to interface with satellites to get a coordinate fix - something I'm sure in the future will be open source. – vapcguy Apr 27 '15 at 19:55
  • My point with this post, too, was to indicate that having a file name, or something outside the bounds of the rules, was going to be the only way to beat 11 keystrokes, btw, since it takes 10 just for HELP!, as I mentioned before Kirby, and only less, like 9, if capitalization and using Shift didn't matter and we didn't have to have a character before or after HELP, such as with the exclamation point, or in Kirby's case, having to type a key character, like a p or * to initiate the program. – vapcguy Apr 27 '15 at 20:35
  • And help.exe and help.out would not work with the black hole's ripping apart of the keys. The e would be gone by the time exe came up, and the t is gone when trying to type out. You could type the t in out, first, then press Home, and type the HELP part, but if you could keep the extension to 1 character, why wouldn't you? – vapcguy Apr 27 '15 at 20:53

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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