R, Jarko, again
cat(diag(diag(('i'%in%'i'):(x=scan()),x%x%x)),sep='')
This differs from Jarko Dubbeldam's intended solution, but the general idea is the same: to generate 1:n
repeated 1:n
times, it leverages diag
in two different ways:
diag(matrix)
returns the diagonal of a matrix.diag(vector, nrow)
generates annrow
xnrow
matrix withvector
along the diagonal, recycling as necessary.
%x%
is the Kronecker matrix product which when applied to two numbers returns their usual product.
Finally, cat
prints the diagonal out with sep
arator ''
which results in the sequence.