Skip to main content
added 361 characters in body
Source Link
des54321
  • 2.5k
  • 9
  • 24

tinylisp, 8076 bytes

Since tinylisp was our most recent LYAL, I figured I had to at least post one answer in the lang. Embarrassingly, this answer (in a golfing dialect of lisp) is just as long as the Common Lisp solution

(load library (d _(q((N D $)(i D(_ N(s D 1)(repeat-val $ N))$ (d A(q((N)(_ N N N 

Try it online!

This defines a helper function _ that takes three arguments, the number of times to repeat each layer N, the current depth of the iteration D (counting down, so deepest depth is zero), and an accumulator $. Depending on depth, this function either returns the accumulator (at depth zero), or uses the library builtin repeat-val to repeat the current accumulator N times, and passes that on to the next depth of the recursion. Then the actual function, A, is defined, which takes a single argument N in, and calls _ with that as all three arguments.

Non-library solution, 9086 bytes

This was my first attempt to do this, without using the builtin library (which has rather ungolfy names), but it unfortunately turned out rather longer.

(d _(q((X N D I $)(i D(i I(_ X N D(s I 1)(c X $))(_ $ N(s D 1)N()))X (d A(q((N)(_ N N N N( 

Try it online!

This works much the same as the library solution, but manually defines the behavior of repeat-val, which requires taking two extra arguments in the helper function, which takes the value X the current depth is repeating, the number of repetitions on each depth N, the current depth D (counting down to zero), the number of repetitions remaining in this depth I, and an accumulator $. The proper function A works much the same, taking N calling _ with the proper arguments. (in this case N for the first four, and nil () for the accumulator)

tinylisp, 80 bytes

Since tinylisp was our most recent LYAL, I figured I had to at least post one answer in the lang. Embarrassingly, this answer (in a golfing dialect of lisp) is just as long as the Common Lisp solution

(load library (d _(q((N D $)(i D(_ N(s D 1)(repeat-val $ N))$ (d A(q((N)(_ N N N 

This defines a helper function _ that takes three arguments, the number of times to repeat each layer N, the current depth of the iteration D (counting down, so deepest depth is zero), and an accumulator $. Depending on depth, this function either returns the accumulator (at depth zero), or uses the library builtin repeat-val to repeat the current accumulator N times, and passes that on to the next depth of the recursion. Then the actual function, A, is defined, which takes a single argument N in, and calls _ with that as all three arguments.

Non-library solution, 90 bytes

This was my first attempt to do this, without using the builtin library (which has rather ungolfy names), but it unfortunately turned out rather longer.

(d _(q((X N D I $)(i D(i I(_ X N D(s I 1)(c X $))(_ $ N(s D 1)N()))X (d A(q((N)(_ N N N N( 

This works much the same as the library solution, but manually defines the behavior of repeat-val, which requires taking two extra arguments in the helper function, which takes the value X the current depth is repeating, the number of repetitions on each depth N, the current depth D (counting down to zero), the number of repetitions remaining in this depth I, and an accumulator $. The proper function A works much the same, taking N calling _ with the proper arguments. (in this case N for the first four, and nil () for the accumulator)

tinylisp, 76 bytes

Since tinylisp was our most recent LYAL, I figured I had to at least post one answer in the lang. Embarrassingly, this answer (in a golfing dialect of lisp) is just as long as the Common Lisp solution

(load library (d _(q((N D $)(i D(_ N(s D 1)(repeat-val $ N))$ (q((N)(_ N N N 

Try it online!

This defines a helper function _ that takes three arguments, the number of times to repeat each layer N, the current depth of the iteration D (counting down, so deepest depth is zero), and an accumulator $. Depending on depth, this function either returns the accumulator (at depth zero), or uses the library builtin repeat-val to repeat the current accumulator N times, and passes that on to the next depth of the recursion. Then the actual function, A, is defined, which takes a single argument N in, and calls _ with that as all three arguments.

Non-library solution, 86 bytes

This was my first attempt to do this, without using the builtin library (which has rather ungolfy names), but it unfortunately turned out rather longer.

(d _(q((X N D I $)(i D(i I(_ X N D(s I 1)(c X $))(_ $ N(s D 1)N()))X (q((N)(_ N N N N( 

Try it online!

This works much the same as the library solution, but manually defines the behavior of repeat-val, which requires taking two extra arguments in the helper function, which takes the value X the current depth is repeating, the number of repetitions on each depth N, the current depth D (counting down to zero), the number of repetitions remaining in this depth I, and an accumulator $. The proper function A works much the same, taking N calling _ with the proper arguments. (in this case N for the first four, and nil () for the accumulator)

Source Link
des54321
  • 2.5k
  • 9
  • 24

tinylisp, 80 bytes

Since tinylisp was our most recent LYAL, I figured I had to at least post one answer in the lang. Embarrassingly, this answer (in a golfing dialect of lisp) is just as long as the Common Lisp solution

(load library (d _(q((N D $)(i D(_ N(s D 1)(repeat-val $ N))$ (d A(q((N)(_ N N N 

This defines a helper function _ that takes three arguments, the number of times to repeat each layer N, the current depth of the iteration D (counting down, so deepest depth is zero), and an accumulator $. Depending on depth, this function either returns the accumulator (at depth zero), or uses the library builtin repeat-val to repeat the current accumulator N times, and passes that on to the next depth of the recursion. Then the actual function, A, is defined, which takes a single argument N in, and calls _ with that as all three arguments.

Non-library solution, 90 bytes

This was my first attempt to do this, without using the builtin library (which has rather ungolfy names), but it unfortunately turned out rather longer.

(d _(q((X N D I $)(i D(i I(_ X N D(s I 1)(c X $))(_ $ N(s D 1)N()))X (d A(q((N)(_ N N N N( 

This works much the same as the library solution, but manually defines the behavior of repeat-val, which requires taking two extra arguments in the helper function, which takes the value X the current depth is repeating, the number of repetitions on each depth N, the current depth D (counting down to zero), the number of repetitions remaining in this depth I, and an accumulator $. The proper function A works much the same, taking N calling _ with the proper arguments. (in this case N for the first four, and nil () for the accumulator)