Skip to main content
Commonmark migration
Source Link

#JavaScript (ES6), 61 bytes

JavaScript (ES6), 61 bytes

Takes input in currying syntax (c)(s), where s is 1-indexed. Returns a 1-dimensional array.

c=>s=>[...Array(c*c)].map((_,k)=>(k=k%c>k/c?k%c:k/c)<s?-~k:0)

Try it online!

#JavaScript (ES6), 61 bytes

Takes input in currying syntax (c)(s), where s is 1-indexed. Returns a 1-dimensional array.

c=>s=>[...Array(c*c)].map((_,k)=>(k=k%c>k/c?k%c:k/c)<s?-~k:0)

Try it online!

JavaScript (ES6), 61 bytes

Takes input in currying syntax (c)(s), where s is 1-indexed. Returns a 1-dimensional array.

c=>s=>[...Array(c*c)].map((_,k)=>(k=k%c>k/c?k%c:k/c)<s?-~k:0)

Try it online!

saved 6 bytes
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

#JavaScript (ES6), 6761 bytes

Takes input in currying syntax (c)(s)., where s is 1-indexed. Returns a 1-dimensional array.

c=>s=>[...Array(cc*c)].map((_,y,a)=>a.map((_,xk)=>(x=x>y?x:y)<s?x+1:0))

Try it online!


If we were allowed to output a 1-dimensional array of \$C^2\$ values instead, then this 62-byte recursive function would be more competitive:

c=>s=>(g=y=>y<c?[(x=k%c>yk=k%c>k/c?k%c:yk/c)<s?-~x~k:0,...g(++k/c)]:[])(k=0)

Try it online!Try it online!

#JavaScript (ES6), 67 bytes

Takes input in currying syntax (c)(s). 1-indexed.

c=>s=>[...Array(c)].map((_,y,a)=>a.map((_,x)=>(x=x>y?x:y)<s?x+1:0))

Try it online!


If we were allowed to output a 1-dimensional array of \$C^2\$ values instead, then this 62-byte recursive function would be more competitive:

c=>s=>(g=y=>y<c?[(x=k%c>y?k%c:y)<s?-~x:0,...g(++k/c)]:[])(k=0)

Try it online!

#JavaScript (ES6), 61 bytes

Takes input in currying syntax (c)(s), where s is 1-indexed. Returns a 1-dimensional array.

c=>s=>[...Array(c*c)].map((_,k)=>(k=k%c>k/c?k%c:k/c)<s?-~k:0)

Try it online!

added a non-competing recursive version
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

#JavaScript (ES6), 67 bytes

Takes input in currying syntax (c)(s). 1-indexed.

c=>s=>[...Array(c)].map((_,y,a)=>a.map((_,x)=>(x=x>y?x:y)<s?x+1:0))

[Try it online!][TIO-jjsm6j7r] [TIOTry it online!


If we were allowed to output a 1-jjsm6j7r]: https://tio.run/##NYxNCsIwFAb3PUV2eR/WoOiqmBTPoSKP2EpLm5REJDl9/EF3M4uZkZ8cbRiWx9r5W1d6Xaw2UZuTUuoYAmeyuKiZF6JrnWuGNvzX9BZKOpncpibjENu02jYboFjvop86Nfk7VUL0tAft8O34Mxj94EgKCfzw7CQqlBc "JavaScriptdimensional array of (Node.js) – Try It Online"\$C^2\$ values instead, then this 62-byte recursive function would be more competitive:

c=>s=>(g=y=>y<c?[(x=k%c>y?k%c:y)<s?-~x:0,...g(++k/c)]:[])(k=0)

Try it online!

#JavaScript (ES6), 67 bytes

Takes input in currying syntax (c)(s). 1-indexed.

c=>s=>[...Array(c)].map((_,y,a)=>a.map((_,x)=>(x=x>y?x:y)<s?x+1:0))

[Try it online!][TIO-jjsm6j7r] [TIO-jjsm6j7r]: https://tio.run/##NYxNCsIwFAb3PUV2eR/WoOiqmBTPoSKP2EpLm5REJDl9/EF3M4uZkZ8cbRiWx9r5W1d6Xaw2UZuTUuoYAmeyuKiZF6JrnWuGNvzX9BZKOpncpibjENu02jYboFjvop86Nfk7VUL0tAft8O34Mxj94EgKCfzw7CQqlBc "JavaScript (Node.js) – Try It Online"

#JavaScript (ES6), 67 bytes

Takes input in currying syntax (c)(s). 1-indexed.

c=>s=>[...Array(c)].map((_,y,a)=>a.map((_,x)=>(x=x>y?x:y)<s?x+1:0))

Try it online!


If we were allowed to output a 1-dimensional array of \$C^2\$ values instead, then this 62-byte recursive function would be more competitive:

c=>s=>(g=y=>y<c?[(x=k%c>y?k%c:y)<s?-~x:0,...g(++k/c)]:[])(k=0)

Try it online!

Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650
Loading