48
\$\begingroup\$

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:

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_

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.


Leaderboards

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>

\$\endgroup\$
5
  • 2
    \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$
    – Dennis
    Commented 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
    Commented Feb 24, 2021 at 3:43
  • \$\begingroup\$ Is duplication of one char allowed? \$\endgroup\$
    – l4m2
    Commented Feb 24, 2022 at 17:42
  • \$\begingroup\$ @l4m2 No. "To be precise, the following characters need to be output, and no more." \$\endgroup\$
    – orlp
    Commented Feb 25, 2022 at 15:49
  • \$\begingroup\$ and no more can be parsed as "No more kind of chars" \$\endgroup\$
    – l4m2
    Commented Feb 25, 2022 at 15:51

106 Answers 106

3
\$\begingroup\$

Brainfuck, 114 103 98 90 76 71 bytes

Another trivial (now non-trivial) solution, but this time is BF!

Saved 14 (!) bytes thanks to @primo.

Saved 4 more bytes thanks to @primo's suggestion to generate the range backwards, and I saved another by incrementing before printing for the lowercase letters.

New (recurrence 4, 71):

+[--[<+++++++>->+<]>-]<<+++<--<-<-----<++++.+>>>[-<<.+<+.>>>]>[-<<.+>>]

Old (values, 114):

-[----->+<]>--->++++++++++>--[----->+<]>-------.++>----[---->+<]>++>++++[->++++++<]>++[-<<.+<<.+>>>>]<<<<<<[-<.+>]

Old (recurrence 1, 103):

++++++++++[[<+>->+<]>+++++++++++++++]<<[<]>>+>++++++++>>----->>-----.++<<<<<[->>>.+>>.+<<<<<]<[->>.+<<]

Old (recurrence 2, 90):

+++++++[[<+>->+<]>>+++[-<+++++++>]<]<<[<]>+++>-->->----->++++.++<<<[->>.+>.+<<<]<[->>.+<<]

Old (recurrence 3, 76):

+[[<+++++++>->+<]>+++]<<[<]>+++>-->->----->++++.++<<<[->>.+>.+<<<]<[->>.+<<]

Assumes 8 bit wrapping cells and wrapping memory. I used Try it online.

All print out _AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789

First, this part

+[--[<+++++++>->+<]>-]<<

initializes the tape with these values

[91, 70, 49, 21, 7]
                 ^

This works because the recurrence relation I modeled basically is f(x) = 7 * (3 * x + 1), backwards. See @primo's Hello, World! Answer for an explanation of what a recurrence relation is.

Then, it's fairly simple to change these values to useful ones. (and print the underscore)

Code: +++<--<-<-----<++++.+

Tape: [96, 65, 48, 26, 10]
       ^

Then, the simple loops use the values to print the rest of characters. I save 1 byte by having an increment before the print.

>>>[-<<.+<+.>>>]>[-<<.+>>]

I really need to find a shorter sequence generation.

I found a recurrence relation that seems to work well, but there might be a shorter one w/ less hunt and peck.

I used a linear regression calculator to find what should be the shortest possible linear recurrence relation, so I should probably find some other formula if I want to improve.

@primo really improved the recurrence relation a lot, thanks.

\$\endgroup\$
3
  • \$\begingroup\$ How about a backwards construction? +[--[<+++++++>->+<]>-] \$\endgroup\$
    – primo
    Commented Jul 21, 2016 at 8:09
  • \$\begingroup\$ @primo Wow! How does that work? \$\endgroup\$
    – Blue
    Commented Jul 21, 2016 at 11:26
  • \$\begingroup\$ 3 is uneven so it will loop a full 256 times. By ending with >-], you can be sure that the final term will be 1 (x7). Actually, you should probably start with -, it finishes a lot faster. \$\endgroup\$
    – primo
    Commented Jul 21, 2016 at 11:31
3
\$\begingroup\$

R, 40 bytes

Inspired by this answer.

cat(intToUtf8(c(97:122,65:90,48:57,95)))

Try it online!

\$\endgroup\$
3
\$\begingroup\$

SMBF, 29 bytes

<[<.-<.->>-]<<-.<[<.->-]9
zZ

Try it online

The last byte is a literal \x1A (decimal 26). It shows in the "edit" mode of this answer as a tiny arrow, but cannot otherwise be seen for some reason...

I use literals in the source code to provide a starting value and how many times to loop. 26 times for the loop printing Z-A and z-a, then subtract and print _, then use the newline (decimal 10) to print 9 and subtract, looping 10 times.

