Skip to main content
The 2024 Developer Survey results are live! See the results
explain the under shenanigans
Source Link
noodle person
  • 8.7k
  • 1
  • 18
  • 70

Uiua, 11 bytes

⊕□⊚⍜ₙ⇡2+1⧻.

Try it online!

Nice and short! (group) and (where) are a great combo for this.

⊕□⊚⍜ₙ⇡2+1⧻.  # input string on the right.   "abcdefghijklmno"
       +1⧻.  # length + 1                   16
   ⍜ₙ⇡2      # 2^( range( log_2( that )))   [1 2 4 8]
⊕□⊚          # group into pieces that size  {"a" "bc" "defg" "hijklmno"}

⍜ₙ⇡2 means range () "under" () logarithm base 2. applies a function, then a second function, and then the inverse of that first function. Here, we apply log_2(x), then range, and then the inverse of log_2(x) which is 2^x.

Literally, ⊕□⊚ does:

     #                              [1 2 4 8]
⊚    # these repeat the naturals:   [0 1 1 2 2 2 2 3 3 3 3 3 3 3 3]
⊕□   # group by boxing the chars     a b c d e f g h i j k l m n o
     # corresponding with indices   {"a" "bc" "defg" "hijklmno"}

Uiua, 11 bytes

⊕□⊚⍜ₙ⇡2+1⧻.

Try it online!

Nice and short! (group) and (where) are a great combo for this.

⊕□⊚⍜ₙ⇡2+1⧻.  # input string on the right.   "abcdefghijklmno"
       +1⧻.  # length + 1                   16
   ⍜ₙ⇡2      # 2^( range( log_2( that )))   [1 2 4 8]
⊕□⊚          # group into pieces that size  {"a" "bc" "defg" "hijklmno"}

Literally, ⊕□⊚ does:

     #                              [1 2 4 8]
⊚    # these repeat the naturals:   [0 1 1 2 2 2 2 3 3 3 3 3 3 3 3]
⊕□   # group by boxing the chars     a b c d e f g h i j k l m n o
     # corresponding with indices   {"a" "bc" "defg" "hijklmno"}

Uiua, 11 bytes

⊕□⊚⍜ₙ⇡2+1⧻.

Try it online!

Nice and short! (group) and (where) are a great combo for this.

⊕□⊚⍜ₙ⇡2+1⧻.  # input string on the right.   "abcdefghijklmno"
       +1⧻.  # length + 1                   16
   ⍜ₙ⇡2      # 2^( range( log_2( that )))   [1 2 4 8]
⊕□⊚          # group into pieces that size  {"a" "bc" "defg" "hijklmno"}

⍜ₙ⇡2 means range () "under" () logarithm base 2. applies a function, then a second function, and then the inverse of that first function. Here, we apply log_2(x), then range, and then the inverse of log_2(x) which is 2^x.

Literally, ⊕□⊚ does:

     #                              [1 2 4 8]
⊚    # these repeat the naturals:   [0 1 1 2 2 2 2 3 3 3 3 3 3 3 3]
⊕□   # group by boxing the chars     a b c d e f g h i j k l m n o
     # corresponding with indices   {"a" "bc" "defg" "hijklmno"}
cleaner way :)
Source Link
noodle person
  • 8.7k
  • 1
  • 18
  • 70

Uiua, 11 bytes

⊕□⊚⍜ₙ⇡2+1⧻.

Try it online!

Nice and short! (group) and (where) are a great combo for this.

⊕□⊚⍜ₙ⇡2+1⧻.  # input string on the right.   "abcdefghijklmno"
       +1⧻.  # length + 1                   16
   ⍜ₙ⇡2      # 2^( range( log_2( that )))   [1 2 4 8]
⊕□⊚          # group into pieces that size  {"a" "bc" "defg" "hijklmno"}

Literally, ⊕□⊚ does:

     #                              [1 2 4 8]
