Skip to main content
added 437 characters in body
Source Link
GammaFunction
  • 6.9k
  • 13
  • 23

Zsh, 5454 51 bytes

-3 by ^= instead of =0^().

((n=$#1,l=0^(n**0l^=n**0.5)))
eval '<<<${1:'{0..$n..$l}':$l}'

Try it online! Try it online!

Shoutouts to eval jank.

Try it online!

((n=$#1,l=0^(n**0l^=n**0.5)))              # the '0^'xor no-opwith xor0 casts n**0.5 to an integer
eval '<<<${1:'           ':$l}'  # when eval'd, prints a subtring of length l
              {0..$n..$l}        # brace expansion: {0..4..16} => 0 4 8 12 16

I left in set -x in the TIO link, scroll down to the debug section to see exactly what happens with the brace expansion.

Zsh, 54 bytes

((n=$#1,l=0^(n**0.5)))
eval '<<<${1:'{0..$n..$l}':$l}'

Shoutouts to eval jank.

Try it online!

((n=$#1,l=0^(n**0.5)))           # the '0^' no-op xor casts to integer
eval '<<<${1:'           ':$l}'  # when eval'd, prints a subtring of length l
              {0..$n..$l}        # brace expansion: {0..4..16} => 0 4 8 12 16

I left in set -x in the TIO link, scroll down to the debug section to see exactly what happens with the brace expansion.

Zsh, 54 51 bytes

-3 by ^= instead of =0^().

((n=$#1,l^=n**0.5))
eval '<<<${1:'{0..$n..$l}':$l}'

Try it online! Try it online!

Shoutouts to eval jank.

((n=$#1,l^=n**0.5))              # the xor with 0 casts n**0.5 to an integer
eval '<<<${1:'           ':$l}'  # when eval'd, prints a subtring of length l
              {0..$n..$l}        # brace expansion: {0..4..16} => 0 4 8 12 16

I left in set -x in the TIO link, scroll down to the debug section to see exactly what happens with the brace expansion.

Source Link
GammaFunction
  • 6.9k
  • 13
  • 23

Zsh, 54 bytes

((n=$#1,l=0^(n**0.5)))
eval '<<<${1:'{0..$n..$l}':$l}'

Shoutouts to eval jank.

Try it online!

((n=$#1,l=0^(n**0.5)))           # the '0^' no-op xor casts to integer
eval '<<<${1:'           ':$l}'  # when eval'd, prints a subtring of length l
              {0..$n..$l}        # brace expansion: {0..4..16} => 0 4 8 12 16

I left in set -x in the TIO link, scroll down to the debug section to see exactly what happens with the brace expansion.