APL, 4 characters
How it works:
⎕
reads user input. As for output, APL by default prints the result from every line.
⍳n
is the integers from 1 to n
. Example: ⍳3
←→ 1 2 3
/
means replicate. Each element from the right argument is repeated as many times as specified by its corresponding element from the left argument. Example: 2 0 3/'ABC'
←→ 'AACCC'
⍨
is the switchcommute operator. When it occurs to the right of a function invoked with a single argument, the switch operator provides it as both left and right argumentmodifies its behaviour, so it either swaps the arguments (A f⍨ AB ←→ AB f A
. (It can also swap arguments:, hence "commute") or provides the same argument on both sides (A f⍨ BA ←→ BA f⍨f A
, hence "switch", but that's irrelevant toa "selfie"). The latter form is used in this solution.)
Bonus:
6-∊⌽⍳¨⍳⎕
(8 characters, thanks @phil-h)
⍳5
(iota five) is 1 2 3 4 5
.
⍳¨ ⍳5
(iota each iota five) is (,1)(1 2)(1 2 3)(1 2 3 4)(1 2 3 4 5)
, a vector of vectors. Each (¨
) is an operator, it takes a function on the left and applies it to each item from the array on the right.
⌽
reverses the array, so we get (1 2 3 4 5)(1 2 3 4)(1 2 3)(1 2)(,1)
.
∊
is enlist (a.k.a. flatten). Recursively traverses the argument and returns the simple scalars from it as a vector.