Skip to main content
edited body
Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

Charcoal, 122122 120 bytes

≔&θ⁰η≔⟦η⟧ζFζFιF⁼κ⁺⟦⟧κ«UMκ⊖μ⊞ζκ»⊞υθ⊞υηFυFιF⁼κ⁺⟦⟧κ⊞υκW∧υ⊟υ«≔⟦⟧ζWι⊞ζ⊟ιF⮌ζ¿⁺⟦⟧κFκ⊞ιλ⊞ικ»≔⮌θθ≔⁰ζF⁻η⊖⌊η«F⁻ζι]→F⁻ιζ[I⊟θ≔ιζ»Fζ]UB≔&θ⁰η≔⟦η⟧ζFζFιF⁼κ⁺⟦⟧κ«UMκ⊖μ⊞ζκ»⊞υθ⊞υηFυFιF⁼κ⁺⟦⟧κ⊞υκF⮌υ«≔⟦⟧ζWι⊞ζ⊟ιF⮌ζ¿⁺⟦⟧κFκ⊞ιλ⊞ικ»≔⮌θθ≔⁰ζF⁻η⊖⌊η«F⁻ζι]→F⁻ιζ[I⊟θ≔ιζ»Fζ]UB, 

Try it online!Try it online! Link is to verbose version of code. Explanation: Not an easy problem to solve without access to recursion.

≔&θ⁰η 

Make a deep clone of the input and set all of the integers in that clone to zero. (BitwiseAnd fully vectorises, unlike, say, Times.)

≔⟦η⟧ζFζFιF⁼κ⁺⟦⟧κ«UMκ⊖μ⊞ζκ» 

Perform a breadth-first search over the clone and decrement each sublist. (Again, it is fortunate that Decremented fully vectorises, although I still have to MapCommand it because I need to modify each sublist in-place.) The resulting list ends up with values appropriate to their depth.

⊞υθ⊞υηFυFιF⁼κ⁺⟦⟧κ⊞υκW∧υ⊟υ«≔⟦⟧ζWι⊞ζ⊟ιF⮌ζ¿⁺⟦⟧κFκ⊞ιλ⊞ικ»⊞υθ⊞υηFυFιF⁼κ⁺⟦⟧κ⊞υκF⮌υ«≔⟦⟧ζWι⊞ζ⊟ιF⮌ζ¿⁺⟦⟧κFκ⊞ιλ⊞ικ» 

Flatten both the input and the depth clone in-place.

≔⮌θθ≔⁰ζF⁻η⊖⌊η«F⁻ζι]→F⁻ιζ[I⊟θ≔ιζ»Fζ]UB, 

Adjust the depth list so that the minimum depth is 1, and use that to build the desired output list from the depth list and the flattened input list. (See my answer to Build a list from a depth map for more detail.)

Charcoal, 122 bytes

≔&θ⁰η≔⟦η⟧ζFζFιF⁼κ⁺⟦⟧κ«UMκ⊖μ⊞ζκ»⊞υθ⊞υηFυFιF⁼κ⁺⟦⟧κ⊞υκW∧υ⊟υ«≔⟦⟧ζWι⊞ζ⊟ιF⮌ζ¿⁺⟦⟧κFκ⊞ιλ⊞ικ»≔⮌θθ≔⁰ζF⁻η⊖⌊η«F⁻ζι]→F⁻ιζ[I⊟θ≔ιζ»Fζ]UB, 

Try it online! Link is to verbose version of code. Explanation: Not an easy problem to solve without access to recursion.

≔&θ⁰η 

Make a deep clone of the input and set all of the integers in that clone to zero. (BitwiseAnd fully vectorises, unlike, say, Times.)

≔⟦η⟧ζFζFιF⁼κ⁺⟦⟧κ«UMκ⊖μ⊞ζκ» 

Perform a breadth-first search over the clone and decrement each sublist. (Again, it is fortunate that Decremented fully vectorises, although I still have to MapCommand it because I need to modify each sublist in-place.) The resulting list ends up with values appropriate to their depth.

⊞υθ⊞υηFυFιF⁼κ⁺⟦⟧κ⊞υκW∧υ⊟υ«≔⟦⟧ζWι⊞ζ⊟ιF⮌ζ¿⁺⟦⟧κFκ⊞ιλ⊞ικ» 

