| Bytes | Lang | Time | Link |
|---|---|---|---|
| 045 | AWK | 250911T150527Z | xrs |
| nan | 230117T181459Z | The Thon | |
| 044 | C clang | 221214T042205Z | l4m2 |
| 045 | JavaScript Node.js | 221213T075127Z | l4m2 |
| 1816 | x8664 machine code | 221106T143502Z | m90 |
| 043 | ><> | 221207T142905Z | Emigna |
| 036 | Python 3 | 221106T140617Z | The Thon |
| 050 | C clang | 221107T172039Z | jdt |
| 027 | Julia 0.7 | 221106T164035Z | Kirill L |
| 056 | Excel ms365 | 221107T105603Z | JvdV |
| 023 | BQN | 221108T223455Z | Dominic |
| 010 | 05AB1E | 221106T171907Z | The Thon |
| 039 | Java 11 | 221107T093351Z | Kevin Cr |
| 073 | Go | 221107T141356Z | bigyihsu |
| 043 | jq | 221108T014816Z | pmf |
| 025 | sclin | 221106T145826Z | Mama Fun |
| 040 | Haskell | 221107T165636Z | Laikoni |
| 061 | Rust | 221107T142858Z | corvus_1 |
| 036 | Ruby | 221106T151927Z | Kirill L |
| 008 | Jelly | 221106T161356Z | Jonathan |
| 073 | /// | 221107T001446Z | Fmbalbue |
| 012 | Vyxal | 221106T205753Z | naffetS |
| 059 | Mathematica | 221106T195556Z | hakr14 |
| 046 | R | 221106T153546Z | Dominic |
| nan | Factor | 221106T141904Z | chunes |
| 050 | JavaScript Node.js | 221106T133736Z | Arnauld |
| 030 | Sequences | 221106T142927Z | The Thon |
| 014 | Charcoal | 221106T142505Z | Neil |
| 030 | Retina 0.8.2 | 221106T141911Z | Neil |
Thunno J, \$ 12 \log_{256}(96) \approx \$ 9.88 bytes
R8Ap.L9616_C
Yet another port of Jonathan Allan's Jelly answer.
JavaScript (Node.js), 45 bytes
f=n=>n>8?'█'+f(n-8):Buffer([226,150,144-n])
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
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.
Python 3, 43 41 36 bytes
lambda n:~-n//8*'▉'+chr(9608-n%-8)
Try it online! (Fails for n=0)
- -2 thanks to 97.100.97.109
- -5 thanks to loopy walt
(Note: 9608 is the decimal value of 0x2588)
Julia 0.7, 35 32 27 bytes
!n='▐'.-diff((0:8:n)∪n)
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)))
Thanks to amelies and MarcMush for -3 and -5 on Julia and pajonk for -1 on R.
Excel (ms365), 56 bytes
- -2 Bytes thanks to @EngineerToast
Formula in B1:
=REPT("█",A1/8)&IF(MOD(A1,8),UNICHAR(9616-MOD(A1,8)),)
BQN, 23 bytes
@+9608+{𝕩>7?0∾𝕊𝕩-8;7-𝕩}
@+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)
- -3 thanks to Sʨɠɠan
- -1 thanks to Kevin Cruijssen
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.
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}
- -10 bytes by @jdt
- -8 bytes by @Neil
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.
O>arange [0, n)8/`chunk into lengths of max 8\len mapget lengths of each chunk9616- _subtract from 9616c>Sconvert to fractional block char
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 ) &#
8/%divmod by 8"█" rot **repeat█<div part> times>ooutputdup (...) &#execute if <mod part> is truthy (i.e. greater than 0)...9616- _ c>Sconvert to fractional block char>ooutput
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.
Jelly, 8 bytes
s8Ẉ⁽"s_Ọ
A monadic Link that accepts a non-negative integer and yields a list of characters.
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 ['█','█','▏']
Mathematica, 59 bytes
FromCharacterCode[9616-Tr[1^#]&/@Range@#~Partition~UpTo@8]&
R, 51 49 46 bytes
\(n)intToUtf8(9616-c(rep(8,n/8),if(b<-n%%8)b))
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 ]
- -1 byte from Mama Fun Roll
- -1 more by taking an entirely different approach
- -18(!) by porting Jonathan Allan's amazing Jelly answer.
JavaScript (Node.js), 50 bytes
-2 thanks to @Neil
f=n=>n?Buffer([226,150,144-(q=n>7?8:n)])+f(n-q):''
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.