Output:

ZzYyXxWwVvUuTtSsRrQqPpOoNnMmLlKkJjIiHhGgFfEeDdCcBbAa_9876543210
\$\endgroup\$
3
\$\begingroup\$

x86-16 machine code, PC DOS, 26 bytes

Binary:

00000000: be12 01ad 918a c1cd 293a cde0 f83c 5f75  ........):...<_u
00000010: f2c3 7a61 5a41 3930 5f5f                 ..zaZA90__

Listing:

BE 0112     MOV  SI, OFFSET TBL     ; SI to range table
        RLOOP:
AD          LODSW                   ; AL = high, AH = low
91          XCHG AX, CX             ; move to CX
        CLOOP:
8A C1       MOV  AL, CL             ; move current char to AL for display
CD 29       INT  29H                ; write to console
3A CD       CMP  CL, CH             ; high and low char the same yet?
E0 F8       LOOPNZ CLOOP            ; if not, decrement and keep looping
3C 5F       CMP  AL, '_'            ; was last char displayed a '_'?
75 F2       JNZ  RLOOP              ; loop until then
C3          RET                     ; return to DOS
        TBL DB 'zaZA90__'           ; handy table of ranges to display

Uses a table with a range of chars to display. Turned out that it wasn't any longer to do it this way than unroll all of the 4 different conditions in code (though I'm positive I can be proven wrong there).

Standalone PC DOS executable (COM) program.

Runtime:

enter image description here

\$\endgroup\$
3
\$\begingroup\$

NoRAL, 173 169 bytes

psh 0a1a
sto 0100 41
sto 011a 61
orr 0201 0201
jpz 0220
sto 0134 30
inc 0215
inc 0216
dec 0201
inc 0205
inc 0206
inc 0209
inc 020a
dec 0202
jpz 0235
jmp 0203
sto 013e 5f

NoRAL is a toy assembly language I found on Esolangs.org. Let's give it a whirl (using a minimally adapted version of the Python implementation): Try it online!

There's also a browser-based interpreter here if you want to step through the code.

Explanation

Everything in NoRAL is stored in addressable memory, including the output (256 consecutive bytes, displayed as a 32x8 rectangle) and the program itself, which is self-modifying.

# We use two memory locations in the code, 0x0201 and 0x0202, as counters
# Set digit counter to ten (0x0a), letter counter to twenty-six (0x1a)
# The psh instruction pushes something to the stack, which we're not using, so it's
# effectively a no-op
psh 0a1a
# The output section of memory runs from addresses 0x0100 to 0x01ff
# We're going to put A-Z at 0100-0119, a-z at 011a-0133, 0-9 at 0134-013d, and _ at 013e
# Output uppercase and lowercase letter, starting with A (ASCII 0x41) & a (0x61)
# These instructions will be modified later to output the other letters
sto 0100 41
sto 011a 61
# OR digit counter with itself (no-op, but sets the zero flag if counter is zero)
orr 0201 0201
# If the digit counter is now zero, skip next section:
jpc 0220
#     Output digit, starting with 0 (ASCII 0x30)
sto 0134 30
#     Increment memory location and ASCII code in previous statement
inc 0215
inc 0216
#     Decrement digit counter
dec 0201
# Increment letters' memory locations and ASCII codes
inc 0205
inc 0206
inc 0209
inc 020a
# Decrement letter counter
dec 0202
# If letter counter is now zero, skip next instruction:
jpz 0235
#   Jump back to "output uppercase and lowercase letter"
jmp 0203
# Output underscore (ASCII 0x5f)
sto 013e 5f
\$\endgroup\$
2
  • \$\begingroup\$ There's no permalink feature in the interpreter, that's purely awful. \$\endgroup\$
    – user96495
    Commented Aug 22, 2020 at 2:45
  • \$\begingroup\$ ...Eh. The thing I found more problematic was that the code disappears out of the input box every time you click Run, but I just kept my code in a text editor and pasted it in whenever I was ready to run it. No big deal. \$\endgroup\$
    – DLosc
    Commented Aug 22, 2020 at 2:49
3
\$\begingroup\$

Python 3, 69 bytes

for i in range(65,123):x=chr(i);print(''if x in'[\\]^`'else x,end='')

Try it online!

Nice

\$\endgroup\$
3
+100
\$\begingroup\$

