TransWikia.com

Print all alphanumeric characters plus underscore

Code Golf Asked by orlp on January 25, 2021

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=/<hd>s*([^n,]*[^s,]),.*?(d+)(?=[^nd<>]*(?:<(?:s>[^n<>]*</s>|[^n<>]+>)[^nd<>]*)*</hd>)/,OVERRIDE_REG=/^Overrides*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>

92 Answers

Convex, 9 bytes

New method! Also, I realized that is it pretty much exactly the same as Luis' answer but in Convex, but I came up with this independently.

'{,®W"Oò

Try it online!

Explanation:

'{,           Array of chars from NUL to 'z
   ®W"       Regex to match non-word characters
       Oò     Replace all matches with emtpy string

Old solution, 10 bytes:

A,'[,_¬^'_

Try it online!

Explanation:

A,          0-9
'[,_¬^      A-Za-z
'_          _

Correct answer by GamrCorps on January 25, 2021

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

Answered by DLosc on January 25, 2021

Pip, 9 bytes

(C,127XW)

Try it online!

Explanation

(C,127XW)
  ,127     Range(127)
 C         Cast each integer in the range to a character
(     XW)  In each character, find all regex matches of `w`

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

Answered by DLosc on January 25, 2021

APL (Dyalog Extended), 12 bytes

Full program.

'_',∊⍳¨'zZ9'

Try it online!

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

ϵnlist (flatten)

'_', prepend an underscore

Answered by Adám on January 25, 2021

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

Answered by 640KB on January 25, 2021

Zsh, 35 bytes

<<<${(j::)${:-{0..z}}#[^[:IDENT:]]}

Try it 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.

Answered by GammaFunction on January 25, 2021

Keg, 15B(The Keg SBCS is in Keg wiki.)

_9ɧZAɧzaɧ(,

Explanation:

_#             Push _
  9ɧ#        Push range 0-9
       ZAɧ#     Push range Z-A
          zaɧ#  Push range z-a
             (,#Output

TIO

Answered by user85052 on January 25, 2021

Japt, 13 12 bytes

;C+B+9ô ¬+'_

Try it online!

Answered by Oliver on January 25, 2021

MATLAB, 30 bytes

['a':'z','A':'Z','0':'9','_']

Very simple :)

Or, at the same cost:

char(48+[49:74,17:42,0:9,47])

or

char([97:122,65:90,48:57,95])

Answered by PieCot on January 25, 2021

R, 40 bytes

Inspired by this answer.

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

Try it online!

Answered by JayCe on January 25, 2021

K, 28 bytes

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

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

Answered by uryga on January 25, 2021

><>, 39 bytes

"AaZ_"o9:n:?!;1-80.
+}$:@=?}:o1+}::o1

Try it online!

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

Answered by Teal pelican on January 25, 2021

Fortran 95, 131 bytes

write(*,1)(char(i),i=97,122)
write(*,1)(char(i),i=65,90)
write(*,2)(i,i=0,9)
write(*,1)'_'
1 format(1A,25A,$)
2 format(10I1,$)
end

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:

print*,(char(i),i=97,122)
print*,(char(i),i=65,90)
print*,(i,i=0,9)
print*,'_'
end

Answered by georgewatson on January 25, 2021

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.

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

Answered by Shaggy on January 25, 2021

RProgN 2, 9 bytes

•zR.'W'-

Explained

•zR.'W'-
•           # 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!

Answered by ATaco on January 25, 2021

q/kdb+, 35 bytes

Solution:

("c"$48+(!)75)except":;<=>?@[\]^`"

Example:

q)("c"$48+(!)75)except":;<=>?@[\]^`"
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"

Notes:

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

Answered by streetster on January 25, 2021

T-SQL, 70 bytes

PRINT'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'

Procedural solutions in SQL are just too long, due to the length of keywords. A couple of my best attempts:

76 Bytes, store the alphabet then UPPER it:

DECLARE @ CHAR(26)='abcdefghijklmnopqrstuvwxyz'PRINT'0123456789_'+@+UPPER(@)

100 Bytes, add all chars from 65-122, then strip out the ones I don't want:

DECLARE @ VARCHAR(99)='0123456789'A:SET @+=CHAR(LEN(@)+55)IF LEN(@)<68GOTO A
PRINT STUFF(@,37,6,'_')

Answered by BradC on January 25, 2021

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

