g | x | w | all
Bytes Lang Time Link
003Japt250410T142206ZShaggy
032AWK250410T140714Zxrs
014MATL161018T213025ZSuever
034Ruby161018T160930Zanna328p
011K oK171001T175523Zmkst
004J161019T221407Zalgorith
033JavaScript170929T170847ZDanielIn
036Groovy161019T195421ZMagic Oc
014Bash161018T161806ZDigital
082Java161019T025039ZTNT
055PHP161018T161703ZJör
047JavaScript ES6161019T075927Zedc65
047Haskell161019T075229Zarjanen
047R161019T070217ZBillywob
039C#161019T005355Zmilk
007Pyth161018T203759ZMaltysen
025Mathematica161018T175023ZJungHwan
026Perl161018T164613ZDada
090Kotlin161018T165642ZPsyduck7
011CJam161018T163803ZMartin E
00305AB1E161018T163156ZAdnan
037JavaScript ES7161018T163659ZHedi
006Jelly161018T161023ZDennis
032Python161018T161915Zxnor
049JavaScript161018T161543Zxenia
036PowerShell v2+161018T160107ZAdmBorkB
019Vim161018T161044Zudioica

Japt, 3 bytes

ùUÊ

Try it

ùUÊ     :Implicit input of array U
ù       :Left pad each element with spaces to length
 UÊ     :  Length of U

AWK, 32 bytes

{for(;i++<NF;)printf"%"NF"d",$i}

Attempt This Online!

MATL, 14 bytes

'%%%dd'inYDGYD

Try it out at MATL Online

This uses formatted string creation by first constructing the format string: %(NUM)d and then applies string formatting again using this format string and the input.

Ruby, 40 36 34 bytes

->m{m.map{|i|$><<i.rjust(m.size)}}

Can be worked on more.

Call as a lambda.

Explanation:

->m{m.map{|i|$><<i.rjust(m.size)}}
->m{                             } # lambda taking array m
    m.map{|i|                   }  # map over array using variable i
             $><<                  # output to $> (stdout)
                 i.rjust(m.size)   # right justify i to m's length

K (oK), 11 bytes

Solution:

,/(-#x)$$x:

Try it online!

Explanation:

Interpretted right-to-left. Convert to string, and left-pad with length of list, then flatten:

,/(-#x)$$x: / the solution                      | example:
         x: / save as 'x'                       |
        $   / string                            | $10 20 30 -> "10","20","30"
       $    / pad right by left                 | 5$"abc" -> "abc  "
  (   )     / do the stuff in brackets together |
    #x      / count x                           | #10 20 30 -> 3
   -        / negate                            |
,/          / flatten (concatenate-over)        | ,/" a"," b"," c" -> " a b c"

J, 4 bytes

":~#

Try it online!

Unary function taking the list of numbers on the right as an array and returning the padded string.

Here it is in use at the REPL. Note that input lines are indented three spaces.

   f=: ":~#
   f 2 3
 2 3
   f 2 10
 210
   f 1111 222 33 4
1111 222  33   4

JavaScript 33 bytes

similar to @Hedi - but the default padding is ' ', so its 4 chars less

a=>a.map(s=>s.padStart(a.length))

f=a=>a.map(s=>s.padStart(a.length))

console.log(f(["0"]))
console.log(f(["1"]))
console.log(f(["2","3"]))
console.log(f(["2","10"]))
console.log(f(["17" ,"19" ,"2"]))
console.log(f(["1000" ,"400" ,"30" ,"7"]))

Groovy, 36 Bytes

{a->a.collect{it.padLeft(a.size())}}

Takes in array of strings only, outputs array of padded strings.

Bash, 14

printf %$#d $@

Input list given at the command line.

Not much to explain here. Simply uses built-in printf facilities to do the necessary padding, based off the number of passed args:

Ideone.

Java, 83 82 bytes

a->{String s="";for(int i=a.length,j=i;i-->0;)s+="%"+j+"s";return s.format(s,a);};

Constructs a format string designed to pad the given arguments by a number of spaces equal to the length of the array. The format string is used as an argument for String.format, and the result is then returned. The functional interface can accept either a String[] or an Integer[] or similar.

Full class:

public class Test {
    public static void main(String[] args) {
        java.util.function.Function<Integer[], String> f = a -> {
            String s = "";
            for (int i = a.length, j = i; i-- > 0;)
                s += "%" + j + "s";
            return s.format(s, a);
        };

        System.out.println(f.apply(new Integer[] {0}));
        System.out.println(f.apply(new Integer[] {2, 10}));
        System.out.println(f.apply(new Integer[] {7, 8, 9, 10}));
        System.out.println(f.apply(new Integer[] {1, 33, 333, 7777}));
        System.out.println(f.apply(new Integer[] {0, 0, 0, 0, 0, 0}));
    }
}

Try it on Ideone.

-1 byte thanks to @KevinCruijssen.

PHP, 55 Bytes

<?foreach($a=$_GET[a]as$i)printf("%".count($a)."s",$i);

Pevious Version 59 Bytes

<?foreach($a=$_GET[a]as$i)echo str_pad($i,count($a)," ",0);

JavaScript (ES6), 47

Anonymous function, input: array of strings, output: array of strings
Using a recursive padding function

a=>a.map(x=>p(x),p=x=>x[a.length-1]?x:p(' '+x))

For an integer/string array as input, 49 bytes:

a=>a.map(x=>p(x),p=x=>(y=' '+x)[a.length]?x:p(y))

Test

f=
a=>a.map(x=>p(x),p=x=>x[a.length-1]?x:p(' '+x))

function update() {
  var l=I.value.match(/\d+/g)||[]
  O.textContent = f(l)
}

update()
 
<input id=I oninput='update()' value='1000,400,30,7'>
<pre id=O></pre>

Haskell, 47 bytes

k=length
f l=map(\s->replicate(k l-k s)' '++s)l

That’s a function from a list of strings to a list of strings, like the JavaScript answers. replicate allows one to get a list (Haskell strings are lists of characters) of a given size, so I use it — and the bolded assumption in the problem — to generate the padding (its length is N − <length of element>, for each element of the input list). I would have preferred to use a printf based solution rather than this one with replicate (it would have been shorter, for one thing) but the import statement kills any savings done on the function itself.

R, 47 bytes

cat(sprintf("%*.f",length(n<-scan()),n),sep="")

Reads input from stdin and uses C-style formating with sprintf. There should be some way the cat function is not needed but couldn't find a way to suppress the quotes on each element without it. If we only want start and end quotes we could use the slightly longer option:

paste0(sprintf("%*.f",length(n<-scan()),n),collapse="")

C#, 39 bytes

s=>s.ConvertAll(c=>c.PadLeft(s.Count));

Takes a List<string> and outputs a List<string>.

Explanation:

/*Func<List<string>, List<string>> Lambda =*/ s =>
    s.ConvertAll(c =>                                // Create a new List<string> by...
        c.PadLeft(s.Count)                           // ...padding each element by 'N'
    )
;

Would've been a few bytes shorter to use LINQ if the import isn't counted and then returning IEnumerable<string> instead of a full blown list:

C#, 35+18 = 53 bytes

using System.Linq;s=>s.Select(c=>c.PadLeft(s.Count));

Pyth - 7 bytes

Straightforward answer using padding builtin.

sm.[;lQ

Test Suite.

Mathematica, 25 bytes

#~StringPadLeft~Length@#&

Both input and output are lists of strings.

Explanation

Length@#

Get the length of the input (number of element).

#~StringPadLeft~...

Pad left each element in the input so that their lengths match the length of the input.

Perl, 26 bytes

-4 bytes thanks to @Ton Hospel

25 bytes of code + -a flag.

printf"%*s",~~@F,$_ for@F

Run with :

perl -ae 'printf"%*s",~~@F,$_ for@F' <<< "10 11 12"

(On some older version of Perl, you might need to add -n)

Kotlin, 90 bytes

Golfed:

fun main(a:Array<String>){a.forEach{b->for(i in 1..a.size-b.length){print(" ")};print(b)}}

Ungolfed:

fun main(a: Array<String>) {
    a.forEach { b ->
        for (i in 1..a.size - b.length) {
            print(" ")
        }
        print(b)
    }
}

CJam, 11 bytes

lS%_,f{Se[}

Try it online! (As a test suite.)

Explanation

l      e# Read input.
S%     e# Split around spaces.
_,     e# Copy and get length.
f{     e# Map this block over the list, passing in the length on each iteration.
  Se[  e#   Left-pad to the given length with spaces.
}

05AB1E, 3 bytes

Code:

Dgj

Explanation:

D    # Duplicate the input array
 g   # Get the length 
  j  # Left-pad with spaces to the length of the array

Try it online! or Verify all test cases.

JavaScript (ES7), 37 bytes

a=>a.map(v=>v.padStart(a.length,' '))

Input: Array of strings
Output: Array of strings

f=
  a=>a.map(v=>v.padStart(a.length,' '))
;
console.log(f(['0']))
console.log(f(['1']))
console.log(f(['2','3']))
console.log(f(['2','10']))
console.log(f(['4','5','6']))
console.log(f(['17','19','20']))
console.log(f(['7','8','9','10']))
console.log(f(['100','200','300','0']))
console.log(f(['1000','400','30','7']))
console.log(f(['1','33','333','7777']))
console.log(f(['0','0','0','0','0','0']))

Jelly, 7 6 bytes

L⁶xaUU

Input is an array of strings. Try it online! or verify all test cases.

How it works

L⁶xaUU  Main link. Argument: A (array of strings)

L       Yield the l, the length of A.
 ⁶x     Repeat ' ' l times.

    U   Upend; reverse all strings in A.
   a    Perform vectorizing logical AND, replacing spaces with their corresponding
        digits and leaving spaces without corresponding digits untouched.
     U  Upend; reverse the strings in the result to restore the original order of
        its digits, moving the spaces to the left.

Python, 32 bytes

lambda l:'%%%ds'%len(l)*len(l)%l

An anonymous function that takes a tuple as input. Either numbers or strings work.

Example:

l=(1,33,333,7777)

'%%%ds'
## A "second-order" format string

'%%%ds'%len(l)           -> '%4s'
## Inserts the length as a number in place of '%d'
## The escaped '%%' becomes '%', ready to take a new format argument
## The result is a format string to pad with that many spaces on the left

'%%%ds'%len(l)*len(l)    -> '%4s%4s%4s%4s'
## Concatenates a copy per element

'%%%ds'%len(l)*len(l)%l  -> '   1  33 3337777'
## Inserts all the tuple elements into the format string 
## So, each one is padded with spaces

JavaScript, 49 bytes

a=>a.map(n=>" ".repeat(a.length-n.length)+n)

Takes the arguments as a list of strings and also returns a list of strings.

Explanation:

a=>                                                   An unnamed function, which takes one argument, a
   a.map(n=>                               )          Do the following to each element n in a:
            " ".repeat(a.length-n.length)             Generate the spaces needed to justify the number
                                         +n           Append the number

PowerShell v2+, 36 bytes

param($a)$a|%{"{0,$($a.count)}"-f$_}

Takes input $a as an array of integers. Loops through them with $a|%{...}. Each iteration, uses the -format operator with the optional Alignment Component (based on $a.count) to left-pad the appropriate number of spaces. That resultant string is left on the pipeline. At end of program execution, the resulting strings are all left on the pipeline as an array.


Examples

Output is newline-separated on each run, as that's the default Write-Output at program completion for an array.

PS C:\Tools\Scripts\golfing> @(0),@(1),@(2,3),@(2,10),@(4,5,6),@(17,19,20),@(7,8,9,10),@(100,200,300,0),@(1000,400,30,7),@(1,33,333,7777),@(0,0,0,0,0,0)|%{""+($_-join',')+" -> ";(.\spaced-out-numbers $_)}
0 -> 
0
1 -> 
1
2,3 -> 
 2
 3
2,10 -> 
 2
10
4,5,6 -> 
  4
  5
  6
17,19,20 -> 
 17
 19
 20
7,8,9,10 -> 
   7
   8
   9
  10
100,200,300,0 -> 
 100
 200
 300
   0
1000,400,30,7 -> 
1000
 400
  30
   7
1,33,333,7777 -> 
   1
  33
 333
7777
0,0,0,0,0,0 -> 
     0
     0
     0
     0
     0
     0

Vim, 19 bytes

YPPG!{<C-F>|R%ri<CR>djVGgJ

Takes a list of numbers one-per-line. Relies on :set expandtab, which is popular, but not universal.

You clearly want to use :right for this. The question is how to get the number of lines onto the command line. The traditional way is :%ri<C-R>=line('$'), but all that text is long.

The shorter, more enterprising approach is to form the command line using the normal mode ! command. It involves some weird workarounds, expanding the file by 2 lines then removing them again, but it comes out 2 bytes shorter. And I'm kinda shocked the garbled command line I get (like :%ri+4!) actually works, but it does.