Skip to main content
deleted 114 characters in body
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394

Jelly, 31 30 30 27 bytes

ŒJẈạṀ$‘Ø0jIr0Ṣ€Ṡị“[],”⁸Fż@¥FḊṖ”żFFḊṖ 

I'm pretty rusty in Jelly, soso can probably be golfed a bit further. It indeed can probably be golfed a bit further:
-3 bytes thanks to @JonathanAllan.

Port of my 05AB1E answer. The Ø0jIr0Ṣ€Ṡị“[], and ż¥FḊṖ”żFFḊṖ are takenis a slight modification from @xigoi's Jelly answer for the Build a list from a depth map challenge.

Try it onlineTry it online or verify all test casesverify all test cases.

 # Main link, taking the input-list as argument: ŒJẈ # Determine the depth of each integer: ŒJ # Get the multidimensional arguments Ẉ # Get the length of each inner list ạṀ$‘ # Invert this depth-list: $ # Apply the previous two links as monad: Ṁ # Get the maximum of this list of depths ạ # Calculate the absolute difference ‘ # Increase each 0-based depth by 1 Ø0jIr0Ṣ€Ṡị“[],” # Create a string to zip with: Ø0j # Surround the list with leading/trailing 0 I # Forward-differences r0 # Map each integer `n` to a list in the range [n,0] Ṣ€ # Sort each range Ṡ # Signum (-1 if <0; 0 if 0; 1 if >0) ị“[],” # Index into "[]," ("[" if 1; "," if 0; "]" if -1)  ¥ # Using two lists as dyad arguments ż @ # with reversed argumentsZip/transpose, ⁸F  # where the first argument isusing the flattenedlist inputabove   F # and the second argument is the string above ż  # flattened Zipinput themas togetherarguments F F # Then flatten the result ḊṖ ḊṖ # And remove the leading/trailing "," # (after which the result is output implicitly) 

Jelly, 31 30 bytes

ŒJẈạṀ$‘Ø0jIr0Ṣ€Ṡị“[],”⁸Fż@¥FḊṖ 

I'm pretty rusty in Jelly, so can probably be golfed a bit further.

Port of my 05AB1E answer. Ø0jIr0Ṣ€Ṡị“[], and ż¥FḊṖ are taken from @xigoi's Jelly answer for the Build a list from a depth map challenge.

Try it online or verify all test cases.

 # Main link, taking the input-list as argument: ŒJẈ # Determine the depth of each integer: ŒJ # Get the multidimensional arguments Ẉ # Get the length of each inner list ạṀ$‘ # Invert this depth-list: $ # Apply the previous two links as monad: Ṁ # Get the maximum of this list of depths ạ # Calculate the absolute difference ‘ # Increase each 0-based depth by 1 Ø0jIr0Ṣ€Ṡị“[],” # Create a string to zip with: Ø0j # Surround the list with leading/trailing 0 I # Forward-differences r0 # Map each integer `n` to a list in the range [n,0] Ṣ€ # Sort each range Ṡ # Signum (-1 if <0; 0 if 0; 1 if >0) ị“[],” # Index into "[]," ("[" if 1; "," if 0; "]" if -1)  ¥ # Using two lists as dyad arguments  @ # with reversed arguments, ⁸F  # where the first argument is the flattened input   # and the second argument is the string above ż  #  Zip them together F # Then flatten the result ḊṖ # And remove the leading/trailing "," # (after which the result is output implicitly) 

Jelly, 31 30 27 bytes

ŒJẈạṀ$‘Ø0jIr0Ṣ€Ṡị“[],”żFFḊṖ 

I'm pretty rusty in Jelly, so can probably be golfed a bit further. It indeed can:
-3 bytes thanks to @JonathanAllan.

Port of my 05AB1E answer. The Ø0jIr0Ṣ€Ṡị“[],”żFFḊṖ is a slight modification from @xigoi's Jelly answer for the Build a list from a depth map challenge.

Try it online or verify all test cases.

 # Main link, taking the input-list as argument: ŒJẈ # Determine the depth of each integer: ŒJ # Get the multidimensional arguments Ẉ # Get the length of each inner list ạṀ$‘ # Invert this depth-list: $ # Apply the previous two links as monad: Ṁ # Get the maximum of this list of depths ạ # Calculate the absolute difference ‘ # Increase each 0-based depth by 1 Ø0jIr0Ṣ€Ṡị“[],” # Create a string to zip with: Ø0j # Surround the list with leading/trailing 0 I # Forward-differences r0 # Map each integer `n` to a list in the range [n,0] Ṣ€ # Sort each range Ṡ # Signum (-1 if <0; 0 if 0; 1 if >0) ị“[],” # Index into "[]," ("[" if 1; "," if 0; "]" if -1) ż # Zip/transpose, using the list above F # and the flattened input as arguments F # Then flatten the result ḊṖ # And remove the leading/trailing "," # (after which the result is output implicitly) 
deleted 262 characters in body
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394

Jelly, 3131 30 bytes

ŒJẈạṀ$‘Ø0jIr0Ṣ€Ṡị“[],” F⁸Çż¥FḊṖ”⁸Fż@¥FḊṖ 

I'm pretty rusty in Jelly, so can probably be golfed a bit further (and I might not even need the separated helper function).

Try it onlineTry it online or verify all test casesverify all test cases.