Answered by mbomb007 on January 25, 2021

QBIC, 66 41 bytes

Had some coffee and re-read the specs:

[65,90|?chr$(a)+chr$(a+32)]?@0123456789_`

This prints Aan all the way up to Zzn, 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

[97,122|Z=Z+chr$(a)][65,90|Z=Z+chr$(b)][48,57|Z=Z+chr$(c)]Z=Z+chr$(95)

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

[97,122|?chr$(a)';`][65,90|?chr$(b)';`][48,57|?chr$(c)';`]?chr$(95)    

Creates one range, printing only substrings, 70 bytes

[48,122|A=A+chr$(a)]?mid$(A,50,26)+mid$(A,18,26)+left$(A,10)+chr$(95)

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

[122|A=A+chr$(a)]?mid$(A,96,26)+mid$(A,64,26)+mid$(A,47,10)+chr$(95)

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

?@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_`

Answered by steenbergh on January 25, 2021

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.

Answered by user65167 on January 25, 2021

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

Answered by user41805 on January 25, 2021

Tcl, 68 bytes

puts abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_

Try it online!


tcl, 99

time {append s [incr i]} 9
set i 64;time {set s $s[format %c%c [incr i] [expr $i+32]]} 26
puts _0$s

demo


tcl, 100

time {append s [incr i]} 9
time {set s $s[format %c%c [expr [incr i]+55] [expr $i+87]]} 26
puts _0$s

demo

Answered by sergiol on January 25, 2021

SmileBASIC, 52 bytes

FOR I=65TO 90?CHR$(I);CHR$(I+32);
NEXT?1234567890;"_

Answered by 12Me21 on January 25, 2021

16-bit x86 machine code, 26 bytes

In hex:

B030B90A00AA40E2FCB05FAA40B11A5040AAE2FC5834207BF4C3

Input: DI: pointer to an array of at least 63 bytes. Function outputs the sequence

0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ

without any termination, since its length is constant.

Disassembly:

00: B0 30       mov    al,'0'
02: B9 0A 00    mov    cx,10
_00000005:
05: AA          stosb              ;*DI++=AL
06: 40          inc    ax          ;AL++
07: E2 FC       loop   _00000005   ;Print digits
09: B0 5F       mov    al,'_'      ;0x5f
0B: AA          stosb
0C: 40          inc    ax          ;AX=0x60
_0000000D:
0D: B1 1A       mov    cl,26
0F: 50          push   ax
_00000010:
10: 40          inc    ax
11: AA          stosb
12: E2 FC       loop   _00000010   ;Print single-case letters
14: 58          pop    ax
15: 34 20       xor    al,020      ;Flip "case" bit
17: 7B F4       jnp    _0000000D   ;Repeat if "not parity", i.e. AX is back to 0x40
19: C3          ret

Answered by meden on January 25, 2021

Lua, 64 Bytes

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

Answered by Katenkyo on January 25, 2021

?????, 10 chars / 13 bytes

Ⓒ…⩥ṻ)ŋ/W⌿

Try it here (ES6 browsers only).

Translated roughly to ES6:

String.fromCharCode(_.range(123)).replace(/W/g,'')

Answered by Mama Fun Roll on January 25, 2021

RETURN, 20 bytes

'_0 9
'a'z
'A'Z
,,,,

Try it here.

Creates a series of charcode ranges and outputs them.

Answered by Mama Fun Roll on January 25, 2021

Julia, 35 bytes

()->join(['a':'z','A':'Z',0:9,'_'])

Alternative solution, also 35 bytes:

()->replace(join('0':'z'),r"W","")

Answered by Mama Fun Roll on January 25, 2021

Hexagony, 33

"A}_8_47<='>({a/[email protected]!356);');

Expanded:

    " A }
  _ 8 _ 4 7
 < = ' > ( {
a / _ x . @ .
 9 !  3 5 6
  ) ; ' ) ;
   . . . .

Output:

aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ1203568479_

Try it online!

Note that there is an unprintable character 0x1A as the first byte of the program. This also makes the first row of the expanded Hexagon look sort of off. Many thanks to Martin for showing me this trick, as well as for suggesting the algorithm for printing the alphabet!

This prints the alphabet by storing a and A on two edges of a hexagon and the number 26 on the edge of the hexagon that touches the joint between the letters. This looks something like this:

A  / a
   |
   26

