title: Blinking Lighthouses

text:
# Question
Title: Blinking Lighthouses
Lighthouses on an island have blink codes that let ships know which lighthouse they are seeing. Input should be strings of S and L. Here is a (Python) example of codes for 4 lighthouses as a list of strings:

```
['SLS', 'SLL', 'SSS', 'LSL']

```

where:

S = short ON (1 sec)
L = long ON (3 sec)

Long and short ON's are both followed by 1 sec OFF, except the last in the code, which is followed by a *7-second LONG OFF pause* to signify end of code. The code for the first lighthouse in the above example corresponds to this blink *schedule* in seconds :

1 ON, 1 OFF, 3 ON, 1 OFF, 1 ON, 7 OFF \[repeat\]

**Challenge:**

n Lighthouses come on simultaneously, each at the start of its schedule. Write a program that takes a series of blink codes (strings in the above format) and outputs the total number of seconds that *exactly* zero, one, two, three, ... n lighthouses were on at the same time *after the first hour of lighthouse operation* (So the output numbers will always total 3600.)

**Test Cases**:

```
Input -> Output
['SLS', 'SLL', 'SSS', 'LSL'] -> 1125, 890, 652, 590, 343
['S', 'L', 'SS'] -> 2250, 630, 540, 180
['SLSL', 'S'] -> 1850, 1450, 300
['SLS'] -> 2314, 1286
['SS', 'SS', 'L'] -> 2520, 360, 0, 720

```

**Rules**:

There can be one or more lighthouses (code strings).

All lighthouses come on simultaneously, each at the start of its code schedule.

Codes can be any length \>= 1 and don't have to be unique (however off-shore mayhem may ensue).

Just for clarity, the 652 in the first example is the time in seconds that *exactly* 2 lighthouse (not 2 or more) were on.

The shortest code in bytes wins ().

# Answer
# Jelly,  ~~24 22 21~~  20 bytes

```
O%9ÄṬ;Øỵ¬ṁ⁽½c)SċⱮLŻ$

```

A monadic Link that accepts the list of lists of `S` and/or `L` characters and yields the ascending list of multiplicity counts.

**Try it online!** Or see the test-suite.

### How?

```
O%9ÄṬ;Øỵ¬ṁ⁽½c)SċⱮLŻ$ - Link: lighthouse patterns, P
             )       - for each pattern in P: say, 'SLSL'
O                    -   cast to ordnials     [83,76,83,76]
 %9                  -   modulo nine          [2,4,2,4]
   Ä                 -   cumulative sums      [2,6,8,12]
    Ṭ                -   untruth              [0,1,0,0,0,1,0,1,0,0,0,1]
     ;Øỵ             -   concatenate "aeiouy" [0,1,0,0,0,1,0,1,0,0,0,1,'a','e','i','o','u','y']
        ¬            -   logical NOT          [1,0,1,1,1,0,1,0,1,1,1,0,0,0,0,0,0,0]
                                              (the "full-pattern" of this lighthouse)
          ⁽½c        -   3600
         ṁ           -   (full-pattern) moulded-like (3600) -> above repeated to length 3600
              S      - sum (vectorises) -> counts at each second
                   $ - last two links as a monad, f(P):
                 L   -   length of P
                  Ż  -   zero-range -> [0..length(P)]
                Ɱ    - for each n in [0..length(P)]:
               ċ     -   count occurrences of n in the counts at each second

```
> 5 votes

# Answer
# 05AB1E, 25 bytes

```
ε€C9%Å10.ý˜7Å0«60n∍}øOZÝ¢

```

Try it online!

```
ε                  }        # for each lighthouse in the implicit input:
 €C                         #   convert each character from binary
   9%                       #   modulo 9: S -> 28 %9 = 1, L -> 21%9 = 3
     Å1                     #   for each number in the resulting list get a list of that many 1's
       0.ý                  #   intersperse with 0's
          ˜                 #   flatten into a list of 1's and 0's
           7Å0«             #   append 7 0's
               60n∍         #   extend the list to length 60^2=3600 by cycling the values
                    ø       # after the loop: transpose the list of lists
                     O      # sum every one of the 3600 sublists
                      ZÝ    # get the range [0 .. max(a)]
                        ¢   # for each value in the range, count occurences in the long list

```

Try the `S/L` to `0/1` conversion with step-by-step output: Try it online!
> 3 votes