Vyxal dr, 9 8 7 bytes

‛\w₇ɾCẎ

Try it Online!

-1 thanks to @emanresu A

-1 thanks to @pxeger

Beats almost everything.

‛\w122ɾCẎ # Takes no input
‛\w       # The string "\w"
   122r   # inclusive range 1-122
       C  # Cast to character
        Ẏ # Regex groups
          # "d" flag prints the deep sum of the top of the stack

Vyxal , 11 bytes

122ɾCkr↔ṅ\_

Try it Online!

An alternative solution requiring no regex. Possibly cheating.

122ɾCkr↔ṅ\_ # Takes no input
122r        # inclusive range 1-122
    C       # Cast to character
     kr     # Uppercase letters, lowercase letters, and digits
       ↔    # Remove all not found in the second argument
        ṅ   # Join by nothing
         \_ # String "_"
            # "Ṫ" flag outputs sum of stack
\$\endgroup\$
3
  • \$\begingroup\$ Nice! 122 -> ⁺¢ \$\endgroup\$
    – emanresu A
    Commented Mar 1, 2022 at 2:47
  • \$\begingroup\$ You can use instead \$\endgroup\$
    – pxeger
    Commented Mar 3, 2022 at 15:27
  • \$\begingroup\$ Apparently someone switched around the order of , so you now need the r flag \$\endgroup\$
    – naffetS
    Commented Jul 10, 2022 at 1:15
2
\$\begingroup\$

Pyke, 13 bytes

150m.C#P)\_+s

Try it here!

Generates ascii 0-150 and filters by alphanumericness and adds _ to the end

\$\endgroup\$
2
\$\begingroup\$

Golfscript, 18 bytes

10,123,65>'[\]^`'^
\$\endgroup\$
2
\$\begingroup\$

Mathematica, 49 bytes

a=CharacterRange;"_"<>{48~a~57,65~a~90,97~a~122}&

Anonymous function. Takes no input and returns the string "_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" as output. Just concatenates a few character ranges.

\$\endgroup\$
2
\$\begingroup\$

JavaScript, 55 bytes

x=>[...new Set(Object.keys(this).join`j345689`)].join``
  1. The code works correctly only when executed inside the global Firefox browser console (tested with Firefox 47.0 on Linux Mint inside a freshly created profile).
    • To be able to open the console, you first have to set devtools.chrome.enabled to true in about:config. (You can then open it using Ctrl + Shift + J).
  2. Even the most ridiculously small change to the browser will likely break this code. In fact, I'm not sure if it will even work on another operating system.
    • The name of the profile might matter as well. I've named mine Default User.
\$\endgroup\$
2
\$\begingroup\$

Python 2, 62 bytes

r=range
print''.join(map(chr,r(97,123)+r(65,91)+r(48,58)))+'_'

prints:

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_

This could probably be golfed more but I'm not sure how!

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Since the output can be in any order, try fiddling with combining ranges and using slices. You may be able to shave off a few bytes that way. \$\endgroup\$ Commented Jul 18, 2016 at 18:40
2
\$\begingroup\$

Jelly, 14 bytes

“09AZaz_”Or2/Ọ

Try it online!

\$\endgroup\$
0
2
\$\begingroup\$

V, 5 bytes

¬ ~Ó×

Try it online!

Explanation

¬ ~                      " Outputs characters in the range " " to `~`
Ó×                       " Removes all non alphanumeric characters
                         " Synonym of vim's :s/\W//g
\$\endgroup\$
2
\$\begingroup\$

K, 28 bytes

_ci,/(97 65+\:!26),95,48+!10

Generates [97..122]++[65..90]++[95]++[48..57] and maps the numbers to chars.

\$\endgroup\$
2
\$\begingroup\$

APL (Dyalog Extended), 12 bytes

Full program.

'_',∊⍳¨'zZ9'

Try it online!

⍳¨'zZ9' "ɩndices" until each of the three characters

ϵnlist (flatten)

'_', prepend an underscore

\$\endgroup\$
2
\$\begingroup\$

ZX Spectrum, (Machine Code) 27 bytes

start in BASIC with PRINT "" AND USR 4e4

      org 40000
      dump 40000


      ld b,"z"
      ld a,"_"
      rst 16
nchar ld a,b
      cp "/"
      ret z
      cp ":"
      jr c,ok ; print numbers
      sub "A"
      cp "Z"+1-“A”
      ld a,b ; undo change
      jr c,ok ; print A-Z
      cp "a"
      jr c,fnext ; in between ranges