Then it enters a loops that prints the letters and then increments them, and then decrements the number. After one iteration we would have:

B  / b
   |
   25

And so on. The linear code for the initialisation is: 0x1A " A } a. The linear code for the loops outside of control flow changes is: ; ) ' ; ) { ( ' =.

Once the counter reaches zero, we follow a different path to print the numbers and an underscore. Written out linearly this is: x 3 5 6 8 4 7 9 ! ; { @. This replaces the current memory edge's value with the number 1203568479 (note that x's ASCII code is 120), which contains all of the decimal digits. We print out this number and then we use a neat feature of Hexagony: we print out the number mod 256 as an ASCII character. This just happens to be 95, or underscore.

Answered by FryAmTheEggman on January 25, 2021

PHP, 40 bytes

_0<?for(;$a++^9?$a^q:$a=A;)echo" $a"|$a;

Online Demo.

Answered by primo on January 25, 2021

Groovy, 36 characters

print(("0".."z").grep(~/w/).join())

Sample run:

bash-4.3$ groovy -e 'print(("0".."z").grep(~/w/).join())'
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz

Answered by manatwork on January 25, 2021

dc, 50 bytes

[la1+ddsaPlc>b]dddsb96saC2scx64sa90scx47sa57scx95P

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

Answered by Joe on January 25, 2021

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

Answered by Jack B on January 25, 2021

Jelly, 14 bytes

“09AZaz_”Or2/Ọ

Try it online!

Answered by Lynn on January 25, 2021

C--, 230 bytes

target byteorder little;export main;import putchar,isalnum;foreign"C"main(){bits32 v,t;v = 48;T:t=foreign"C"isalnum(v);if (t!=0){foreign"C"putchar(v);}if (v==95){foreign"C"putchar(v);}v=v+1;if (v<123){goto T;}foreign"C"return(0);}

Ungolfed:

target byteorder little;

export main;
import putchar, isalnum;

foreign "C" main(){
    bits32 v, tmp;
    v = 48;
Top:
    tmp = foreign "C" isalnum(v);
    if (tmp != 0){
        foreign "C" putchar(v);
    }

    if (v == 95){
        foreign "C" putchar(v);
    }

    v=v+1;
    if (v < 123) { goto Top; }

    foreign "C" return (0);
}

Answered by kirbyfan64sos on January 25, 2021

PHP, 74 71 bytes

echo 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_';

Answered by MonkeyZeus on January 25, 2021

brainfuck, 58 bytes

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

Try it online.

Initializes the tape to 3·2n, and works from there.

+++[[<+>->++<]>]    initialize the tape
                    |   0 |   3 |   6 |  12 |  24 |  48 |  96 | 192 | 128 |   0 |   0 |
                                                                                    ^
<<[-<->]            subract 128 from 192
                    |   0 |   3 |   6 |  12 |  24 |  48 |  96 |  64 |   0 |   0 |   0 |
                                                                        ^
<<-.+<<++           ouput '_'; increment 24 twice
                    |   0 |   3 |   6 |  12 |  26 |  48 |  96 |  64 |   0 |   0 |   0 |
                                                ^
[->>+.>+.<<<]       output aAbBcC ~ zZ
                    |   0 |   3 |   6 |  12 |   0 |  48 | 122 |  90 |   0 |   0 |   0 |
                                                ^
<--[->>.+<<]        decrement 12 twice; output 0 ~ 9
                    |   0 |   3 |   6 |   0 |   0 |  58 | 122 |  90 |   0 |   0 |   0 |
                                          ^

Answered by primo on January 25, 2021

O, 40 bytes

