Skip to main content
added a shorter version
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (ES6), 65 bytes

Expects the input list in reverse order.

Very similar to the 66-byte version, but returns a flattened string.

f=([n,...a],b='0')=>n?b.replace(/./g,v=>f(a,1+v.repeat(n-2)+1)):b 

Try it online!


JavaScript (ES6), 66 bytes

JavaScript (ES6), 66 bytes

JavaScript (ES6), 65 bytes

Expects the input list in reverse order.

Very similar to the 66-byte version, but returns a flattened string.

f=([n,...a],b='0')=>n?b.replace(/./g,v=>f(a,1+v.repeat(n-2)+1)):b 

Try it online!


JavaScript (ES6), 66 bytes

added a commented version
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
f=([n,...c]a],b=[0])=>n?b.map(v=>f(ca,[1,...Array(n-2).fill(v),1])):b 

Try it online!Try it online!

Commented

f = ( // f is a recursive function taking: [ n, // n = next value from the input list ...a ], // a[] = all remaining values b = [ 0 ] // b[] = output, initialized to [ 0 ] ) => // n ? // if n is defined: b.map(v => // for each value v in b[]: f( // do a recursive call: a, // pass the remaining values [ // build an array consisting of: 1, // a leading '1' ...Array(n - 2) // followed by n - 2 values .fill(v), // set to v 1 // followed by a trailing '1' ] // end of array ) // end of recursive call ) // end of map() : // else: b // we're done: return b[] 
f=([n,...c],b=[0])=>n?b.map(v=>f(c,[1,...Array(n-2).fill(v),1])):b 

Try it online!

f=([n,...a],b=[0])=>n?b.map(v=>f(a,[1,...Array(n-2).fill(v),1])):b 

Try it online!

Commented

f = ( // f is a recursive function taking: [ n, // n = next value from the input list ...a ], // a[] = all remaining values b = [ 0 ] // b[] = output, initialized to [ 0 ] ) => // n ? // if n is defined: b.map(v => // for each value v in b[]: f( // do a recursive call: a, // pass the remaining values [ // build an array consisting of: 1, // a leading '1' ...Array(n - 2) // followed by n - 2 values .fill(v), // set to v 1 // followed by a trailing '1' ] // end of array ) // end of recursive call ) // end of map() : // else: b // we're done: return b[] 
deleted 284 characters in body
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (ES6), 66 bytes

Expects the input list in reverse order. Or +8 bytes if this is not acceptable.

f=([n,...c],b=[0])=>n?b.map(v=>f(c,[1,...Array(n-2).fill(v),1])):b 

Try it online!

JavaScript (ES6), 66 bytes

Expects the input list in reverse order. Or +8 bytes if this is not acceptable.

f=([n,...c],b=[0])=>n?b.map(v=>f(c,[1,...Array(n-2).fill(v),1])):b 

Try it online!

JavaScript (ES6), 66 bytes

Expects the input list in reverse order.

f=([n,...c],b=[0])=>n?b.map(v=>f(c,[1,...Array(n-2).fill(v),1])):b 

Try it online!

Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading