Print Numbers Vertically

Hello,
I am trying to figure out how I can print an array of numbers
vertically. For example

a = [ 1, 24, 546, 1000, 32, 256 ]

output (spaces optional) :

1 2 5 1 3 2
4 4 0 2 5
6 0 6
0

I need this because I’ve got a string to display horizontally and I
need to display a position number underneath each character column.
I have been thinking about how to do this but it gets complicated
quickly. So far Im thinking:

  • convert to string

  • for each digit place ( start with 1’s place go to biggest )

    • for each num
      - if has digit
      -print digit
      - else
      print space

    Any help would be appreciated.

The ouput should have each number in its own column.

Second try:

1 2 5 1 3 2
4 4 0 2 5
6 0 6
0

Chris Foley wrote:

   0
a = [ 1, 24, 546, 1000, 32, 256 ]
height = a.max.to_s.length
a.map do |num|
num.to_s.ljust(height).split(//)
end.transpose.each do |line|
puts line.join(" ")
end

Prints:
1 2 5 1 3 2
4 4 0 2 5
6 0 6
0

HTH,
Sebastian

Wow, amazing what you can learn from a solution to a simple problem like
that.
Thank you, Sebastian.