⊚    # these repeat the naturals:   [0 1 1 2 2 2 2 3 3 3 3 3 3 3 3]
⊕□   # group by boxing the chars     a b c d e f g h i j k l m n o
     # corresponding with indices   {"a" "bc" "defg" "hijklmno"}

Uiua, 11 bytes

⊕□⊚⍜ₙ⇡2+1⧻.

Try it online!

Nice and short! (group) and (where) are a great combo for this.

⊕□⊚⍜ₙ⇡2+1⧻.  # input string on the right.   "abcdefghijklmno"
       +1⧻.  # length + 1                   16
   ⍜ₙ⇡2      # 2^( range( log_2( that )))   [1 2 4 8]
⊕□⊚          # group into pieces that size  {"a" "bc" "defg" "hijklmno"}

Uiua, 11 bytes

⊕□⊚⍜ₙ⇡2+1⧻.

Try it online!

Nice and short! (group) and (where) are a great combo for this.

⊕□⊚⍜ₙ⇡2+1⧻.  # input string on the right.   "abcdefghijklmno"
       +1⧻.  # length + 1                   16
   ⍜ₙ⇡2      # 2^( range( log_2( that )))   [1 2 4 8]
⊕□⊚          # group into pieces that size  {"a" "bc" "defg" "hijklmno"}

Literally, ⊕□⊚ does:

     #                              [1 2 4 8]
⊚    # these repeat the naturals:   [0 1 1 2 2 2 2 3 3 3 3 3 3 3 3]
⊕□   # group by boxing the chars     a b c d e f g h i j k l m n o
     # corresponding with indices   {"a" "bc" "defg" "hijklmno"}
cleaner way :)
Source Link
noodle person
  • 8.7k
  • 1
  • 18
  • 70

Uiua, 11 bytes

⊕□↙⊃⧻⊚ⁿ:2°⊏⊕□⊚⍜ₙ⇡2+1⧻.

Try it online!Try it online!

A bit inefficient but it gets the job done niceNice and short! (group) and (where) are a great combo for this.

⊕□↙⊃⧻⊚ⁿ:2°⊏⊕□⊚⍜ₙ⇡2+1⧻.  # input string on the right.   "abcdefg""abcdefghijklmno"
         °⊏+1⧻.  # range [0, input length)      [0+ 1 2 ... 7]
      ⁿ:2    # 2 to the power of each       [1 2 4 ... 64]16
     ⍜ₙ⇡2      # those repeat the integers    [0 1 1 2 2 2 2 ... 2^(64 7s)]
  ↙⊃⧻        # cut off at input length   range( log_2( that [0))) 1 1 2[1 2 24 2]8]
⊕□ ⊕□⊚          # group the input string  into pieces that size  {"a" "bc" "defg" "hijklmno"}

Uiua, 11 bytes

⊕□↙⊃⧻⊚ⁿ:2°⊏

Try it online!

A bit inefficient but it gets the job done nice and short.

⊕□↙⊃⧻⊚ⁿ:2°⊏  # input string on the right.   "abcdefg"
         °⊏  # range [0, input length)      [0 1 2 ... 7]
      ⁿ:2    # 2 to the power of each       [1 2 4 ... 64]
           # those repeat the integers    [0 1 1 2 2 2 2 ... (64 7s)]
  ↙⊃⧻        # cut off at input length      [0 1 1 2 2 2 2]
⊕□           # group the input string       {"a" "bc" "defg"}

Uiua, 11 bytes

⊕□⊚⍜ₙ⇡2+1⧻.

Try it online!

Nice and short! (group) and (where) are a great combo for this.

⊕□⊚⍜ₙ⇡2+1⧻.  # input string on the right.   "abcdefghijklmno"
       +1⧻.  # length + 1                   16
   ⍜ₙ⇡2      # 2^( range( log_2( that )))   [1 2 4 8]
⊕□⊚          # group into pieces that size  {"a" "bc" "defg" "hijklmno"}
added 447 characters in body
Source Link
noodle person
  • 8.7k
  • 1
  • 18
  • 70
Loading
Source Link
noodle person
  • 8.7k
  • 1
  • 18
  • 70
Loading