Output integers in negative order, increase the maximum integer everytime
05AB1E, 6 bytes
L€LíJJ
Try it online!
Explanation
Example input 4
L # range [1 ... input]
# STACK: [1,2,3,4]
€L # map: range
# STACK: [[1],[1,2],[1,2,3],[1,2,3,4]]
í # reverse each
# STACK: [[1],[2,1],[3,2,1],[4,3,2,1]]
J # join inner lists
# STACK: ['1','21','321','4321']
J # join list
# OUTPUT: 1213214321
JavaScript (ES6), 37 bytes
f=(n,k=1)=>k>n?n--?f(n):'':f(n,k+1)+k
Demo
f=(n,k=1)=>k>n?n--?f(n):'':f(n,k+1)+k
console.log(f(6))
Alternate method for n < 10, 34 bytes (non-competing)
f=(n,s='1')=>--n?s+f(n,++s[0]+s):s
In JavaScript, strings are immutable. Therefore, it's impossible to alter the content of the Nth character of a string s
by assigning a new value to s[N]
.
However, the expression ++s[N]
is valid and does evaluate as one would expect, even if the string remains unchanged. For instance:
++"1"[0] // equals 2
And by extension:
s = "21"
++s[0] + s // equals "321"
Jelly, 5 bytes
RRUVV
Try it online!
Formula not mine.
I suspect there is too much going on here...
[ANSWER ACCEPTED] I'd have given some 5 rep to Dennis, but this is not Reputation Exchange. Dennis showed me the VV
behavior. To my surprise, this is shorter than 05AB1E.