ok    rst 16
fnext djnz nchar

Hexcode

067A3E5FD778D641fe1a78380b
413809FE5B3804FE613801D710Ea

Output: _zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA9876543210

\$\endgroup\$
2
  • \$\begingroup\$ Can we have a hexdump of the compiled version? \$\endgroup\$ Commented Jul 19, 2016 at 17:37
  • \$\begingroup\$ Will make it later. \$\endgroup\$ Commented Jul 19, 2016 at 21:02
2
\$\begingroup\$

Lua, 64 bytes

s="abcdefghijklmnopqrstuvwxyz"print(s..s:upper().."_0123456789")

Try it online!

\$\endgroup\$
4
  • \$\begingroup\$ I tried your code with this and it doesn't print numbers. \$\endgroup\$
    – user65167
    Commented Feb 10, 2017 at 19:53
  • \$\begingroup\$ @PrzemysławP Just ran it in the demo environment and it ran just fine (printing out abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_) \$\endgroup\$
    – Katenkyo
    Commented Feb 14, 2017 at 15:23
  • \$\begingroup\$ Yes, but question was to output also 0123456789, right? \$\endgroup\$
    – user65167
    Commented Feb 14, 2017 at 15:42
  • 1
    \$\begingroup\$ @PrzemysławP Wow, how did I missed that ?! Thanks, it's fixed now, it should be printing abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789 \$\endgroup\$
    – Katenkyo
    Commented Feb 14, 2017 at 16:05
2
\$\begingroup\$

Excel, 54 48 bytes

-6 bytes thanks to @TaylorRaine

=CONCAT(ROW(1:10)-1,CHAR({64,96}+ROW(1:26)))&"_"

Original Answer

=CONCAT(ROW(1:10)-1,CHAR(ROW(2:3)*32+COLUMN(A:Z)))&"_"

Link to Spreadsheet

\$\endgroup\$
2
  • 2
    \$\begingroup\$ If you replace the innards of the Char statement with {64,96}+ROW(1:26), you can get this down to 48 bytes \$\endgroup\$ Commented Feb 25, 2022 at 1:25
  • 1
    \$\begingroup\$ Thanks. That's what happens when you get locked in on a way to do something. \$\endgroup\$
    – Axuary
    Commented Feb 25, 2022 at 13:11
2
\$\begingroup\$

Java (JDK), 71, 70 bytes

(b,B)->{B="_";for(b=47;b++<122;)B+=b>57&b<65|b>90&b<97?"":b;return B;}

Try it online!

Inspired by an answer from dorukayhan this is a java.util.function.BiFunction<Character, String, String>

\$\endgroup\$
0
2
\$\begingroup\$

Pip, 9 7 bytes

C,E7~XW

Attempt This Online!

Explanation

C,E7~XW
  E7     2 to the 7th power (128)
 ,       Range
C        Cast each integer in the range to a character
    ~XW  In each character, find the first regex match of `\w`

The result is a list of values, some of which are nil, some of which are an alphanumeric or underscore character. By default, Pip outputs lists with no separator, and nil outputs nothing; so the output of the program is simply the requested characters plus a trailing newline.

\$\endgroup\$
2
\$\begingroup\$

Pure Zsh, 35 29 bytes

-6 bytes inspired by @pxeger's Zsh+coreutils answer

>{0..z};printf %c [[:IDENT:]]

Try it online! Attempt This Online!

The [:IDENT:] character class is exactly this. We use empty fallback ${:- } to a brace expansion, remove all non-[:IDENT:] characters, and then (j::)oin.

Turns out it's shorter to use multios to create a file for each character, then glob all matching files, joined with printf %c.

\$\endgroup\$
2
\$\begingroup\$

Haskell, 36 bytes

[c|c<-['('..'~'],(_,"")<-lex['a',c]]

Try it online!

Not the shortest answer but I thought of a cute way to solve this: pick out all the chars c such that ['a',c] lexes into a single identifier.

lex "a(" returns [("a","(")] but lex "ak" returns [("ak","")].

The only false positive is a' which is a valid identifier in Haskell even though ' is not A-Za-z0-9_.

