15
\$\begingroup\$

The title is valid Jelly Code which has the same output as L€€ except printed twice.

Background

You can skip this section without losing ability to complete the challenge

Some operations in Jelly try to convert its argument to a list first before applying the operation. One example is , the mapping quick. This sometimes leads to unintended output.

For the program L€ and input 5, the Jelly interpreter tries to find the length of every element of the list 5. Since 5 is not a list, Jelly converts it to the list [1,2,3,4,5]. Then the length of every element is output: [1,1,1,1,1]. Note that every integer has length 1. If e.g. 10 was present, it would become 1, not 2 (the length in digits).

For the program L€€ and input 5, the Jelly interpreter tries to find the length of every element of every element of the list 5. Since 5 is not a list, Jelly converts it to the list [1,2,3,4,5]. Now the interpreter tries to find the length of every element of every element of the list [1,2,3,4,5]. Every element is not a list, so Jelly converts them to lists in the same manner: [[1],[1,2],[1,2,3],[1,2,3,4],[1,2,3,4,5]]. The length of every sub-element is output as [[1],[1,1],[1,1,1],[1,1,1,1],[1,1,1,1,1]]

Task

Your task is to find the output of the Jelly program L followed by repeated a times, with input b, where a and b are positive integers equal to your program/function's inputs.

A way to do this is:

Starting with the input b, do the following a times:

  • For every integer that the program sees, replace it with the range of the integer (where range(x) := [1,2,3,...,x-1,x])

Finally, replace every integer with 1.

Test Cases