# Answer
# , 60 53 52 bytes

```
_1+(0,#\)#/.~@,[:+/(3600$(6$0),~&;19<@#:@|14+3&u:)&>

```

Try it online!

-7 after reading Jonathan Allen's idea of doing arithmetic on the character codes, though I use a different method which converts S to 2 and L to 14, and then converts those to binary.

## idea

* For each pattern, convert it into a bitmask where 1 is on, 0 is off
* Extend that bitmask cyclically to 3600. Now we have an `n x 3600` matrix.
* Sum columns. Now we have the numbers 0-n, each some number of times.
* Prepend the numbers 0-n to that list, in case any happen to be missing, and so the result will be ordered from 0 to n.
* Group and count.
* Subtract 1 from each count.
> 2 votes

# Answer
# JavaScript (ES6), 113 bytes

Expects an array of strings. Returns an object.

```
a=>(n=3600,g=L=>n--?g(o[a.map(s=>t+=~~(s=s.replace(/./g,c=>c>g?10:1110))[n%(s.length+6)],t=0),t]=-~o[t]):o)(o={})

```

Try it online!
> 2 votes

# Answer
# Python 2, ~~125~~ 117 bytes

```
lambda a:map(map(sum,zip(*[sum([2*(c<'S')*[1]+[1,0]for c in C],[0]*6)*500for C in a]))[6:3606].count,range(len(a)+1))

```

-8 thanks to Jonathan Allan.
> 1 votes

# Answer
# Python 3, 154 bytes

Very trivial approach: convert the code strings into sequences of 1s and 0s representing the seconds in which each lighthouse is ON or OFF; then cumulate the sum of seconds depending on how many lighthouses are on at the same time.

```
def f(h):
 t=[0]*(len(h)+1)
 for i in range(3600):t[[c[i]for c in[(x.replace('S','10').replace('L','1110')+'0'*6)*450for x in h]].count('1')]+=1
 print(t)

```

Try it online!

---

*Un-golfed function with comments*

```
def f(lighthouses):
    """
    function that takes as input the list of lighthouses' blink codes
    """

    # replace in the codes 'S' and 'L' with '1's
    # corresponding to the effective ON duration in seconds
    # '0' is needed for the OFF separation period
    lighthouses = [x.replace('S', '10') for x in lighthouses]
    lighthouses = [x.replace('L', '1110') for x in lighthouses]

    # LONG OFF period
    # only 6s because one '0' is already added on the last character
    lighthouses = [x + '0'*6 for x in lighthouses]

    # repeat the sequence for at least 1h
    # minimum code duration 'S' = 8s
    # 3600/8=450 then repeat 450 times to be sure to have at least 1h
    lighthouses = [x * 450 for x in lighthouses]

    # initialize the list to keep the total number of seconds
    tot = [0] * (len(lighthouses) + 1)

    # loop over 1h of repeated sequences
    for i in range(3600):

        # increase the counter
        # the index corresponds to how many lighthouses are ON at the same time
        # counting how many '1's there are at a given position in all the sequences
        tot[[c[i] for c in lighthouses].count('1')] += 1

    # outputs the list with total seconds
    print(tot)

```
> 1 votes

# Answer
# , ~~119~~ 116 bytes

*Edit: -3 bytes thanks to Giuseppe*

```
function(a)table(c(rowSums(sapply(a,function(x)!1:3600%in%cumsum(rep(c(utf8ToInt(x)%%9,!!1:6),999)))),0:sum(a>0)))-1

```

Try it online!
> 1 votes

# Answer
# Nibbles, 24 bytes

```
.:0,,$,`?.`'.@<3600^~:+.$.\`,%$9`$$.,6 0+$@

```

Attempt This Online!

This program is a bit complicated.

```
.:0,,$,`?.`'.@<3600^~:+.$.\`,%$9`$$.,6 0+$@
.                                           For each
 :0,                                         n from 0 to
    ,                                         length
     $                                         input
      ,`?                                    number of occurences
                                          @   of n in
         .                              +$     sum each sublist of
          `'                                    transpose
            .                                    for each
             @                                    blink code from the input
              <3600                               take the first 3600 items of
                   ^~                              repeat infinitely
                     :                              join
                      +                              concatenate
                       .                              for each
                        $                              letter from the blink code
                         .      `$$                     sign of each number in
                          \                              reversed
                           `,                             range from 0 up to (excluding)
                             %$9                           the letter modulo 9
                                   .,6 0             with six zeroes