ŒJẈạṀ$‘Ø0jIr0Ṣ€Ṡị“[],”  # HelperMain functionlink, taking athe input-list as argument: ŒJẈ  # Determine the depth of each integer: ŒJ  # Get the multidimensional arguments Ẉ  # Get the length of each inner list ạṀ$‘  # Invert this depth-list: $  # Apply the previous two links as monad: Ṁ  # Get the maximum of this list of depths ạ  # Calculate the absolute difference ‘  # Increase each 0-based depth by 1  Ø0jIr0Ṣ€Ṡị“[],”  # Create a string to zip with:  Ø0j  # Surround the list with leading/trailing 0   I  # Forward-differences   r0  # Map each integer `n` to a list in the range [n,0]   Ṣ€  # Sort each range    # Signum (-1 if <0; 0 if 0; 1 if >0)   ị“[],”  # Index into "[]," ("[" if 1; "," if 0; "]" if -1)   F⁸Çż¥FḊṖ ¥ # Main# link, takingUsing atwo listlists as argument: F  dyad arguments  @ #  Flatten thewith (implicit)reversed input-argumentarguments,  Ç ⁸F # Callwhere the helper-function above first argument is the flattened input  # Withand the input assecond argument ¥ #  Using these lastis the lists as dyadstring arguments:above   ż  # Zip them together F  # Then flatten the result ḊṖ  # And remove the leading/trailing ","   # (after which the result is output implicitly) 

Jelly, 31 bytes

ŒJẈạṀ$‘Ø0jIr0Ṣ€Ṡị“[],” F⁸Çż¥FḊṖ 

I'm pretty rusty in Jelly, so can probably be golfed a bit further (and I might not even need the separated helper function).

Try it online or verify all test cases.

ŒJẈạṀ$‘Ø0jIr0Ṣ€Ṡị“[],” # Helper function, taking a list as argument: ŒJẈ  # Determine the depth of each integer: ŒJ  # Get the multidimensional arguments Ẉ  # Get the length of each inner list ạṀ$‘  # Invert this depth-list: $  # Apply the previous two links as monad: Ṁ  # Get the maximum of this list of depths ạ  # Calculate the absolute difference ‘  # Increase each 0-based depth by 1  Ø0jIr0Ṣ€Ṡị“[],” # Create a string to zip with:  Ø0j # Surround the list with leading/trailing 0   I # Forward-differences   r0 # Map each integer `n` to a list in the range [n,0]   Ṣ€ # Sort each range   Ṡ # Signum (-1 if <0; 0 if 0; 1 if >0)   ị“[],” # Index into "[]," ("[" if 1; "," if 0; "]" if -1)   F⁸Çż¥FḊṖ # Main link, taking a list as argument: F  #  Flatten the (implicit) input-argument  Ç  # Call the helper-function above   # With the input as argument ¥ #  Using these last the lists as dyad arguments:   ż  # Zip them together F  # Then flatten the result ḊṖ  # And remove the leading/trailing ","   # (after which the result is output implicitly) 

Jelly, 31 30 bytes

ŒJẈạṀ$‘Ø0jIr0Ṣ€Ṡị“[],”⁸Fż@¥FḊṖ 

I'm pretty rusty in Jelly, so can probably be golfed a bit further.

Try it online or verify all test cases.

  # Main link, taking the input-list as argument: ŒJẈ # Determine the depth of each integer: ŒJ # Get the multidimensional arguments Ẉ # Get the length of each inner list ạṀ$‘ # Invert this depth-list: $ # Apply the previous two links as monad: Ṁ # Get the maximum of this list of depths ạ # Calculate the absolute difference ‘ # Increase each 0-based depth by 1 Ø0jIr0Ṣ€Ṡị“[],”  # Create a string to zip with: Ø0j  # Surround the list with leading/trailing 0 I  # Forward-differences r0  # Map each integer `n` to a list in the range [n,0] Ṣ€  # Sort each range Ṡ  # Signum (-1 if <0; 0 if 0; 1 if >0) ị“[],”  # Index into "[]," ("[" if 1; "," if 0; "]" if -1) ¥ # Using two lists as dyad arguments  @ # with reversed arguments, ⁸F # where the first argument is the flattened input  # and the second argument is the string above ż # Zip them together F # Then flatten the result ḊṖ # And remove the leading/trailing "," # (after which the result is output implicitly) 
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394

Jelly, 31 bytes

ŒJẈạṀ$‘Ø0jIr0Ṣ€Ṡị“[],” F⁸Çż¥FḊṖ 

I'm pretty rusty in Jelly, so can probably be golfed a bit further (and I might not even need the separated helper function).

Input as a list; output as a string.

Port of my 05AB1E answer. Ø0jIr0Ṣ€Ṡị“[],” and ż¥FḊṖ are taken from @xigoi's Jelly answer for the Build a list from a depth map challenge.

Try it online or verify all test cases.

Explanation:

ŒJẈạṀ$‘Ø0jIr0Ṣ€Ṡị“[],” # Helper function, taking a list as argument: ŒJẈ # Determine the depth of each integer: ŒJ # Get the multidimensional arguments Ẉ # Get the length of each inner list ạṀ$‘ # Invert this depth-list: $ # Apply the previous two links as monad: Ṁ # Get the maximum of this list of depths ạ # Calculate the absolute difference ‘ # Increase each 0-based depth by 1 Ø0jIr0Ṣ€Ṡị“[],” # Create a string to zip with: Ø0j # Surround the list with leading/trailing 0 I # Forward-differences r0 # Map each integer `n` to a list in the range [n,0] Ṣ€ # Sort each range Ṡ # Signum (-1 if <0; 0 if 0; 1 if >0) ị“[],” # Index into "[]," ("[" if 1; "," if 0; "]" if -1) F⁸Çż¥FḊṖ # Main link, taking a list as argument: F # Flatten the (implicit) input-argument Ç # Call the helper-function above ⁸ # With the input as argument ¥ # Using these last the lists as dyad arguments: ż # Zip them together F # Then flatten the result ḊṖ # And remove the leading/trailing "," # (after which the result is output implicitly)