a
b
output
- - - - -
1
1
[1]
- - - - -
1
2
[1, 1]
- - - - -
1
3
[1, 1, 1]
- - - - -
1
4
[1, 1, 1, 1]
- - - - -
1
5
[1, 1, 1, 1, 1]
- - - - -
1
6
[1, 1, 1, 1, 1, 1]
- - - - -
2
1
[[1]]
- - - - -
2
2
[[1], [1, 1]]
- - - - -
2
3
[[1], [1, 1], [1, 1, 1]]
- - - - -
2
4
[[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]
- - - - -
2
5
[[1], [1, 1], [1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1, 1]]
- - - - -
2
6
[[1], [1, 1], [1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]]
- - - - -
3
1
[[[1]]]
- - - - -
3
2
[[[1]], [[1], [1, 1]]]
- - - - -
3
3
[[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]]
- - - - -
3
4
[[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]]
- - - - -
3
5
[[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1, 1]]]
- - - - -
3
6
[[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]]]
- - - - -
4
1
[[[[1]]]]
- - - - -
4
2
[[[[1]]], [[[1]], [[1], [1, 1]]]]
- - - - -
4
3
[[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]]]
- - - - -
4
4
[[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]]]
- - - - -
4
5
[[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1, 1]]]]
- - - - -
4
6
[[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]]]]
- - - - -
5
1
[[[[[1]]]]]
- - - - -
5
2
[[[[[1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]]]]
- - - - -
5
3
[[[[[1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]]]]
- - - - -
5
4
[[[[[1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]]]]
- - - - -
5
5
[[[[[1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1, 1]]]]]
- - - - -
5
6
[[[[[1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]]]]]
- - - - -
6
1
[[[[[[1]]]]]]
- - - - -
6
2
[[[[[[1]]]]], [[[[[1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]]]]]
- - - - -
6
3
[[[[[[1]]]]], [[[[[1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]]]], [[[[[1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]]]]]
- - - - -
6
4
[[[[[[1]]]]], [[[[[1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]]]], [[[[[1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]]]], [[[[[1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]]]]]
- - - - -
6
5
[[[[[[1]]]]], [[[[[1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]]]], [[[[[1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]]]], [[[[[1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]]]], [[[[[1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1, 1]]]]]]
- - - - -
6
6
[[[[[[1]]]]], [[[[[1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]]]], [[[[[1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]]]], [[[[[1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]]]], [[[[[1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1, 1]]]]], [[[[[1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1, 1]]]], [[[[1]]], [[[1]], [[1], [1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1, 1]]], [[[1]], [[1], [1, 1]], [[1], [1, 1], [1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1, 1]], [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]]]]]]

Rules

  • a and b are restricted to positive integers
  • Your program or function may take a and b in any order and in any standard input format
  • The output should be a depth-a list or string representation of such a list
  • The output should be returned through any standard output format.
  • This is , so shortest code in each language wins!
\$\endgroup\$
5
  • \$\begingroup\$ I would disallow builtins that eval a string as Jelly code (looking at you, Jelly) \$\endgroup\$
    – Stephen
    Aug 14, 2017 at 19:27
  • \$\begingroup\$ @StepHen The creation of the string takes too many bytes as compared to repeating the Range function, so I will leave the capability to eval as permitted. \$\endgroup\$ Aug 14, 2017 at 19:30
  • \$\begingroup\$ Fort clarification: The length of any integer is 1, not the length of its decimal expansion? \$\endgroup\$
    – Titus
    Aug 14, 2017 at 21:30
  • \$\begingroup\$ @Titus Yes. I will clarify this in the question. \$\endgroup\$ Aug 14, 2017 at 21:31
  • 2
    \$\begingroup\$ The title can be golfed to L€€CH!DṬHỊṢṄ! (or maybe L€€Ṅ) btw... \$\endgroup\$ Aug 15, 2017 at 10:11

9 Answers 9

13
\$\begingroup\$

Jelly, 3 bytes

R¡Ṡ

Try it online!

Takes input in reverse order.
-2 bytes thanks to fireflame.
-1 byte thanks to Dennis

Explanation

R¡Ṡ  Main link
 ¡   Repeat <first argument> times
R    Range (generates range, and vectorizes on lists)
  Ṡ  Sign (converts all numbers to 1 because they are all positive)
\$\endgroup\$
5
  • 3
    \$\begingroup\$ You can make use of implicit input by removing and taking arguments in reverse order. \$\endgroup\$ Aug 14, 2017 at 19:59
  • \$\begingroup\$ @fireflame241 oh ok thanks! -2 bytes then by removing the ^3 as well \$\endgroup\$
    – hyper-neutrino
    Aug 14, 2017 at 20:00
  • 6
    \$\begingroup\$ You can use the sign atom instead of molding. \$\endgroup\$
    – Dennis
    Aug 15, 2017 at 4:06
  • \$\begingroup\$ Of course Jelly would be unbeatable here... \$\endgroup\$ Aug 15, 2017 at 10:13
  • \$\begingroup\$ @Erik True, but I'm surprised that neither L nor appears in this solution. \$\endgroup\$ Aug 15, 2017 at 11:02
11
\$\begingroup\$

Python 2, 49 bytes

-1 thanks to Jonathan Allan

f=lambda a,b:1>>a or[0]*b and f(a,b-1)+[f(a-1,b)]

Try it online!

This problem seemed like it could be written in the form of a doubly recursive function, subtracting one from each parameter. The key idea is that the sequence can be related as follows:

f(0,b) = 1
f(a,0) = []
f(a,b) = f(a,b-1) + [f(a-1,b)]

However writing a recursive function like this is pretty tricky, since 1 is a truthy value and [] is a falsy value, so we need two short-circuiting keywords (and and or).

A less golfed version might look like:

lambda a,b:int(a<1)or[1,[]][b<1]and f(a,b-1)+[f(a-1,b)]

However we can use the trick that 1>>a gives 1 if a is zero, and 0 otherwise, and that we can return a truthy value if b>0 and an empty list otherwise by doing [0]*b.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Save one with or[0]*b and in place of or[0][:b]and. \$\endgroup\$ Aug 15, 2017 at 1:25
9
\$\begingroup\$

Mathematica, 17 bytes

1^Range~Nest~##&

Takes b then a.

Try it on Wolfram Sandbox

How?

1^Range~Nest~##&

  Range             (* Range function; generates {1..<input>} *)
       ~Nest~##     (* Apply it on <input 1> <input 2> times *)
                    (* Mathematica automatically maps Range onto integers *)
1^                  (* Raise those to the exponent of 1; make everything 1 *)

Usage

1^Range~Nest~##&[4, 2]

{{1}, {1, 1}, {1, 1, 1}, {1, 1, 1, 1}}

\$\endgroup\$
4
\$\begingroup\$

Gaia, 7 bytes

ẏ¦”@)⊃e

Try it online!

ẏ¦ does just about the same thing here as L€ in Jelly. is "is positive?" and ¦ is map, which also implicitly casts an integer to the range 1 .. n before mapping. And since we're dealing with only integers >= 1, will result in 1 for each.

ẏ¦”      Push the string "ẏ¦"
   @)    Push the first input+1
     ⊃   Repeat the last character of the string until it's input+1 characters long.
      e  Eval it.
\$\endgroup\$
3
\$\begingroup\$

Python 2, 57 55 bytes

-1 byte thanks to Jakob
-1 byte thanks to notjagan

f=lambda a,b:[1]*b*(a<2)or[f(a-1,i+1)for i in range(b)]

Try it online!

\$\endgroup\$
0
3
\$\begingroup\$

PHP, 134 bytes

for($r=[$argv[2]];$argv[1]--;)($w=array_walk_recursive)($r,function(&$n){$n=range(1,$n);});$w($r,function(&$n){$n=1;});print_r($r[0]);

There may be a shorter approach than the literal one ... but it´s working at least.

Run with -nr and provide a and b as arguments or try it online.


For output as in the examples, use echo strtr(preg_replace('#"\d":#','',json_encode($r[0],JSON_NUMERIC_CHECK)),"{}","[]"); (as I do in the TiO) instead of print_r($r[0]);.

\$\endgroup\$
3
\$\begingroup\$

JavaScript (ES6), 95 bytes

f=(a,b,r=/\d+/g)=>a--?f(a,b.replace(r,s=>`[${[...Array(+s)].map((_,i)=>++i)}]`)):b.replace(r,1)
<div oninput=o.textContent=f(a.value,b.value)><input type=number min=0 value=0 id=a><input type=number min=0 value=0 id=b><pre wrap id=o>1

I/O is with strings. The best I could do nonrecursively was 100 bytes:

(a,b)=>[...Array(-~a)].reduce(r=>r.replace(/\d+/g,a--?s=>`[${[...Array(+s)].map((_,i)=>++i)}]`:1),b)
\$\endgroup\$
3
\$\begingroup\$

Brachylog, 21 bytes

,1{t+₁I&⟦₁ᵐ⁾;I}ⁱ⁽ṡᵐ⁾c

Try it online!

Conceptually simple, but keeping track of the right level to map the 'range' predicate at, takes up almost half the bytes. :(

                 % Implicit input, list [a, b]
,1               % Append iteration index 1 to the list
{           }ⁱ⁽  % Do this iteratively a times, with [b, i] as the initial input
 t+₁I            % Increment iteration index, let this be I
     &⟦₁ᵐ⁾       % Map the "range from 1 to input" predicate on the first part of input
                 %   (b in the first iteration), at depth given by (old) iteration index
          ;I     % Append the incremented index to this, this is the input to next iteration
ṡᵐ⁾              % Take the sign of each element, mapped at depth given by final I
c                % "Concatenate" to remove extra surrounding array

And a recursive solution, just for the heck of it:

24 bytes

{t0&hṡᵐ|t-₁L&h⟦₁ᵐ;Lz↰ᵐ}c

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Jelly, 12 bytes

⁴Ṿ;”L;”€ẋ³¤V

Try it online!

Just to get things started. I'm pretty sure it would be shorter if I actually did it the way I'm supposed to, so I'm working on that (inb4 ninja'd by someone)

Explanation

⁴Ṿ;”L;”€ẋ³¤V  Main link
 Ṿ            Generate Jelly code that will evaluate to
⁴             The second input
  ;           Concatenate with
   ”L         "L"
     ;        Concatenate with
      ”€ẋ³¤   Niladic Expression
      ”€      "€"
        ẋ     Repeated                times
         ³             <first input>
           V  Jelly-eval it
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.