J, 13 12 bytes
[$[:,1++/&i.
how
We take x
as the left arg, n
as the right. Let's take x = 8
and n = 3
for this example:
+/&i.
: Transform both args by creating integer rangesi.
, that is, the left arg becomes0 1 2 3 4 5 6 7
and the right arg becomes0 1 2
. Now we create an "addition table+/
from those two:0 1 2 1 2 3 2 3 4 3 4 5 4 5 6 5 6 7 6 7 8 7 8 9
1 +
: Add 1 to every element of this table:1 2 3 2 3 4 3 4 5 4 5 6 5 6 7 6 7 8 7 8 9 8 9 10
[: ,
: Flatten it,
:1 2 3 2 3 4 3 4 5 4 5 6 5 6 7 6 7 8 7 8 9 8 9 10
[ $
: Shape it$
so it has the same number of elements as the original, untransformed left arg[
, ie,x
:1 2 3 2 3 4 3 4