[[D2*(,]B6*(+{n.84*+}dC8*(C4*.9+mr]{nc}d

Answered by kirbyfan64sos on January 25, 2021

K, 21 bytes

_ci95,(97+!26),65+!26

Answered by kirbyfan64sos on January 25, 2021

ZX Spectrum, (Machine Code) 28 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
      cp "A"
      jr c,fnext ; in between ranges
      cp "Z"+1
      jr c,ok ; print A-Z
      cp "a"
      jr c,fnext ; in between ranges
ok    rst 16
fnext djnz nchar

Hexcode

067A3E5FD778FE2FC8FE3A390CFE
413809FE5B3804FE613801D710E9

Output: _zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA9876543210

Answered by Johan Koelman on January 25, 2021

C, 56 55 bytes

i;k(){for(;putchar(i%26+"aA0"[i++/26])^57;);puts("_");}

Output:

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_

Answered by o79y on January 25, 2021

Brainfuck, 89 bytes

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

Try it here

Details:

+++++++++[>+++++>+<<-]>+++.  Goes to '0' while remembering a 9 for the 9 other numbers
[<+.>-]                      Simply prints for the next 9 characters
<+++++++>                    Moves it 7 space to the letters
>+++++++++++++               Saves a 13
[<+<+.+.>>-]                 Prints 2 char at a time while making a second '13' space
<<+++++.+>                   Moves 5, prints '_' and moves to the lowercases
[<+.+.>-]                    And again the double print

If I could have commented, I would have to improve others answers. But since I can't, I might as well post my own. As I started writing this the lowest BF one was 96 long.

Answered by Robijoe on January 25, 2021

Python 2.x, 63 bytes

print''.join(chr(a)for a in range(123)if chr(a).isalnum())+'_'

Try it online.

Explanation:

chr(a)for a in range(123)if chr(a).isalnum() # generates a list iterating through ascii 
                                             #  symbols, picking just numbers alphabet characters

''.join(...)+'_'                             # joins a list of items with no spacing;
                                             # appends '_' at the end

My first golfing attempt; thanks to mbomb007 for the hints

Answered by harry on January 25, 2021

Common Lisp, 160 bytes

(setq a 47)(loop(setq a(+ a 1))(princ(code-char a))(when(and(> a 56)(< a 64))(setq a 64))(when(and(> a 89)(< a 96))(setq a 96))(when(> a 121)(return)))(princ'_)

Answered by CocoaBean on January 25, 2021

F#, 50 59 bytes

Seq.iter(printf"%c"<<char)(95::[48..57]@[65..90]@[97..122])

Output:

_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

Edit: missed the digits the first time

Edit2, inspired by this Haskell solution this F# snippet is 67 bytes.

Seq.zip"aA0_""zZ9_"|>Seq.iter(fun(x,y)->Seq.iter(printf"%c")[x..y])

Output:

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_

Answered by asibahi on January 25, 2021

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.

Answered by LegionMammal978 on January 25, 2021

Brainfuck 36 Bytes (96 commands)

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

Explanation:

 >++++++[-<++++++++>]    Increment to '0'
 +++++[<.+.+>-]          Print 10 characters (0 to 9)
 <+++++++>               Increment to lower upper characters
 +++++++++++++[-<.+.+>]  Print 26 characters (A to Z)
 <++++.++>               Increment to '_' Print it and move to a
 +++++++++++++[-<.+.+>]  Print 26 characters (a to z)

EDIT: Most straightforward solution IMHO, still shorter than the others

Answered by Hans on January 25, 2021

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.

Answered by user2428118 on January 25, 2021

Javascript (Using external library) (105 bytes)

_.Range(97,26).Concat(_.Range(65,26).Concat(_.Range(48,10))).Push(95).Write("",x=>String.fromCharCode(x))

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

Answered by applejacks01 on January 25, 2021

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)
Next
End Sub

Answered by tjb1 on January 25, 2021

Golfscript, 18 bytes

10,123,65>'[]^`'^

Answered by primo on January 25, 2021

Object Pascal, 85 83 73 bytes

Just plain object pascal using a set of chars. Writing a full program instead of a procedure shaves off 2 bytes. Removing the program keyword shaves 10 more bytes.

var c:char;begin for c in['a'..'z','A'..'Z','0'..'9','_']do write(c);end.

Answered by hdrz on January 25, 2021

Erlang, 56 bytes

f()->[X||X<-lists:seq(1,$z),re:run([X],"\w")/=nomatch].


Erlang, 57 bytes

f()->S=fun lists:seq/2,[$_|S($0,$9)]++S($A,$Z)++S($a,$z).

Answered by c.P.u1 on January 25, 2021

Perl 6

put |grep /<alnum>/,'0'..'z'
put |grep /w/,'0'..'z'

Explanation:

put # 「print()」 but with trailing newline

# turn the following into a Slip so that there aren't 
# any spaces in the output
|

grep
  /w/,      # match wordchars
  '0' .. 'z' # in this Range

( grep returns a List, which puts spaces between each element when stringified )

Answered by Brad Gilbert b2gills on January 25, 2021

Actually, 24 bytes

"[]^`""A{"Oix♂c-9ur♂$+Σ

Try it online!

There's probably a shorter way

Explanation:

"[]^`""A{"Oix♂c-9ur♂$+Σ
       "A{"O              push a list containing the ordinals of "A" and "{"
            ix            flatten the list, end-exclusive range
              ♂c          convert each ordinal into its corresponding character
"[]^`"         -         remove non-alphabetic characters except "_"
                 9ur♂$+   push range(10), convert to strings, concatenate lists
                       Σ  concatenate strings in the list

Answered by user45941 on January 25, 2021

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.

Answered by aloisdg on January 25, 2021

Sesos, 17 bytes

00000000: a854be 2cbc9e 71d597 14bc56 1ad99e 713b           .T.,..q....V...q;

Output

0123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz_

Try it online! Check Debug to see the generated binary code.

How it works

The binary file above has been generated by assembling the following SASM code.

add 48     ; Set cell 0 to 48 ('0').
fwd 1      ; Advance to cell 1.
add 10     ; Set cell 1 to 10.
jmp        ; Set an entry marker and jump to the jnz instruction.
    rwd 1  ;   Retrocede to cell 0.
    put    ;   Print its content (initially '0').
    add 1  ;   Increment cell 0 ('0' -> '1', etc.).
    fwd 1  ;   Advance to cell 1.
    sub 1  ;   Decrement cell 1.
jnz        ; While cell 1 in non-zero, jump to 'rwd 1'.
           ; This loop will print "0123456789".
rwd 1      ; Retrocede to cell 0, which holds 48 + 10 = 58.
add 7      ; Set cell 0 to 65 ('A').
fwd 1      ; Advance to cell 1.
add 26     ; Set cell 1 to 26.
jmp        ; Set an entry marker and jump to the jnz instruction.
    rwd 1  ; Retrocede to cell 0.
    put    ; Print its content (initially 'A').
    add 32 ; Add 32 to convert to lowercase ('A' -> 'a', etc.).
    put    ; Print the cell's content.
    sub 31 ; Subtract 31 to switch to the next uppercase letter ('a' -> 'B', etc.).
    fwd 1  ; Advance to cell 1.
    sub 1  ;   Decrement cell 1.
jnz        ; While cell 1 in non-zero, jump to 'rwd 1'.
           ; This loop will print "AaBb...YyZz".
rwd 1      ; Retrocede th cell 0, which holds 65 + 26 = 91.
add 4      ; Set cell 0 to 95 ('_').
put        ; Print its content.

Answered by Dennis on January 25, 2021

Haskell, 31 bytes

do(x,y)<-zip"aA0_""zZ9_";[x..y]

The expression zip "aA0_" "zZ9_" gives the list of endpoints [('a','z'),('A','Z'),('0','9'),('_','_')]. The do notation takes each (x,y) to the inclusive (x,y)->[x..y] and concatenates the results. Thanks to Anders Kaseorg for two bytes with do instead of >>=.

Compare to alternatives:

do(x,y)<-zip"aA0_""zZ9_";[x..y]

zip"aA0_""zZ9_">>= (x,y)->[x..y]
f(x,y)=[x..y];f=<<zip"aA0_""zZ9_"
id=<<zipWith enumFromTo"aA0_""zZ9_"
[c|(a,b)<-zip"aA0_""zZ9_",c<-[a..b]]
f[x,y]=[x..y];f=<<words"az AZ 09 __"

Answered by xnor on January 25, 2021

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.

Answered by Blue on January 25, 2021

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 ""

Answered by Conor O'Brien on January 25, 2021

Pure bash, 32

printf %s {a..z} {A..Z} {0..9} _

Ideone.

Answered by Digital Trauma on January 25, 2021

R

cat(letters,LETTERS,0:9,"_",sep="")

I believe this does not count as letters and LETTERS are built-in constants. But this one should be fine:

cat(intToUtf8(c(65:90,97:122)),0:9,"_",sep="")

Answered by djhurio on January 25, 2021

bash – 47 37 bytes

man sh|egrep -o \w|sort -u|tr -d \n

Output on my system is:

_0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ

Thanks to Digital Trauma for helpful suggestions.

On some systems you might be able to use ascii instead of man sh to save a byte.

Answered by user15259 on January 25, 2021

brainfuck, 105

first code golf attempt using this

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

ungolfed

>++++++[<++++++++>-]         // 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

Answered by Kevin L on January 25, 2021

PHP, 60 48 bytes

New version that's much shorter!

<?=preg_replace('/W/','',join(range(' ','z')));

Try it on Ideone

Inspired by TimmyD's solution. Takes a range of all characters from   to z, joins them into a string, then replaces all characters that match W (which is any character not specified in this challenge) with nothing.

Old version:

0123456789_<?php for($i=64;++$i<91;)echo chr($i).chr($i+32);

Ungolfed:

0123456789_
<?php 
    for($i=64;++$i<91;) echo chr($i).chr($i+32);

Anything written outside the <?php tag is considered plain text. The for loop in the PHP code echoes the uppercase and lowercase of each letter.

Answered by Business Cat on January 25, 2021

Japt, 22 bytes

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

Try it there.

Answered by nicael on January 25, 2021

Python 3, 58 bytes

print('_',*filter(str.isalnum,map(chr,range(123))),sep='')

A full program that prints to STDOUT.

The output is: _0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

How it works

map(chr,range(123))       Yield an iterator containing all ascii characters with
                          code-points in [0,122]...
*filter(str.isalnum,...)  ...keep characters if alphanumeric and unpack into tuple...
print('_',...,sep='')     ...add underscore and print all characters with no separating
                          space

Try it on Ideone

If string constants were allowed, the following would have been 45 bytes:

from string import*
print('_'+printable[:62])

Answered by TheBikingViking on January 25, 2021

My first attempt at codegolf!

C#, 168 152 150 147 130 127 117 116 115 109 106 bytes

for(var a='0';a<'~';a++){Console.Write(System.Text.RegularExpressions.Regex.IsMatch(a+"","\w")?a+"":"");}

Thanks a lot to aloisdg, AstroDan, Leaky Nun and Kevin Lau - not Kenny for all the help in comments.

Answered by Daniel on January 25, 2021

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>.

Answered by dorukayhan on January 25, 2021

C#, 85 bytes

()=>{var r="_";for(char c='/';c<'z';)r+=char.IsLetterOrDigit(++c)?c+"":"";return r;};

C# lambda where the output is a string.

A full string would be 69 bytes...

Code:

()=>{
    var r="_";
    for(char c='/';c<'z';)
        r+=char.IsLetterOrDigit(++c)?c+"":"";
    return r;
};

Try it online!

Answered by aloisdg on January 25, 2021

///, 63 bytes

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_

Answered by Erik the Outgolfer on January 25, 2021

J, 30 29 28 bytes

Saved a byte thanks to randomra!

~.u:95,;48 65 97+i."*10,,~26

Output:

   ~.u:95,;48 65 97+i."*10,,~26
_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

Explanation

I wont provide an explanation per se, but will provide intermediate results.

   10,,~26
10 26 26
   i. b. 0
1 _ _
   *  b. 0
0 0 0
   i."* b. 0
   i."*2 3 4
0 1 0 0
0 1 2 0
0 1 2 3
   i. 2
0 1
   i. 3
0 1 2
   i. 4
0 1 2 3
   i."*10,,~26
0 1 2 3 4 5 6 7 8 9  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
   0 1 2 + i."*10,,~26
0 1 2 3 4 5 6 7  8  9  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
1 2 3 4 5 6 7 8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
   48 65 97+i."*10,,~26
48 49 50  51  52  53  54  55  56  57  48  48  48  48  48  48  48  48  48  48  48  48  48  48  48  48
65 66 67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
   ;48 65 97+i."*10,,~26
48 49 50 51 52 53 54 55 56 57 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
   95,;48 65 97+i."*10,,~26
95 48 49 50 51 52 53 54 55 56 57 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 ...
   u:95,;48 65 97+i."*10,,~26
_01234567890000000000000000ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
   ~.u:95,;48 65 97+i."*10,,~26
_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

Answered by Conor O'Brien on January 25, 2021

05AB1E, 18 16 12 bytes

žyLçá9Ý'_)˜J

Explanation

žyL               # push [1..128]
   ç              # convert to char
    á             # keep only members of the alphabet
     9Ý           # push [0..9]
       '_         # push underscore
         )˜J      # add to lists of lists, flatten and join
                  # implicit output

Try it online

Edit: Saved 4 bytes thank to Adnan

Answered by Emigna on January 25, 2021

Retina, 30 19 16 15 12 bytes

I modified my original alphabet attempt for this latest version. Each character is printed in a loop.

The first line is empty.


;
+T`;w`w_

Try it online

Output:

_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

Thanks to Leaky Nun for golfing 4 bytes off my latest attempt.

Answered by mbomb007 on January 25, 2021

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!

Answered by Cowabunghole on January 25, 2021

Perl, 20 bytes

Requires -E at no extra cost.

say+a.._,A.._,_..9,_

So, my original answer (below) was a bit too boring. The only thing I've managed to come up with is the above, that's exactly the same, but looks a bit more confusing... It's pretty much exactly equivalent to the below:

say a..z,A..Z,0..9,_

I like @msh210's suggestions in the comments, but they're just a bit too long!

Answered by Dom Hastings on January 25, 2021

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 (-> ,,).

Answered by nimi on January 25, 2021

PowerShell v3+, 35 33 bytes

-join([char[]](1..127)-match'w')

Constructs a dynamic array 1..127, casts it as a char array. That's fed to the -match operator working on the regex w, which will return all elements that match (i.e., exactly alphanumeric and underscore). We encapsulate those array elements in a -join to bundle it up as one string. That's left on the pipeline and output is implicit.

Answered by AdmBorkBork on January 25, 2021

CJam, 15 14 11 bytes

4 bytes off thanks to @FryAmTheEggman and @Dennis!

A,'[,_el^'_

Try it online!

A,    e# Push range [0 1 ... 9]
'[,   e# Push range of chars from 0 to "Z" ("[" minus 1)
_el   e# Duplicate and convert to lowercase
^     e# Symmetric difference. This keeps letters only, both upper- and lower-case
'_    e# Push "_".
      e# Implicitly display stack contents, without separators

Answered by Luis Mendo on January 25, 2021

SML, 70 (lame) bytes, 80 78 71 64 bytes

I did it! The lame solution has been defeated by 6 bytes:

fun&123="_"| &91= &97| &58= &65| &n=str(chr n)^ &(n+1);print(&48)

Try it online! Better readable:

fun t 123 = "_"
  | t 91  = t 97
  | t 58  = t 65
  | t n   = str(chr(n)) ^ t (n+1);
print(t 48)

Keep reading to see past me whining about not having found this solution yet.


print"_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

The sad truth so far: I didn't manage to get something shorter than this, and believe me, I've tried.

Straight forward using build-in functions:

print("_"^implode(List.filter Char.isAlphaNum(List.tabulate(123,chr))))

Generate Char list, filter, implode (char list -> string), add _, print:

_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

Uses 71 bytes and is thereby 2 bytes to long to beat the lame solution. As more or less only keywords remain, I'm pretty sure this approach can't be golfed any further.

Let's build our own function!
This approach yielded multiple solutions of which the shortest one

fun&26a=""| &n a=str(chr(n+a))^ &(n+1)a;print(&16 32^ &0 65^ &0 97^"_")

also still needs 71 bytes. At least some a bit more interesting stuff is happening here. Let's name the function f instead of & and have closer look:

1  fun f 26 a = ""
2    | f  n a = str(chr(n+a)) ^ f (n+1) a
3  ;
4  print(f 16 32 ^ f 0 65 ^ f 0 97 ^ "_")
  • 4 f n a returns a string of 26-n consecutive ascii-chars starting at char number a. ^ concats two strings.
  • 1 Pattern matching. If the second argument is 26, return an empty string.
  • 2 Recursion: If n is not yet 26, get the current char, convert it into a string and append it to the (recursively build) rest of the string.
  • 3 Tell the interpreter that we are finished with declaring f so we can use it afterwards.

26-n? Why not do something more intuitive like

fun f 0 a = ""
  | f n a = str(chr(n+a)) ^ f (n-1) a;
print(f 10 47 ^ f 26 64 ^ f 26 96 ^ "_")

, would nobody ask here ever.

Because on the one hand this would print

9876543210ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba_

which albeit correct doesn't look very nice. However, more importantly in this case we have one 0 and two 26 and in the other case two 0 and one 26, which saves 1 byte.

Nevertheless it's still two bytes to go to underbid the infamous solution. At least for this approach remains a tiny bit of hope to achieve this goal, some time, in a brighter future ...
But probably not.

Answered by Laikoni on January 25, 2021

MATL, 11 bytes

7W:'W'[]YX

Try it online!

7W     % Push  2 raised to 7, i.e. 128
:      % Range [1 2 ... 128]
'W'   % Push string to be used as regex pattern
[]     % Push empty array
YX     % Regex replace. Uses (and consumes) three inputs: source text, regex pattern, 
       % target text. The first input (source text) is implicitly converted to char.
       % So this replaces non-word characters by nothing.
       % Implicitly display

Answered by Luis Mendo on January 25, 2021

Dyalog APL, 18 bytes

∊'w'⎕S'&'⎕UCS⍳255

prints:

0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz

Answered by Adám on January 25, 2021

Ruby, 26 bytes

Characters can be printed in any order? Don't mind if I do!

Try it online!

$><<(?0..?z).grep(/w/)*''

Answered by Value Ink on January 25, 2021

V, 27 bytes

i1122ñYpñvHgJ|éidd@"Í×

Try it online!

This answer is horribly convoluted. I'll post an explanation later.

Hexdump:

00000000: 6916 1631 1b31 3232 f159 7001 f176 4867  i..1.122.Yp..vHg
00000010: 4a7c e969 6464 4022 1bcd d7              J|.idd@"...

Explanation:

Readable:

i<C-v><C-v>1<esc>                                   "Insert the text "<C-v>1"
                                                    "<C-v> means "literal"
                 122ñ       ñ                       "122 times,
                     Yp                             "Duplicate this line
                       <C-a>                        "And increment the first number on this line
                             vHgJ                   "Join every line together
                                 |éi                "Insert an 'i' at the beginning of this line
                                    dd              "Delete this line
                                      @"<esc>       "And execute it as V code.
                                                    "That will generate every ascii value from 1-123
                                             Í×     "Now remove every non-word character.

Answered by James on January 25, 2021

Brachylog, 25 bytes

"_"w9yrcw"A":"Z"ycL@l:Lcw

This prints the following to STDOUT:

_9876543210abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ

Explanation

"_"w               Write "_"
9y                 Get the list [0:1:2:3:4:5:6:7:8:9]
  rcw              Reverse it, concatenate into one number, write
"A":"Z"y           Get the list of all uppercase letters
        cL         Concatenate into a single string L
          @l:Lcw   Concatenate L to itself lowercased and write

Answered by Fatalize on January 25, 2021

Haskell, 38 bytes

'_':['a'..'z']++['A'..'Z']++['0'..'9']

Nothing to explain here.

Answered by nimi on January 25, 2021

JavaScript (ES6), 62 bytes

_=>String.fromCharCode(...Array(123).keys()).replace(/W/g,'')

Returns 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz, so only 6 bytes shorter than a function that returns the string literal. Yes, it sucks.

Answered by Neil on January 25, 2021

Cheddar, 31 27 bytes

->97@"123+65@"91+48@"58+"_"

This showcases the @" operator well

Non-completing because I finally got aroudn to fixing the @" operator. The bug was that it was generating a Cheddar range not a JS range so it couldn't properly work


Explanation

The @" operator was designed by @CᴏɴᴏʀO'Bʀɪᴇɴ, and what it does is generate a string range from LHS to RHS. When used as an unary operator, it returns the char at the given code point (like python's chr)

Ungolfed

->
  97 @" 123 +
  65 @" 91  +
  48 @" 58  +
  "_"

Answered by Downgoat on January 25, 2021

C, 50 bytes

Call f() without any arguments.

f(n){for(n=128;--n;)isalnum(n)|n==95&&putchar(n);}

Prints

zyxwvutsrqponmlkjihgfedcba_ZYXWVUTSRQPONMLKJIHGFEDCBA9876543210

Answered by owacoder on January 25, 2021

Pyke, 13 bytes

150m.C#P)_+s

Try it here!

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

Answered by Blue on January 25, 2021

MATL, 20 bytes

95 48:57 65:90t32+vc

Try it online!

This is a very boring and straightforward answer.

Answered by James on January 25, 2021

Pyth, 13 12 bytes

s:#"w"0rk|

Try it online!

Finds all characters in U+0000 to U+007B that matches the regex /w/.

Outputs 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz.

alternative approach: 15 bytes

ssrMc4"0:A[a{_`

Try it online!

basically generates the half-inclusive ranges required: 0-:, A-[, a-{, _-`.

Answered by Leaky Nun on January 25, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP