Skip to main content
added 760 characters in body
Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

Charcoal, 27 2323 18 bytes

≔EX²N↨⁴↨ι²υIE⊗υ⁺ιυ

Try it online! Link is to verbose version of code. Explanation: Now a port of @tsh's Python answer.

≔EX²N↨⁴↨ι²υ

Map the numbers up to 2ⁿ by converting them to base 2 and then interpreting the result as base 4.

IE⊗υ⁺ιυ

Vectorised add the doubled array to itself as a matrix.

Previous 27 23 byte answer uses a different approach that is interesting in its own right because some golfing languages have built-ins for things like group index by value or sort array by key.

≔EX⁴N↨²÷↨ι⁴¦²υIE⊕⌈υ⌕Aυι

Try it online! Link is to verbose version of code. Explanation:

≔EX⁴N↨²÷↨ι⁴¦²υ

For each element in the final diagram, convert it to base 4, halve the digits, then convert from base 2. This gives the row number for that element.

IE⊕⌈υ⌕Aυι

For each row list the elements assigned to that row.

Charcoal, 27 23 bytes

≔EX⁴N↨²÷↨ι⁴¦²υIE⊕⌈υ⌕Aυι

Try it online! Link is to verbose version of code. Explanation:

≔EX⁴N↨²÷↨ι⁴¦²υ

For each element in the final diagram, convert it to base 4, halve the digits, then convert from base 2. This gives the row number for that element.

IE⊕⌈υ⌕Aυι

For each row list the elements assigned to that row.

Charcoal, 27 23 18 bytes

≔EX²N↨⁴↨ι²υIE⊗υ⁺ιυ

Try it online! Link is to verbose version of code. Explanation: Now a port of @tsh's Python answer.

≔EX²N↨⁴↨ι²υ

Map the numbers up to 2ⁿ by converting them to base 2 and then interpreting the result as base 4.

IE⊗υ⁺ιυ

Vectorised add the doubled array to itself as a matrix.

Previous 27 23 byte answer uses a different approach that is interesting in its own right because some golfing languages have built-ins for things like group index by value or sort array by key.

≔EX⁴N↨²÷↨ι⁴¦²υIE⊕⌈υ⌕Aυι

Try it online! Link is to verbose version of code. Explanation:

≔EX⁴N↨²÷↨ι⁴¦²υ

For each element in the final diagram, convert it to base 4, halve the digits, then convert from base 2. This gives the row number for that element.

IE⊕⌈υ⌕Aυι

For each row list the elements assigned to that row.

deleted 306 characters in body
Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

Charcoal, 2727 23 bytes

⊞υ⁰FN≔⁺⁺υυ⁺⁺υυX²ιυIE⊕⌈υ⌕Aυι≔EX⁴N↨²÷↨ι⁴¦²υIE⊕⌈υ⌕Aυι

Try it online!Try it online! Link is to verbose version of code. Explanation:

⊞υ⁰

Start with a 1×1 array of row numbers.

FN

Repeat the given number of times.

≔⁺⁺υυ⁺⁺υυX²ιυ≔EX⁴N↨²÷↨ι⁴¦²υ

Each time, the array becomes four times larger. The previously calculated 4ⁱ elements go in the top left quadrant so they remainFor each element in the same rowfinal diagram, the next 4ⁱ elements go in the top right quadrant so they have the same row asconvert it to base 4, halve the previously calculated elementsdigits, then the remaining elements in the bottom left and bottom right quadrants go inconvert from base 2. This gives the next 2ⁱ rowsrow number for that element.

IE⊕⌈υ⌕Aυι

For each row list the elements assigned to that row.

Charcoal, 27 bytes

⊞υ⁰FN≔⁺⁺υυ⁺⁺υυX²ιυIE⊕⌈υ⌕Aυι

Try it online! Link is to verbose version of code. Explanation:

⊞υ⁰

Start with a 1×1 array of row numbers.

FN

Repeat the given number of times.

≔⁺⁺υυ⁺⁺υυX²ιυ

Each time, the array becomes four times larger. The previously calculated 4ⁱ elements go in the top left quadrant so they remain in the same row, the next 4ⁱ elements go in the top right quadrant so they have the same row as the previously calculated elements, then the remaining elements in the bottom left and bottom right quadrants go in the next 2ⁱ rows.

IE⊕⌈υ⌕Aυι

For each row list the elements assigned to that row.

Charcoal, 27 23 bytes

≔EX⁴N↨²÷↨ι⁴¦²υIE⊕⌈υ⌕Aυι

Try it online! Link is to verbose version of code. Explanation:

≔EX⁴N↨²÷↨ι⁴¦²υ

For each element in the final diagram, convert it to base 4, halve the digits, then convert from base 2. This gives the row number for that element.

IE⊕⌈υ⌕Aυι

For each row list the elements assigned to that row.

Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

Charcoal, 27 bytes

⊞υ⁰FN≔⁺⁺υυ⁺⁺υυX²ιυIE⊕⌈υ⌕Aυι

Try it online! Link is to verbose version of code. Explanation:

⊞υ⁰

Start with a 1×1 array of row numbers.

FN

Repeat the given number of times.

≔⁺⁺υυ⁺⁺υυX²ιυ

Each time, the array becomes four times larger. The previously calculated 4ⁱ elements go in the top left quadrant so they remain in the same row, the next 4ⁱ elements go in the top right quadrant so they have the same row as the previously calculated elements, then the remaining elements in the bottom left and bottom right quadrants go in the next 2ⁱ rows.

IE⊕⌈υ⌕Aυι

For each row list the elements assigned to that row.