# Print a meter of numbers to a specified limit

Given a positive integer n, output a number meter formatted like this:

                  0 1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 1 1 1 1 1 1 1 1 1 1 2


The input number is 20 in this example.

More formally, the decimal representations of the numbers are arranged vertically, from most significant digits on the last row to least significant digits at the top, using space-padding.

All numbers should be printed, and any size of number is allowed.

An example solution in Python 3 follows:

def meter(top: int):
initial = list(str(str(n).ljust(len(str(top + 1)))) for n in range(1, top + 1))
rotated = list(zip(*initial))[::-1]

return "\n".join(" ".join(n) for n in rotated)


This is Code Golf! Make the answer with the lowest bytes to win.

• I've added a more formal definition. Feel free to rollback or edit further if necessary. Commented Aug 18, 2023 at 13:00
• This is almost the same format used in advent of code, though theirs reads top down rather than bottom up. Commented Aug 18, 2023 at 18:28
• Thanks for the formalities, I didn't really know how to describe such a weird concept. Yours is more helpful. As for the advent of code, I never realized it was in there, I just wrote this for a decibel meter and thought it would be a cool Code Golf. Commented Aug 18, 2023 at 20:57

# Canvas, 4 bytes

Ｒ↶ ＊


Try it online.

Explanation:

Ｒ     # Push a list in the range [1, (implicit) input-integer],
# and implicitly print each integer on a separated newline to the Canvas
↶    # Rotate the entire Canvas 90 degrees counterclockwise
＊  # Join each character on each line of the Canvas with a space delimiter


{" "/'|+(#$x)$$1+!x}  Try it online! -10 : more straightforward (less fun?) -10 : Actual golfing courtesy of @coltim and @bstrat # JavaScript (ES6), 69 bytes Expects the input number as a string. f=(n,d=0,i=n)=>i?f(n,d,i-1)+(${i}[d]||' ')+' ':n[++d]?f(n,d)+
:''


Try it online!

# Vyxal, 40 bitsv2, 5 bytes

ɾ∩Ṙ⁋øɽ


Try it Online!

I honestly don't know how people find these obscure string overloads that I can never seem to remember.

## Explained

ɾ∩Ṙ⁋øɽ­⁡​‎‎⁪⁡⁪⁠⁪⁡⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁪‏‏​⁡⁠⁡‌⁢​‎‎⁪⁡⁪⁠⁪⁣⁪‏⁠‎⁪⁡⁪⁠⁪⁤⁪‏‏​⁡⁠⁡‌⁣​‎‎⁪⁡⁪⁠⁪⁢⁡⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁢⁪‏‏​⁡⁠⁡‌­
ɾ∩      # ‎⁡Transpose the range [1, input], treating digits as columns.
Ṙ⁋    # ‎⁢Reverse that, and join each sublist on spaces. Then, join that on newlines.
øɽ  # ‎⁣Right align that. I honestly don't know why this works. It just does.
💎


Created with the help of Luminespire.

• flagless 6 (or 5 vyncoded) Commented Aug 18, 2023 at 11:42

# Thunno 2N, 7 bytes

RðƬrðȷj


Try it online!

#### Explanation

RðƬrðȷj  # Implicit input
RðƬ      # Transpose [1..input], filling with spaces
rðȷj  # Reverse and join each on spaces
# Implicit output, joined on newlines


# Charcoal, 7 bytes

↑ＩＥＮ⟦⊕ι


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

   Ｎ    Input as a number
Ｅ     Map over implicit range
ι Current value
⊕  Incremented
⟦   Make into sublist (causes the output to be double-spaced)
Ｉ      Cast to string
↑       Print rotated 90°


# 05AB1E, 6 bytes

L€SζR»


Try it online.

Explanation:

L       # Push a list in the range [1, (implicit) input-integer]
€S     # Map each integer to a list of digits
ζ    # Zip/transpose; swapping rows/columsn,
# with a space character to fill unequal length rows
R   # Reverse this list of lists
»  # Join each inner list by spaces, and then each string by newlines
# (after which the result is output implicitly)


# sclin, 55 bytes

;1+ I>a10X>b tpose _"_\" \"rep + ; tk _ w>< n>o"map


Try it here! Takes input from the second line.

For testing purposes:

;1+ I>a10X>b tpose _"_\" \"rep + ; tk _ w>< n>o"map
20


## Explanation

Prettified code:

; 1+ I>a 10X>b tpose _ ( _ " "rep + ; tk _ w>< n>o ) map


Assuming input n:

• ; 1+ I>a range [1, n]
• 10X>b digitize (literally "convert each to base-10 digits")
• tpose _ transpose, reverse resulting lines
• (...) map map over each line...
• _ " "rep + ; tk _ left-pad with spaces to length n
• _ reverse
• " "rep + concatenate to infinite list of spaces
• ; tk take first n elements
• _ reverse again
• w>< n>o join with space and output

The (current) lack of string manipulation commands present in sclin makes it a tad unwieldy for string challenges...

# Python, 72 bytes

n=input()
*map(print,*(f'{j+1:<{len(n)}}'[::-1]for j in range(int(n)))),


Attempt This Online!

-1 thanks to @Arnauld (by switching to Python 3.8)
-5 thanks to @c-- (by using f-strings)
-12 thanks to @loopy walt (by using map rather than a for loop)

• 84 bytes using f-strings
– c--
Commented Aug 18, 2023 at 14:51
• 72 Commented Aug 19, 2023 at 6:10

# Ruby, 79 bytes

->n{(1..n).map{d=_1.digits
[" "]*(n.to_s.size-d.size)+d}.transpose.map{_1*" "}}


Attempt This Online!

• Alternate 79, maybe you can improve it? ->n{(1..n).map{_1.to_s.ljust(n.to_s.size).chars}.transpose.reverse.map{_1*" "}} Commented Aug 19, 2023 at 7:31
• 68 bytes Commented Aug 19, 2023 at 21:06
• @Jonah Very nice. That’s a very different approach from mine; you should post it as your own answer. Commented Aug 20, 2023 at 2:21

# Japt-R, 8 bytes

õs ÕÔË¬¸


Try it

# R, 82 bytes

\(n)write(t(Reduce(cbind,strsplit(format(paste(1:n),j="l"),""))[nchar(n):1,]),1,n)


Attempt This Online!

# J, 25 23 20 bytes

1j1#"#.0|.@|:1":@+i.


Try it online!

-3 thanks to doug!

• 1 ... +i. 1...n
• ":@ Each of them formatted as a string
• 0|.@|: Transposed and reversed
• 1j1#"#. Add the space padding
• Shouldn’t the most significant digit be on the bottom row?
– doug
Commented Aug 18, 2023 at 21:57
• Yep, fixed now. Thanks! Commented Aug 18, 2023 at 22:48
• FWIW, I just learned of # with complex count. I think think could be useful here.
– doug
Commented Aug 19, 2023 at 21:17
• It's a good thought but eg [:;"{1j1<@#"+0|.@|:1":@+i. is 26, and I don't see a way to beat 23 with that method. Commented Aug 19, 2023 at 21:29
• I think the idea would be to do the take rank 1 at the end. 1j1#"#.0|.@|:1":@+i.
– doug
Commented Aug 19, 2023 at 21:40

# Ruby, 68 bytes

->n{(0...s=n.to_s.size).map{|i|(0..n).map{_1.digits[i-s]||" "}*" "}}


Attempt This Online!

Inspired by Jordan's ruby answer, but different enough to merit a new post.

# Retina, 57 bytes

.+
*¶
¶
$^$.>#¶#¶
P^.+
N$.$.%
¶

~L$#+ L.{$.&}
A#


Try it online! Explanation: Based on my golf to @TwiNight's answer to Enklactify these strings to transpose the text.

.+
*¶
¶
$^$.>#¶#¶


Create a range from 1 to the input, but with the digits reversed, and each line padded with a #, and the lines separated by a line with just a #.

P^.+


Left pad everything with spaces so that it lines up.

N$.$.%


Sort all characters by their column index.

¶

~L$#+ L.{$.&}


Complete the transposition by joining everything together and then splitting by the number of #s.

A#


Remove the final line, which will always be the #s.

# Excel, 49 bytes

=MID(SEQUENCE(,A1),1+LEN(A1)-SEQUENCE(LEN(A1)),1)


Input in cell A1.

# Jelly, 6 bytes

Ṿ€z⁶ṚG


Try it online!

-2 thanks to @UnrelatedString

#### Explanation

Ṿ€z⁶ṚG  # Main link - argument n
€      # To each number in the range [1..n]:
Ṿ       #  Convert it to a string
z⁶    # Transpose using filler space
Ṛ   # Reverse this list of lists
G  # Format as a grid
# (join each on spaces, then newlines)

• For starters, there's G :P Commented Aug 20, 2023 at 23:49
• @UnrelatedString nice! Love how it says "Attempt to format z as a grid" in the docs lol Commented Aug 21, 2023 at 8:36

# jq, 68 66 bytes

-2 bytes with a better use of range

[range(.)+1|@sh/""]|transpose|map(map(.//" ")|join(" "))|reverse[]

[
range(.) + 1   # range generates 0 to n - 1; add 1
| @sh / ""     # Since numbers do not have spaces or special characters,
# @sh behaves the same as @text/tostring.
# / "" splits into an array of characters
]                # [ ... ] collects values into an array
| transpose      # transpose, filling missing values with null.
| map(
map(.//" ")  # replace null with space
| join(" ")  # join on spaces
)
| reverse[]      # most-significant digits last.
`