We can eliminate it by starting the range at ( (one past ').

\$\endgroup\$
2
\$\begingroup\$

Zsh, 27 26 bytes

ls>{0..z}|tr -d '
:-@[-^`'

Attempt This Online!

Explanation:

  • >{0..z}: create files named 0 1 ... (all the ASCII characters in between) ... y z
  • ls: list all those newly created files
  • tr -d '¶:-@[-^`': remove the additional punctuation characters and the newlines

ls> works on arrays (unlike <<<), but is shorter than echo. (doesn't work if you care about order or duplicates). There's your newly discovered golfing tip of the day!

\$\endgroup\$
0
1
\$\begingroup\$

MATL, 20 bytes

95 48:57 65:90t32+vc

Try it online!

This is a very boring and straightforward answer.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You can replace 95 by '_' or by 95c and then h casts numbers to chars automatically, so you save the final c. Also, you can replace 32+ by ck. And changing the order allows you to remove a space: 65:90tck95c48:57v \$\endgroup\$
    – Luis Mendo
    Commented Jul 18, 2016 at 17:58
1
\$\begingroup\$

MSM, 79 bytes

;.;.;.;.;.;.:,,_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.

There's no shorter way to get all the letters, numbers and the underscore than explicitly writing them down. I also need 62 . commands to concatenate all the chars into a single string. These are generated by starting with a single . (on the very right), duplicating an concatenating (-> ;.) 8 times, splitting into 64 single dots again (-> :) and dropping two of them (-> ,,).

\$\endgroup\$
1
\$\begingroup\$

Java, 106 bytes

String A(char b){String B="_";for(b=48;b++<58;)B+=b;for(b=65;b++<91;)B+=b;for(b=97;b++<123)B+=b;return B;}

Returns _0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz by abusing for-loops.

Making the above function compilable costs 9 bytes, resulting in a 115-byte program:

class a{String A(char b){String B="_";for(b=48;b++<58;)B+=b;for(b=65;b++<91;)B+=b;for(b=97;b++<123)B+=b;return B;}}

The equivalent monolithic program which prints _0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz is 148 bytes long:

interface a{static void main(String[]A){char b;String B="_";for(b=48;b++<58;)B+=b;for(b=65;b++<91;)B+=b;for(b=97;b++<123)B+=b;System.out.print(B);}}

Java (lambda expression), 91 bytes

(b,B)->{B="_";for(b=48;b++<58;)B+=b;for(b=65;b++<91;)B+=b;for(b=97;b++<123)B+=b;return B;};

This is a java.util.function.BiFunction<Character, String, String>.

\$\endgroup\$
7
  • \$\begingroup\$ Maybe it's a bit boring, but just manually printing everything: void f(){System.out.print("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_");} (94 bytes) is shorter in Java. ;) \$\endgroup\$ Commented Jul 19, 2016 at 7:08
  • \$\begingroup\$ yay under 100 ''void f(){char c=97;String r="";while(c<='z')r+=c++;System.out.print(r+r.toUpperCase()+"_");} \$\endgroup\$
    – dwana
    Commented Jul 19, 2016 at 10:42
  • \$\begingroup\$ 91 my final form, void f(){char c=65;String r="";while(c<=90)r+=c++;System.out.print(r.toLowerCase()+r+"_");} \$\endgroup\$
    – dwana
    Commented Jul 19, 2016 at 10:49
  • 1
    \$\begingroup\$ @KevinCruijssen shorter, as function: ()->"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345‌​6789_" ("only" 69 bytes). \$\endgroup\$ Commented Jul 19, 2016 at 13:43
  • 1
    \$\begingroup\$ 79 void d(){for(char b=1;b<127;b++)System.out.print((b+"").replaceAll("\\W",""));} \$\endgroup\$
    – PeterK
    Commented Jul 20, 2016 at 11:18
1
\$\begingroup\$

Japt, 22 bytes

0o#{ £YdÃf@Xf"\\\\w"Ãq

Try it there.

\$\endgroup\$
1
\$\begingroup\$

Jolf, 17 bytes

RψΜz@~dpAHd mHLSE

Try it here!

Explanation

RψΜz@~dpAHd mHLSE
   z@~             range from 1 to 126
  Μ   dpAH         chars of
 ψ        d mHLS   filter all that don't match "\w+" (LS)
R               E  join by ""
\$\endgroup\$
1
\$\begingroup\$

LINQ, 88 bytes

from c in Enumerable.Range(0,123)where char.IsLetterOrDigit((char)c)|c==95 select(char)c

A LINQ expression (OK it is almost C#) where the output is an IEnumerable<char>. You can try it with LinqPad.

\$\endgroup\$

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.