g | x | w | all
Bytes Lang Time Link
045AWK250911T150527Zxrs
nan230117T181459ZThe Thon
044C clang221214T042205Zl4m2
045JavaScript Node.js221213T075127Zl4m2
1816x8664 machine code221106T143502Zm90
043><>221207T142905ZEmigna
036Python 3221106T140617ZThe Thon
050C clang221107T172039Zjdt
027Julia 0.7221106T164035ZKirill L
056Excel ms365221107T105603ZJvdV
023BQN221108T223455ZDominic
01005AB1E221106T171907ZThe Thon
039Java 11221107T093351ZKevin Cr
073Go221107T141356Zbigyihsu
043jq221108T014816Zpmf
025sclin221106T145826ZMama Fun
040Haskell221107T165636ZLaikoni
061Rust221107T142858Zcorvus_1
036Ruby221106T151927ZKirill L
008Jelly221106T161356ZJonathan
073///221107T001446ZFmbalbue
012Vyxal221106T205753ZnaffetS
059Mathematica221106T195556Zhakr14
046R221106T153546ZDominic
nanFactor221106T141904Zchunes
050JavaScript Node.js221106T133736ZArnauld
030Sequences221106T142927ZThe Thon
014Charcoal221106T142505ZNeil
030Retina 0.8.2221106T141911ZNeil

AWK, 45 bytes

{for(;$1>0;printf("%c",9608-($1<0)*$1))$1-=8}

Attempt This Online!

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

R8Ap.L9616_C

Attempt This Online!

Yet another port of Jonathan Allan's Jelly answer.

C (clang), 46 44 bytes

f(*o,n){for(;*o=n>0;*o++=9608-(n<0)*n)n-=8;}

Try it online!

From jdt's solution, support 0

JavaScript (Node.js), 45 bytes

f=n=>n>8?'█'+f(n-8):Buffer([226,150,144-n])

Try it online!

52 bytes without Buffer:

f=n=>n>7?'█'+f(n-8):['▏▎▍▌▋▊▉'[n-1]]

x86-64 machine code, 18 16 bytes

AB B8 88 25 00 00 83 EE 08 77 F5 29 F0 48 AB C3

Try it online!

Following the standard calling convention for Unix-like systems (from the System V AMD64 ABI), this takes in RDI an address at which to place the result, as a null-terminated UTF-32 string, and takes the number n in ESI. The starting point is after the first byte.

In assembly:

r:  stosd           # Write EAX to the string, advancing the pointer.
f:  mov eax, 0x2588 # (Start here) Set EAX to 0x2588.
    sub esi, 8      # Subtract 8 from the input number in ESI.
    ja r            # Jump back if the number was greater than 8.
    sub eax, esi    # Subtract ESI from EAX, increasing it by 0 to 7.
    stosq   # Write RAX (the 64-bit register containing EAX) to the string,
            #  advancing the pointer. Because it's little-endian,
            #  the first 32 bits are the value of EAX, and the next 32 bits are 0
            #  (as the high bits are zeroed when operating on only EAX)
            #  to add the null terminator.
    ret             # Return.

><>, 43 bytes

:8,:1%-v
v1-"█"$>:?!
>~{8%:"█"+$?!~}>o<

Try it online!

Python 3, 43 41 36 bytes

lambda n:~-n//8*'▉'+chr(9608-n%-8)

Try it online! (Fails for n=0)

(Note: 9608 is the decimal value of 0x2588)

C (clang), 54 50 bytes

-4 bytes thanks to @Neil!

f(*o,n){for(;n>8;n-=8)*o++=9608;*o++=9616-n;*o=0;}

Try it online!

Julia 0.7, 35 32 27 bytes

!n='▐'.-diff((0:8:n)∪n)

Try it online!

Generates a range from 0 to n with step 8, and n itself force-included. Then taking the diff produces our codepoint offsets, e.g. 35 gives 8 8 8 8 3, etc. Returns character arrays.

Analogous solution in R:

R, 45 44 43 bytes

\(n)intToUtf8(9616-diff(c(0:(n/8-.1)*8,n)))

Attempt This Online!

Thanks to amelies and MarcMush for -3 and -5 on Julia and pajonk for -1 on R.

Excel (ms365), 56 bytes

enter image description here

Formula in B1:

=REPT("█",A1/8)&IF(MOD(A1,8),UNICHAR(9616-MOD(A1,8)),)

BQN, 23 bytes

@+9608+{𝕩>7?0∾𝕊𝕩-8;7-𝕩}

Try it at BQN REPL

@+9608+{𝕩>7?0∾𝕊𝕩-8;7-𝕩}
       {              }  # recursive function 𝕊 with argument 𝕩
        𝕩>7?             # if x is greater than 7
            0∾           #   prepend zero onto
              𝕊𝕩-8       #   result of recursive call with agument 𝕩-8
                  ;      # otherwise
                   7-𝕩   #   7-𝕩
      +                  # now, add the result of this to
@                        #   the null character
 +9608                   #   +9608

We could use the literal character '▉' instead of @+9608, but this would prevent the code from being encoded with the BQN single byte character system, so the UTF8-encoded code would end-up longer.

05AB1E, 14 11 10 bytes

L8ô€gŽb¶αç