```
> 1 votes

# Answer
# Vyxal, `AB` 37 bytes

```
:ƛ`SL`⟨₀|1110⟩Ŀ\06εJṅÞċ60²Ẏv⌊;∑$Lʀ¨VO

```

The first start may be slow (or time-off) due to the use of the infinite lazy list, but then everything works well

Try it Online!
> 1 votes

# Answer
# Charcoal, 32 bytes

```
ＩＥ⊕Ｌθ№Ｅ³⁶⁰⁰Σ⭆θ§⁺⪫Ｅν×1∨⁼πS³0×0⁷λι

```

Try it online! Link is to verbose version of code. Explanation: For each number of "on" lighthouses and each second of the hour, calculate the "on" pattern for each lighthouse and count how many of the seconds had that number of lighthouses "on".

```
    θ                               Input array
   Ｌ                                Length
  ⊕                                 Incremented
 Ｅ                                  Map over implicit range
       ³⁶⁰⁰                         Literal `3600` (seconds)
      Ｅ                             Map over implicit range
             θ                      Input array
            ⭆                       Map over elements and join
                  ν                 Current blink code
                 Ｅ                  Map over characters
                    1               Literal string `1`
                   ×                Repeated by
                       π            Current character
                      ⁼             Equals
                        S           Literal string `S`
                     ∨              Logical Or
                         ³          Literal `3`
                ⪫                   Join with
                          0         Literal string `0`
               ⁺                    Concatenated with
                            0       Literal string `0`
                           ×        Repeated by
                             ⁷      Literal `7`
              §                     Indexed by
                              λ     Current second
           Σ                        Sum i.e. count of "on" lighthouses
     №                              Count of
                               ι    Outer index
Ｉ                                   Cast to string
                                    Implicitly print