Flatten both the input and the depth clone in-place.

≔⮌θθ≔⁰ζF⁻η⊖⌊η«F⁻ζι]→F⁻ιζ[I⊟θ≔ιζ»Fζ]UB, 

Adjust the depth list so that the minimum depth is 1, and use that to build the desired output list from the depth list and the flattened input list. (See my answer to Build a list from a depth map for more detail.)

Charcoal, 122 120 bytes

≔&θ⁰η≔⟦η⟧ζFζFιF⁼κ⁺⟦⟧κ«UMκ⊖μ⊞ζκ»⊞υθ⊞υηFυFιF⁼κ⁺⟦⟧κ⊞υκF⮌υ«≔⟦⟧ζWι⊞ζ⊟ιF⮌ζ¿⁺⟦⟧κFκ⊞ιλ⊞ικ»≔⮌θθ≔⁰ζF⁻η⊖⌊η«F⁻ζι]→F⁻ιζ[I⊟θ≔ιζ»Fζ]UB, 

Try it online! Link is to verbose version of code. Explanation: Not an easy problem to solve without access to recursion.

≔&θ⁰η 

Make a deep clone of the input and set all of the integers in that clone to zero. (BitwiseAnd fully vectorises, unlike, say, Times.)

≔⟦η⟧ζFζFιF⁼κ⁺⟦⟧κ«UMκ⊖μ⊞ζκ» 

Perform a breadth-first search over the clone and decrement each sublist. (Again, it is fortunate that Decremented fully vectorises, although I still have to MapCommand it because I need to modify each sublist in-place.) The resulting list ends up with values appropriate to their depth.

⊞υθ⊞υηFυFιF⁼κ⁺⟦⟧κ⊞υκF⮌υ«≔⟦⟧ζWι⊞ζ⊟ιF⮌ζ¿⁺⟦⟧κFκ⊞ιλ⊞ικ» 

Flatten both the input and the depth clone in-place.

≔⮌θθ≔⁰ζF⁻η⊖⌊η«F⁻ζι]→F⁻ιζ[I⊟θ≔ιζ»Fζ]UB, 

Adjust the depth list so that the minimum depth is 1, and use that to build the desired output list from the depth list and the flattened input list. (See my answer to Build a list from a depth map for more detail.)

Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

Charcoal, 122 bytes

≔&θ⁰η≔⟦η⟧ζFζFιF⁼κ⁺⟦⟧κ«UMκ⊖μ⊞ζκ»⊞υθ⊞υηFυFιF⁼κ⁺⟦⟧κ⊞υκW∧υ⊟υ«≔⟦⟧ζWι⊞ζ⊟ιF⮌ζ¿⁺⟦⟧κFκ⊞ιλ⊞ικ»≔⮌θθ≔⁰ζF⁻η⊖⌊η«F⁻ζι]→F⁻ιζ[I⊟θ≔ιζ»Fζ]UB, 

Try it online! Link is to verbose version of code. Explanation: Not an easy problem to solve without access to recursion.

≔&θ⁰η 

Make a deep clone of the input and set all of the integers in that clone to zero. (BitwiseAnd fully vectorises, unlike, say, Times.)

≔⟦η⟧ζFζFιF⁼κ⁺⟦⟧κ«UMκ⊖μ⊞ζκ» 

Perform a breadth-first search over the clone and decrement each sublist. (Again, it is fortunate that Decremented fully vectorises, although I still have to MapCommand it because I need to modify each sublist in-place.) The resulting list ends up with values appropriate to their depth.

⊞υθ⊞υηFυFιF⁼κ⁺⟦⟧κ⊞υκW∧υ⊟υ«≔⟦⟧ζWι⊞ζ⊟ιF⮌ζ¿⁺⟦⟧κFκ⊞ιλ⊞ικ» 

Flatten both the input and the depth clone in-place.

≔⮌θθ≔⁰ζF⁻η⊖⌊η«F⁻ζι]→F⁻ιζ[I⊟θ≔ιζ»Fζ]UB, 

Adjust the depth list so that the minimum depth is 1, and use that to build the desired output list from the depth list and the flattened input list. (See my answer to Build a list from a depth map for more detail.)