Try it online! (I've put J for join in the footer, but apparently outputting a list of characters is ok)

Explained

L8ô€gŽb¶αç  # Implicit integer input          17
L           # Inclusive range                 [1, 2, ..., 17]
 8ô         # Split into groups of 8          [1, ..., 8], [9, ..., 16], [17]
   €g       # Length of each                  [8, 8, 1]
     Žb¶    # 9616
        α   # Absolute difference from 9616   [9608, 9608, 9615]
         ç  # chr of each                     ["█", "█", "▏"]
            # Implicit output

Java 11, 58 48 39 bytes

n->"█".repeat(--n/8)+(char)(9615-n%8)

-9 bytes thanks to @Neil.

Doesn't support n=0.

Try it online.

Explanation:

n->                  // Method with integer parameter and String return-type
  "█".repeat(        //  Repeat this character
             --n/8)  //  `n-1` integer-divided by 8 times
                     //  (by first decreasing `n` by 1 with `--n`)
  +(char)            //  Append an integer casted to a character:
         (9615-n%8)  //   9615 minus (`n-1` modulo 8)

Go, 91 81 73 bytes

func f(n int)(s string){
for;n>8;n-=8{s+="▉"}
s+=string(9616-n)
return}

Attempt This Online!

jq, 43 bytes

[9616-((range(1;./8)|8),(.-1)%8+1)]|implode

Try it online!

sclin, 25 bytes

O>a8/`"len"map9616- _ c>S

Try it here! Port of @Jonathan Allan's clever Jelly answer!

For testing purposes:

[8 32 33 35 246] ( ; n>o ) map
O>a8/`"len"map9616- _ c>S

Explanation

Prettified code:

O>a 8/` \len map 9616- _ c>S

Assuming input n.


sclin, 38 bytes

8/%"█"rot ** >o""Q"9616- _ c>S >o"&#

Try it here! Outputs the bars.

For testing purposes:

[8 32 33 35 246] ( ; ""n>o ) map
8/%"█"rot ** >o""Q"9616- _ c>S >o"&#

Explanation

Prettified code:

8/% "█" rot ** >o dup ( 9616- _ c>S >o ) &#

Haskell, 44 40 bytes

f n|n<9=[toEnum$9616-n]
f n='█':f(n-8)

Attempt This Online!

-4 bytes by ignoring n=0

Rust, 61 bytes

|n,r|{*r=[9608].repeat((!-n/8)as _);r.push((9615-!-n%8)as _)}

A fn(i32,&mut Vec<u32>), where the first argument is n, and r is a mutable reference to a vector where the output will be stored.

Attempt This Online!

Ruby, 46 36 bytes

->n{?█*(n/8)<<(n%8>0?9616-n%8:"")}

Attempt This Online!

A whopping 10 bytes saved by G B.

Jelly, 8 bytes

s8Ẉ⁽"s_Ọ

A monadic Link that accepts a non-negative integer and yields a list of characters.

Try it online!

How?

s8Ẉ⁽"s_Ọ - Link: integer, n   e.g. 17
 8       - eight
s        - split (implicit [1..n]) into chucks of length (8)
                                   [[1..8],[9..16],[17]]
  Ẉ      - length of each          [8,8,1]
   ⁽"s   - 9616
      _  - subtract (vectorises)   [9608,9608,9615]
       Ọ - cast to characters      ['█','█','▏']

///, 73 bytes

/d/iii//ddii/█//ddi/▉//dd/▊//dii/▋//di/▌//d/▍//ii/▎//i/▏/

Try it online!

Input is a unary.

Vyxal, 12 bytes

ɾ8ẇvL9616εCṅ

Try it Online!

Yet another port of Jonathan Allan's Jelly answer.

Mathematica, 59 bytes

FromCharacterCode[9616-Tr[1^#]&/@Range@#~Partition~UpTo@8]&

View it on Wolfram Cloud!

R, 51 49 46 bytes

\(n)intToUtf8(9616-c(rep(8,n/8),if(b<-n%%8)b))

Attempt This Online!

Still not as golfy as Kirill L's approach, unfortunately...

Factor, 66 65 64 46 bytes

[ [1,b] 8 group [ length ] map 9616 v-n vabs ]

Attempt This Online!

JavaScript (Node.js), 50 bytes

-2 thanks to @Neil

f=n=>n?Buffer([226,150,144-(q=n>7?8:n)])+f(n-q):''

Try it online!

How?

We use Buffer() to build the characters from their UTF-8 encodings.

For instance, the character with code point 9608 (0x2588) is generated with:

Buffer([226,150,136]) // 0xE2, 0x96, 0x88

That's a bit lengthy, but still shorter than the infamous String.fromCharCode(9608).

Sequences, 30 bytes

iH8/nx$\▉$""Jfh8%H?9616h-VF:

Sequences was definitely not made for this!

Explained:

iH8/nx$\▉$""Jfh8%H?9616h-VF:
iH                            // Get an integer input and store in `h`
  8/                          // Divide by 8
    n                         // Convert to integer (floor)
     x$  $                    // This many times:
       \▉                     //   Push the string "▉"
                              // Implicitly put into a list
          ""J                 // Join by empty strings
             f                // Output with no newline
              h               // Push `h`
               8%H            // Mod by 8 and store in `h`
                  ?           // If this is truthy (h != 0)
                       h      //   Push `h`
                   9616 -     //   Subtract from 9616
                         V    //   Get chr of the result
                          F   //   Output with a newline
                           :  // Else: (do nothing)

In Sequences there is no way of multiplying an integer with a string, so we have to settle for making a list of that string, repeated, and then join it by an empty string.

Also, Sequences uses the 96 printable ASCII characters as its codepage, but because we have in our code, we have to use UTF-8.

Charcoal, 14 bytes

⭆⪪×ψN⁸℅⁻⁹⁶¹⁶Lι

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

   ψ            Predefined variable null byte
  ×             Repeated by
    N           Input integer
 ⪪              Split into substrings of maximum length
     ⁸          Literal integer `8`
⭆               Map over substrings and join
             ι  Current substring
            L   Length
       ⁻        Subtract from
        ⁹⁶¹⁶    Literal integer `0x2590`
      ℅         Convert to Unicode

Retina 0.8.2, 30 bytes

.+
$*
1{1,8}
$.&
T`8-1`▉-▏

Try it online! Link includes test cases. Explanation:

.+
$*

Convert to unary.

1{1,8}
$.&

Convert groups of up to 8 to decimal.

T`8-1`▉-▏

Map digits to the appropriate Unicode character.