Write a program or function that prints or returns a string of the alphanumeric characters plus underscore, in any order. To be precise, the following characters need to be output, and no more:


When printing to stdout, an optional trailing newline after your output is permitted.

Built-in constants that contain 9 or more of the above characters are disallowed.

Shortest code in bytes wins.

This is a very simple challenge, which I believe will generate some interesting answers nevertheless.


Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

# Language Name, N bytes

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

# Ruby, <s>104</s> <s>101</s> 96 bytes

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

# Perl, 43 + 2 (-p flag) = 45 bytes

You can also make the language name a link which will then show up in the leaderboard snippet:

# [><>](http://esolangs.org/wiki/Fish), 121 bytes

var QUESTION_ID=85666,OVERRIDE_USER=4162;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

  • 2
    \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$
    – Dennis
    Jul 19, 2016 at 0:45
  • \$\begingroup\$ "Built-in constants that contain 9 or more of the above characters are disallowed" sighs in 05AB1E... \$\endgroup\$
    – Makonede
    Feb 24, 2021 at 3:43
  • \$\begingroup\$ Is duplication of one char allowed? \$\endgroup\$
    – l4m2
    Feb 24, 2022 at 17:42
  • \$\begingroup\$ @l4m2 No. "To be precise, the following characters need to be output, and no more." \$\endgroup\$
    – orlp
    Feb 25, 2022 at 15:49
  • \$\begingroup\$ and no more can be parsed as "No more kind of chars" \$\endgroup\$
    – l4m2
    Feb 25, 2022 at 15:51

106 Answers 106

1 2 3

Excel VBA, 130 bytes

Have fun hitting enter...

Sub q()
For i = 1 To 123
If i > 47 And i < 58 Or i > 64 And i < 91 Or i > 96 And i < 123 Or i = 95 Then MsgBox Chr(i)
End Sub

brainfuck, 105

first code golf attempt using this



>++++++[<++++++++>-]         // p1=48
++++++++++                   // p2=10
[-<.+>]<                     // print 0-9, p1=58, p2=0
+++++++                      // p1=65
>>+++++[<+++++>-]<+          // p2=26
[-<.+>]<                     // print A-Z, p1=91, p2=0
++++.++                      // print underscore, p1=97 
>>+++++[<+++++>-]<+          // p2=26
[-<.+>]                      // print a-z
  • \$\begingroup\$ ++++++++++++++++++++++++++++++++++++++++++++++++ That can be done better. \$\endgroup\$
    – orlp
    Jul 18, 2016 at 20:30
  • \$\begingroup\$ improved the +x26 as well \$\endgroup\$
    – Kevin L
    Jul 19, 2016 at 13:23

Javascript (Using external library) (105 bytes)


What this does is gets the char code ranges from a-z, concats with A-Z, then concats 0-9, then pushes the code for _. Write takes a delimiter and joins everything together

Library: https://github.com/mvegh1/Enumerable/blob/master/linq.js

enter image description here


PHP, 74 71 bytes

echo 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_';

Brainfuck - 116 commands


Output: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz

How it works

>++++++++[<++++++>-] Get yourself up to \48, the start of [0-9]

>+++[<+++>-]<+ Count up 10

[<.+>-] Then print each character and bump it up

++[<+++>-]<+> jump up to the start of [A-Z]

>++++[<++++++>-]<++ start a counter of 26

[<.+>-] and print and increment 26 values

<++++.++> jump to [a-z], stopping in at _

>++++[<++++++>-]<++ counter of 26

[<.+>-] and print and increment 26 values

there's got to be a way to simplify that counter to 26 and the print happening twice, but I'm not nearly good enough with brainfuck to do so

  • \$\begingroup\$ 48 doubled is 96, so you could use replace the initial loop with >++++[>++++++[>++>++++<<-]<-] to get both. Probably shorter than two output loops. \$\endgroup\$
    – primo
    Jul 20, 2016 at 9:23

dc, 50 bytes


This doesn't feel very elegant.

[              # Open macro definition
 la 1+         #  Load a, increment
 dd            #  Duplicate a+1 twice
 sa            #  Store a+1 as `a'
 P             #  Print new value of a as a character
 lc>b          #  If c>a, do this again
]              # Close macro definition
ddd sb         # DDDuplicate and store as `b'
96sa C2sc x    # Set lower and upper bounds (`a' and `c') for [a-z] and execute a copy of b
64sa 90sc x    # Set bounds for [A-Z] and execute a copy of b
47sa 57sc x    # Set bounds for [0-9] and execute a copy of b
95P            # Print underscore

RETURN, 20 bytes

'_0 9

Try it here.

Creates a series of charcode ranges and outputs them.


𝔼𝕊𝕄𝕚𝕟, 10 chars / 13 bytes


Try it here (ES6 browsers only).

Translated roughly to ES6:


Common Lisp, 61 bytes

using formule for lowercase'ing from Practical Lisp, namely (format t "~(~a~)" "ExAMpleStRINg")

(format t"~a~:*~(~a~)0123456789_"'abcdefghijklmnopqrstuvwxyz)

Ideas for improvement are welcomed.


QBIC, 66 41 bytes

Had some coffee and re-read the specs:


This prints Aa\n all the way up to Zz\n, then the literal 0123456789_.

There are quite a lot of ways QBIC can approach this challenge if we want to print the string in the order provided.

By adding all the requested ranges to Z$ (Z$ gets printed implicitly), 71 bytes


Printing each range to screen, with ';` to prevent newlines, 67 bytes


Creates one range, printing only substrings, 70 bytes


Creating one range, but with modified start of that range, 69 bytes


But sadly the best at 66 bytes, just plainly printing this string:


q/kdb+, 35 bytes






Turns out I cannot read :) Q.an solves this in 5 bytes. I'll try to golf this new solution.

  • 1
    \$\begingroup\$ "Built-ins that contain 9 or more of these characters are disallowed." \$\endgroup\$ Jun 22, 2017 at 23:34

RProgN 2, 9 bytes



•           # Push a space
 z          # Push the character 'z'
  R         # Create a stack of all characters from space to z.
   .        # Concatenate them into a single string.
    '\W'-   # Filter out everything that matches the regex '\W' (Non-alpha-numeric characters)
            # Implicit print

Try it online!


JavaScript (ES7), 60 57 bytes

Shame we can't return an array or set of the characters, I could've saved quite a few bytes there.

_=>[...new Set(Object.keys(this).join`4Z_`+2**29)].join``

Test it

The second line is sorted to make it easy to check all characters are included.

_=>[...new Set(Object.keys(this).join`4Z_`+2**29)].join``
<pre id=o></pre>

  • \$\begingroup\$ G J K N Q U missing on Firefox 97.0 \$\endgroup\$
    – l4m2
    Feb 24, 2022 at 17:47

Fortran 95, 131 bytes

1 format(1A,25A,$)
2 format(10I1,$)

Just because every challenge is improved by a Fortran entry.

You'd think it would be easy to golf this down, but the required variable declarations get expensive very quickly so I think this is about as short as it's going to get.

If delimiters (\n) were allowed between characters in the output, this could be reduced to 83 bytes:


><>, 39 bytes


Try it online!

Fairly simple, prints _, loop prints a, A then increments and compares to Z. At the end it'll print 9-0.


Thunno J, \$12\log_{256}(96)\approx\$ 10 bytes

(Actually \$\approx\$ 9.88 bytes but the leaderboard doesn't take decimals)


Attempt This Online!


123R # range(123)
CJ   # converted from codepoints
"\w" # string "\w"
Af   # regex findall
     # Implicit output, joined
1 2 3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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