```
> 0 votes

# Answer
# Wolfram Language (Mathematica), 119 bytes

```
Rest@BinCounts@Total[PadRight[#,3600,#]&/@(Flatten@Join[Characters[#]/.{"S"->{1,0},"L"->{1,1,1,0}},Array[0#&,6]]&/@#)]&

```

Try it online!

Seems similar to others (yet DIY and worse), but I couldn’t get past the challenge with the word "Lighthouse" 8)
> 0 votes

---
Tags: code-golf, string, array, arithmetic
---


title: Advanced Binary Number System

text:
# Question
Title: Advanced Binary Number System
Your task is to write a program that calculates the amount of different ways to display any given whole positive number using the following rules:

Meet the 'advanced binary system':

Any whole positive number can be displayed in binary form, but each bit can have every number from 0 to 9. This means, a valid number might look like this: **480** and would be calculated to 4 * 2^2 + 8 * 2^1 + 0 * 2^0 = 32. You see, every 'bit' is multiplied with 2 to the power of the significance of the bit, just like in binary but with 10 (0 to 9) different possible bits instead of 2 (0 and 1).

It is given a whole positive decimal number in any kind of form. This can be text input, a variable value, an array element, etc. Then your program calculates in how many ways (using the number format explained above. Leading zeroes obviously do not count) the inputted decimal number can be displayed. The result should then be returned, printed or drawn in any readable way as a decimal number.

Examples:

Input: 3 -\> Output: 2 \> Reason: the decimal number 3 can be displayed as 11 (1 * 2^1 + 1 * 2^0) and as 3 (3 * 2^0), thus 2 different possibilities

Input: 1 -\> Output: 1 \> Reason: the only possibility is 1 (1 * 2^0)

Input: 2 -\> Output: 2 \> Reason: possibilities are 10 and 2

And so on.

This is code golf: program with least amount of bytes wins!

**Test cases**

The first 30 values are:

```
1, 2, 2, 4, 4, 6, 6, 10, 10, 13, 13, 18, 18, 22, 22, 30, 30, 36, 36, 45, 45, 52, 52, 64, 64, 72, 72, 84, 84, 93

```

# Answer
# Python 2, 45 bytes

Based on the conjectured formula presented in OEIS A309616.

```
f=lambda n:n<2or-f(n/2-5)*(n>9)+f(n-2)+f(n/2)

```

Try it online!
> 8 votes

# Answer
# Python, 53 bytes

```
f=lambda n:sum(f(k)for k in range(n)if~9<2*k-n<1)or 1

```

Try it online!

The `if` condition is golfed from `0<=n-2*k<=9`.

---

# Python, 46 bytes

```
f=lambda n:sum(map(f,range(n//2+1)[-5:n]),n<1)

```

Try it online!

*-2 by dingledooper*
> 7 votes

# Answer
# Jelly, 6 bytes

```
BḌRDḄċ

```

Try it online!

## How it works

For the input \\$x\\$, we generate the range \\$\[1, n\]\\$, where \\$n\\$ is the binary representation of \\$x\\$, treated as decimal. For example: \\$x = 3\\$ yields \\$n = 11\\$ and \\$x = 6\\$ yields \\$n = 110\\$. We then convert each number in this range to its decimal digits, convert them back to binary, and count the occurrences of \\$x\\$.

We use the fact that Jelly's base converter doesn't care about the digit values, and simply sums up \\$a \times b^n\\$ for digit \\$a\\$, base \\$b\\$ and position \\$n\\$.

```
BḌRDḄċ - Main link. Takes x on the left
B      - Convert x to binary
 Ḍ     - Treat this binary representation as a base 10 number, n
  R    - Range from 1 to n
   D   - Convert each to digits
    Ḅ  - Convert the digits to binary
     ċ - Count occurrences of x

```
> 6 votes

# Answer
# Vyxal, 5 bytes

```
↵2vβO

```

Try it Online!

Times out after default time online for anything over 4, times out for all inputs over 5 after maximum time.

Kind of similar to caird's jelly answer but much slower.

## Explained

```
↵2vβO
↵      # 10 to the power of the input - this will always be longer than the binary representation of the input
 2vβ   # convert each item in the range [1, that] to base 2 - the base converter just happens to be nice with digits greater than the base.
    O  # Count how many items in that list are equal to the input

```
> 4 votes

# Answer
# JavaScript (ES6), 35 bytes

Based on the OEIS formula found by dingledooper.

```
f=n=>n<2?n>=0:f(n-2)+f(n/=2)-f(n-5)

```

Try it online!
> 4 votes

# Answer
# Swift:

# \- 187 bytes (standalone program)

# \- 66 bytes (function f)

(The question asks for a "program" so providing it as a program.)

```
import Darwin.C.stdlib
guard let x=CommandLine.arguments.dropFirst().first,let n=Int(x) else {exit(1)}
func f(_ n:Int)->Int{n<1 ?n==0 ?1:0: n%2==0 ?f(n-1):f(n/2)+f(n-1)}
print("\(f(n))")

```

Try it online!

To get multiple output for a range:

```
print("\((0...100).map(f))")

```

Notes:

* not that it matters for the sake of this contest, but the compiled & optimized standalone Swift program for arm64 macOS 11+ is 134,440 bytes, and can be downloaded here for inspection; this might seem large but not when you consider that it requires no dependency to be installed also, such as a Python, Java, or Javascript runtime (Swift compiles in a manner similar to C or C++)
* if you have Swift installed (for linux/windows/Mac) you can just use the function (and not the full program) directly in the Swift REPL as you would use a function in the Python REPL etc.

The algorithm used is Michael Somos' Haskell answer above for the OEIS sequence.
> 4 votes

# Answer
# Charcoal, 14 bytes

```
ＮθＩ№Ｅ⊕⍘θ²⍘Ｉι²θ

```

Try it online! Link is to verbose version of code. Explanation: Port of @caird's Jelly answer.

```
Ｎθ              Input `n` as a number
       θ        Input `n`
      ⍘ ²       Convert to a string in base `2`
     ⊕          Increment in base `10`
    Ｅ           Map over implicit range
           ι    Current value
          Ｉ     Cast to string
         ⍘  ²   Interpret as base `2`
   №            Count occurrences of
             θ  Input `n`
  Ｉ             Cast to string
                Implicitly print

```

I tried to solve this myself but I ended up with a 21 byte port of @xnor's Python answer but using dynamic programming instead of recursion:

```
⊞υ¹ＦＮ⊞υΣΦυ¬÷⁻⊕ι⊗λχＩ⊟υ

```

Try it online! Link is to verbose version of code. Explanation:

```
⊞υ¹

```

Start with `1` way to produce `0`.

```
ＦＮ

```

Repeat `n` times.

```
⊞υΣΦυ¬÷⁻⊕ι⊗λχ

```

Get the counts at `n/2`, `n/2-2` ... `n/2-8` and take their sum to produce the next count.

```
Ｉ⊟υ

```

Output the final count.
> 3 votes

# Answer
# C (gcc), <sup>~~42~~ ~~39~~</sup> 37 bytes

```
f(n){n=n<1?!n:f(n-2)+f(n/=2)-f(n-5);}

```

Try it online!

*Port of Arnauld's JavaScript answer based on dingledooper's Python answer!!!*
*Saved 3 bytes thanks to jdt!!!*
*Saved 2 bytes thanks to alephalpha!!!*
> 3 votes

# Answer
# Fig, \\$10\log\_{256}(96)\approx\\$ 8.231 bytes

```
IxeBefa_Ob

```

Try it online!

Port of caird's Jelly answer.
> 3 votes

# Answer
# Desmos, 75 bytes

```
f(n)=∑_{k=0}^{10^N}0^{(n-∑_{j=0}^Nmod(floor(k/10^j),10)2^j)^2}
N=log_2n

```

Try It On Desmos!

Try It On Desmos! - Prettified

We can golf some bytes, but it'll be super slow (it can't calculate values any higher than around \\$n=6\\$ in a reasonable amount of time.):

### 66 bytes

```
f(n)=∑_{k=0}^{10^n}0^{(n-∑_{j=0}^nmod(floor(k/10^j),10)2^j)^2}

```

Try It On Desmos!
> 3 votes

# Answer
# PARI/GP, 35 bytes

```
f(n)=if(n<1,!n,sum(i=0,4,f(n\2-i)))

```

Attempt This Online!

A port of @xnor's Python answer.

---

# PARI/GP, 42 bytes

```
n->sum(i=1,n^4,fromdigits(digits(i),2)==n)

```

Attempt This Online!

A port of @lyxal's Vyxal answer, but uses the upper bound \\$n^4\\$.

In fact, when \\$n\>2\\$, `fromdigits(digits(n,2),10)` \\$\le 10/9\times10^{\log\_2 n}=10/9\times(10^{1/\log2})^{\log n}\<(10/9\times10^{1/\log2})^{\log n}\<(e^4)^{\log n}=n^4\\$. It's easy to see that this is also true when \\$n=1,2\\$.

---

# HOPS, 28 bytes

```
A=1-x^9+x*A+(x-x^11)*A@(x^2)

```

Attempt This Online!

This is not a challenge. I cannot use the IO convention for . But it is still fun to find the generating function. So I won't post this in another answer.

The generating function of this sequence satisfies \\$B(x)=(1-x^{10})B(x^2)/(1-x)\\$. But we cannot determine the constant term of \\$B(x)\\$ from this equation.

We know that this constant term is \\$1\\$. Let \\$B(x)=1+x A(x)\\$, then we have \\$1+x A(x)=(1-x^{10})(1+x^2A(x^2))/(1-x)\\$, whence \\$A(x)=1-x^9+x A(x)+(x-x^{11})A(x^2)\\$.
> 2 votes

# Answer
# 05AB1E, 5 bytes

```
bLCI¢

```

Try it online or verify all test cases.

**Explanation:**

```
b      # Convert the (implicit) input-integer to binary
 L     # Pop and push a list in the range [1,binary(input)]
  C    # Interpret each integer as binary, and convert it to a base-10 integer
   I¢  # Count how many times the input occurs in this list
       # (which is output implicitly as result)

```
> 2 votes

# Answer
# Ruby, ~~40~~ 37 bytes

```
f=->n{n<1?1:(0..n/2).last(5).sum(&f)}

```

Try it online!

Based on xnor's answer.
> 2 votes

# Answer
# Pyt, 6 bytes

```
Đɓř2Ĩɔ

```

Try it online!

Port of caird coinheringaahing's Jelly answer

```
Đ           implicit input; Đuplicate
 ɓ          convert to ɓinary (automatically casted to decimal number)
  ř         řangify
   2Ĩ       interpret each element of the array as a base-2 Ĩnteger
     ɔ      ɔount occurrences of input in array; implicit print

```
> 2 votes

# Answer
# Japt `-x`, 10 bytes

```
ôÂ¢@¶Xì ì2

```

Try it
> 1 votes

---
Tags: code-golf, number, number-theory, binary
---


title: Tips for golfing in Scratch

text:
# Question
Title: Tips for golfing in Scratch
Scratch is a visual programming language. For the sake of counting bytes, Scratch is usually written in scratchblocks2 syntax.

Post tips that specifically apply to Scratch or scratchblocks2.

# Answer
> 4 votes
## Abuse the bool type

In Scratch the true and false values are equivalent to 0 and 1, so you can perform arithmetic operations over them. A practical example would be finding the sign of a number:

```
define f(n
set[r v]to(<(n)>(0)>-<(n)<(0

```

# Answer
> 3 votes
# Use a Function if Possible

Where possible, if the challenge says functions are allowed, use them! The syntax for defining a function is almost always shorter than the usual `when gf clicked`.

For example:

```
define f(n
say((n)+(1

```

Over:

```
when gf clicked
ask()and wait
say((answer)+(1

```

This also means one doesn't have to use the `answer` variable, which is quite longer than `n`.

# Answer
> 3 votes
# Alternatives to Ternary "if...else" operators

As of the time this answer is posted, Scratch lacks a ternary operator. If we had one, it'd have looked like this:

However, we can use a workaround with this:

In sb syntax (22 bytes):

```
((x)*<>)+((y)*<not<>>)

```

Make sure to replace `x` and `y` with the values for when the boolean is true and when it's false. The booleans may be empty here, but when using it should have the same conditions.

~~Besides, this only works when `x` and `y` are numbers. Currently this fails with strings.~~ See edit.

This also works because of https://codegolf.stackexchange.com/a/198744/110681

**EDIT:** you could use our invented ternary operator with a `(item()of[ v])` to index a number into the list, depending on the truth value of the boolean.

**EDIT:** To get single character results, Jacob has commented on his version, which is 20 bytes (replace `<>` with your boolean):

```
letter((1)+<>)of[ab]

```

However, notice that this doesn't work for emojis or Unicode characters, and they will return  if you try using them.

# Answer
> 2 votes
## Brackets auto-complete

In the scratchblocks3 visual syntax (backwards-compatible with scratckblocks2 syntax), you can auto-complete the brackets.

E.g. The hello, world program:

```
when gf clicked
say[hello, world]

```

Can be golfed into:

```
when gf clicked
say[hello, world

```

In addition, the end statement of switching structures is auto-completed at the end. So instead of

```
define f(n
set[i v]to(1
set[o v]to(
repeat(length of(n
repeat((2)-((i)mod(2
set[o v]to(join(o)(letter(i)of(n
end
change[i v]by(1

```

You could do (-4 bytes)

```
define f(n
set[i v]to(0
set[o v]to(
repeat(length of(n
change[i v]by(1
repeat((2)-((i)mod(2
set[o v]to(join(o)(letter(i)of(n

```

# Answer
> 1 votes
# Output via a variable or list, not `say`

The previous consensus for output in Scratch was that you had to `say` the output. However, this doesn't really make sense, since variables are automatically displayed in Scratch if not unchecked in the interface, just as `say` is automatically displayed if the sprite is not checked as hidden.

Now, per this consensus, it's allowed to just output by writing a global variable, which can in some cases save many bytes.

For example, this (meaningless) code:

```
repeat(10
change[i v]by(1
if<(i)>5>then
set[a v]to((i)*(2
end
end
say(a

```

Can become just:

```
repeat(10
change[i v]by(1
if<(i)>5>then
set[a v]to((i)*(2

```

---
Tags: code-golf, tips
---


# Question
Title: Print all alphanumeric characters plus underscore
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>
```

# Answer
> 12 votes
## 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
'_          _

```

# Answer
> 16 votes
# Ruby, 26 bytes

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

Try it online!

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

```

# Answer
> 11 votes
## 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!

# Answer
> 10 votes
## 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.

# Answer
> 10 votes
## Haskell, 38 bytes

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

```

Nothing to explain here.

# Answer
> 9 votes
# 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  +
  "_"

```

# Answer
> 9 votes
## 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 |
                                          ^

```

# Answer
> 8 votes
# 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.

```

# Answer
> 8 votes
# 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

```

# Answer
> 7 votes
## 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.

# Answer
> 7 votes
## 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 __"

```

# Answer
> 5 votes
# Pascal (FPC), ~~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.

```

Try it online!

# Answer
> 4 votes
# 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-{, _-``.

# Answer
> 4 votes
# C, 50 bytes

Call `f()` without any arguments.

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

```

Prints

```
zyxwvutsrqponmlkjihgfedcba_ZYXWVUTSRQPONMLKJIHGFEDCBA9876543210

```

# Answer
> 4 votes
# 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.*

# Answer
> 4 votes
# ///, 63 bytes

```
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_

```

# Answer
> 4 votes
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.

# Answer
> 4 votes
# 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])

```

# Answer
> 4 votes
# 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.

# Answer
> 4 votes
# Pure bash, 32

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

```

Ideone.

# Answer
> 4 votes
# 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.

```

# Answer
> 4 votes
## PHP, 40 bytes

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

```

Online Demo.

# Answer
> 3 votes
# 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

```

# Answer
> 3 votes
# Dyalog APL, 18 bytes

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

```

prints:

```
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz

```

# Answer
> 3 votes
# 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

```

# Answer
> 3 votes
# 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

```

# Answer
> 3 votes
## 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

# Answer
> 3 votes
# 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.

# Answer
> 3 votes
# 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_

```

# Answer
> 3 votes
## 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.

# Answer
> 3 votes
# Hexagony, 33

```
"A}_8_47<='>({a/_x.@.9!\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.

# Answer
> 3 votes
# 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

```

# Answer
> 3 votes
# , 40 bytes

Inspired by this answer.

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

```

Try it online!

# Answer
> 3 votes
# 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:

# Answer
> 3 votes
# 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

```

# Answer
> 3 votes
# 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

```

# Answer
> 3 votes
# Python 3, 69 bytes

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

```

Try it online!

Nice

# Answer
> 2 votes
## Pyke, 13 bytes

```
150m.C#P)\_+s

```

Try it here!

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

# Answer
> 2 votes
# 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!

# Answer
> 2 votes
## Golfscript, 18 bytes

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

```

# Answer
> 2 votes
# 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*.

# Answer
> 2 votes
# 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.

# Answer
> 2 votes
## 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`

# Answer
> 2 votes
# Jelly, 14 bytes

```
“09AZaz_”Or2/Ọ

```

Try it online!

# Answer
> 2 votes
# Lua, 64 bytes

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

```

Try it online!

# Answer
> 2 votes
# , 5 bytes

```
¬ ~Ó×

```

Try it online!

### Explanation

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

```

# Answer
> 2 votes
# K, 28 bytes

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

```

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

# Answer
> 2 votes
# 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`.

# Answer
> 2 votes
# APL (Dyalog Extended), 12 bytes

Full program.

```
'_',∊⍳¨'zZ9'

```

Try it online!

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

**ϵ**nlist (flatten)

`'_',` prepend an underscore

# Answer
> 2 votes
# 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.

# Answer
> 2 votes
# 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!

# Answer
> 2 votes
# 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>`

# Answer
> 2 votes
# 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

# Answer
> 2 votes
# 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 `'`).

# Answer
> 1 votes
# MATL, 20 bytes

```
95 48:57 65:90t32+vc

```

Try it online!

This is a very boring and straightforward answer.

# Answer
> 1 votes
## 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.*

# Answer
> 1 votes
## 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 (-\> `,,`).

# Answer
> 1 votes
# 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!

# Answer
> 1 votes
# 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>`.

# Answer
> 1 votes
# Japt, 22 bytes

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

```

Try it there.

# Answer
> 1 votes
## 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.

# Answer
> 1 votes
# 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 ""

```

# Answer
> 1 votes
# 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.

# Answer
> 1 votes
# 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

# Answer
> 1 votes
# 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'_)

```

# Answer
> 1 votes
# 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

# Answer
> 1 votes
# C, ~~56~~ 55 bytes

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

```

Output:

```
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_

```

# Answer
> 1 votes
# K, 21 bytes

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

```

# Answer
> 1 votes
# O, 40 bytes

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

```

# Answer
> 1 votes
# 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);
}

```

# Answer
> 1 votes
# Groovy, 36 characters

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

```

Sample run:

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

```

# Answer
> 1 votes
# Julia, 35 bytes

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

```

Alternative solution, also 35 bytes:

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

```

# Answer
> 1 votes
# 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

```

# Answer
> 1 votes
# SmileBASIC, 52 bytes

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

```

# Answer
> 1 votes
# 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~~

# Answer
> 1 votes
# 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,'_')

```

# Answer
> 1 votes
## 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])

```

# Answer
> 1 votes
# Japt, ~~13~~ 12 bytes

```
;C+B+9ô ¬+'_

```

Try it online!

# Answer
> 1 votes
## Keg, 15B(The Keg SBCS is in Keg wiki.)

```
\_\0\9ɧZAɧzaɧ(,

```

Explanation:

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

```

TIO

# Answer
> 1 votes
### x86\_16 machine code - 57 bytes

```
B4 0E         MOV AH, 0EH
        LOWERCASE:
B0 61         MOV AL, "a"
8A D8         MOV BL, AL
CD 10         INT 10H
           LOOP1:
FE C0         INC AL
CD 10         INT 10H
3C 7A         CMP AL, "z"
74 02         JE UPPERCASE
75 F6         JNE LOOP1
        UPPERCASE:
8A C3         MOV AL, BL
24 DF         AND AL, 0DFH
CD 10         INT 10H
           LOOP2:
FE C0         INC AL
CD 10         INT 10H
3C 5A         CMP AL, "Z"
74 02         JE NUMBER
75 F6         JNE LOOP2
          NUMBER:
B0 30         MOV AL, "0"
CD 10         INT 10H
           LOOP3:
FE C0         INC AL
CD 10         INT 10H
3C 39         CMP AL, "9"
74 02         JE UNDERSCORE
75 F6         JNE LOOP3
       UNDERSCORE:
B0 5F         MOV AL, "_"
CD 10         INT 10H
            EXIT:
B8 4C00       MOV AX, 4C00h
CD 21         INT 21H

```

Running with DOSBox :

# Answer
> 1 votes
# Stax, 7 bytes

```
ë½óG╨}S

```

Run and debug it

# Answer
> 1 votes
# JavaScript (Node.js), 51 bytes

```
f=n=>n>>8?'':(/\w/.test(c=Buffer([n]))?c:'')+f(-~n)

```

Try it online!

Trivial one

# Answer
> 1 votes
# Noether, 35 bytes

```
65~a26(a`+BPa`32++BP!`)10(zP!z)95BP

```

Try it online!

# Answer
> 1 votes
# Factor, 41 bytes

```
"Aa0_""   \0"[ dupd + [a,b] write ] 2each

```

Attempt This Online!

# Answer
> 1 votes
# Regenerate `-as ""`, 12 bytes

```
[0-9A-Z_a-z]

```

Attempt This Online!

If Regenerate supported character class shortcuts, then `\w` would work as a 2-byte solution.

# Answer
> 1 votes
# Dyalog APL, 27 bytes

```
'_',⎕UCS∊47 64 96+⍳¨10,2⍴26

```

# Answer
> 0 votes
# 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

```

# Answer
> 0 votes
## 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="")

```

# Answer
> 0 votes
## 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

```

# Answer
> 0 votes
# 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 )

# Answer
> 0 votes
# 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).`

# Answer
> 0 votes
# 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

```

# Answer
> 0 votes
## 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

# Answer
> 0 votes
# PHP, ~~74~~ 71 bytes

```
echo 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_';

```

# Answer
> 0 votes
# 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

# Answer
> 0 votes
# 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

```

# Answer
> 0 votes
# RETURN, 20 bytes

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

```

`Try it here.`

Creates a series of charcode ranges and outputs them.

# Answer
> 0 votes
# , 10 chars / 13 bytes

```
Ⓒ…⩥ṻ)ŋ/\W⌿

```

`Try it here (ES6 browsers only).`

Translated roughly to ES6:

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

```

# Answer
> 0 votes
# 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.

# Answer
> 0 votes
## QBIC, ~~66~~ 41 bytes

Had some coffee and re-read the specs:

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

```

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

```
[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_`

```

# Answer
> 0 votes
# 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.

# Answer
> 0 votes
# 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!

# Answer
> 0 votes
# 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>
```

# Answer
> 0 votes
# 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

```

# Answer
> 0 votes
# \>\<\>, 39 bytes

```
"AaZ_"o\9: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.

# Answer
> 0 votes
# Thunno `J`, \\$12\log\_{256}(96)\approx\\$ 10 bytes

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

```
123RCJ"\w"Af

```

Attempt This Online!

#### Explanation

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

```

---
Tags: code-golf, kolmogorov-complexity
---