g | x | w | all
Bytes Lang Time Link
047Haskell241215T213145ZMaroonSp
041AWK241029T204105Zxrs
090Raku Perl 6 rakudo240820T090906ZThemooni
009Pyth240820T081827Zint 21h
009Uiua240703T112631Znoodle p
046tinylisp 2240816T190028ZDLosc
044JavaScript Node.js240714T232756ZAndrew B
055Haskell240705T151856ZDPD-
022Haskell + hgl240707T133716ZWheat Wi
010Pip p240707T025922ZAiden Ch
036Julia 1.0240706T125129ZMarcMush
037Ruby240703T091600Zint 21h
012APL Dyalog Extended240702T224208ZAdá
1785Nibbles240704T155522ZDominic
050C gcc240703T211432Zcorvus_1
019GolfScript240703T115536ZTwilight
041Python 3.8 prerelease240702T225141Zsquarero
026brainfuck240702T233900Znoodle p
012J240703T190336Znoodle p
012Brachylog240704T093923ZFatalize
3534Excel240703T040741Zz..
054Julia 1.0240703T150526ZAshlin H
028Perl 5 n240703T140300ZXcali
011MathGolf240703T131038ZKevin Cr
005Husk240703T123630ZDominic
00605AB1E240703T084621ZKevin Cr
043PowerShell240703T115900Zuser3141
015K ngn/k240703T112728Zovs
041Google Sheets240702T230407Zdoubleun
005Japt m240703T085355ZShaggy
032Arturo240703T074338Zchunes
046R240703T073506Zpajonk
020APL+WIN240703T062803ZGraham
013Charcoal240703T054954ZNeil
058C gcc240703T045119ZDigital
011Uiua240703T005301Znoodle p
005Nekomata240703T020237Zalephalp
038JavaScript V8240703T011421Zl4m2
016K ngn/k240703T000159ZBubbler
016J240703T001653ZBubbler
021Retina 0.8.2240702T235815ZNeil
005Jelly240702T230349ZJonathan
003Vyxal240702T224503Zlyxal

Haskell, 47 bytes

g n""=[]
g n s|(h,t)<-splitAt n s=h:g(n*2)t
g 1

Try it online!

It returns the answer as a list of strings. This is basically the simplest possible answer. More readably, it might be written like this:

go n "" = []
go n string = chunk : go (n*2) string'
  where (chunk, string') = splitAt n string

AWK, 64 52 41 bytes

{for(i=1;i<NF;i=2*i)print substr($0,i,i)}

Use [ -F '' ] flag upon calling awk to separate fields and give us the right number for NF.

{for(i=1;i<length($0);i=2*i)printf substr($0,i,i)FS}

Try it online!

{for(i=1;i<length($0);i=2*i)printf substr($0,i,i)"\n"(y=y y" ")}


{for(i=1;i<length($0);i=2*i) # twice as many letters per
printf substr($0,i,i)        # just the letters we need
"\n"(y=y y" ")}              # whitespace for next line

Raku (Perl 6) (rakudo), 90 bytes

sub MAIN($i){my $s=$i;for (1,2,4...^*>$s.chars) ->$x {say $s.substr(0,$x);$s.=substr($x)}}

Attempt This Online!

ungolfed:

sub MAIN($i){
    my $s=$i;
    for (1,2,4...^*>$s.chars) ->$x {
        say $s.substr(0,$x);
        $s.=substr($x)
    }
}

straightfowards and uninventive and probably not very golfed but this is my first time doing raku or perl and i wanted to try it out.

Pyth, 9 bytes

fTcQtM^2U

Try it online!

Takes a string as an input and outputs a list of strings.

        U # create a range 0..length of the string
      ^2  # make them powers of 2
    tM    # decrease by 1
  cQ      # chop the input string Q
fT        # remove empty strings

Uiua, 9 bytes

This solution was written by Kai Schmidt, the creator of Uiua, not by me, so I'm making this a community wiki.

⊕□⌊ₙ2+1°⊏

Try it!

This is a very simple solution, and very short: Take the range of 0 to the length of the input, add one to each, take the base-2 logarithm, and floor it. This list has natural numbers repeated doubling in length, so we use this as a group to take each part of the input into a list of boxes.

tinylisp 2, 46 bytes

(d F(\(S(I 1))(? S(c(] I S)(F([ I S)(* I 2)))(

Try It Online!

Ungolfed & commented

(def segments
 (lambda        ; Function
  (S (I 1))     ; Takes two args: a string, and a number defaulting to 1
  (if S         ; If the string is nonempty:
   (cons        ;  Prepend
    (take I S)  ;  the first I characters of S
    (segments   ;  to the result of a recursive call on
     (drop I S) ;   All but the first I characters of S
     (* I 2)))  ;   I times 2
   nil)))       ; Else, empty list

JavaScript (Node.js), 44 bytes

x=>[...x].reduce((a,c,i)=>i&++i?a+c:a+' '+c)

Try it online!

Haskell, 61 58 56 55 bytes

takeWhile(>"").evalState(mapM(state.splitAt.(2^))[0..])

Try it online!

It maps (with state) over the infinite sequence of powers of two. Each map step returns the first n characters of the string in the state and puts the remaining in the state. So giving as initial state the string and stop iterating when the result is the empty string, we obtain the result.

Haskell + hgl, 22 bytes

This answer was written jointly with 0 '

cr<<<gB(l<bi<st)<zp nN

Attempt This Online!

Explanation

23 bytes

he<pST(fo<pa(eq<db.*l))

Attempt This Online!

Explanation

This implements an exponential time algorithm. Unlike the previous solution this errors when the input is not one less than a power of two in length.

Reflection

There are quite a few things I see here to improve.

As of 79db5b20 these reflections are implemented and this answer can be

10 bytes

xuc$pw2<nn

18 bytes

cr<<<gB(lB2<st)<eU

19 bytes

he<pST(apa$eq<db.*l)

Pip -p, 10 bytes

a^@--E\,#a

I feel there could be 1 or 2 bytes improvement but I don't see it at the moment.

Attempt This Online!

Julia 1.0, 36 bytes

!s=keys(s).|>k->show(s[2^~-k:~-2^k])

Try it online!

Ends with an error. Substrings are printed in quotes. Cleaner output with println instead of show (+3 bytes)

Ruby, 55 53 47 45 37 bytes

f=->s,a=1{s&&[s[0,a],*f[s[a..],a+a]]}

Attempt This Online!

@OP just to let you know, the easy tasks are welcome! :)

A recursive function with 2 variables: the original string and the counter. The function chops a string piece, adds it to the unnamed output vector and updates the counter until the string is empty.

APL (Dyalog Extended), 16 12 bytes

Anonymous tacit prefix function, port of Bubbler's J.

⊢⊂⍨1=1⊥2⊤⍳∘≢

 the argument…

⊂⍨ partitioned by…

1= where one equals…

1⊥  the vertical sum (lit. base-1 evaluation) of…

2⊤ the binary representation (one number per column) of

⍳∘  the indices from 1 to the…

 length of the argument

Try it online!

Alternative APL (Dyalog Unicode), 12 bytes

Anonymous tacit prefix function, port of noodle person's J.

⊢⊆⍨1+∘⌊2⍟⍳∘≢

 the argument…

⊂⍨ grouped by…

1+∘ incremented…

 floored…

2⍟ log₂ of…

⍳∘ the indices of…

 the argument length Try it online!

Old APL (Dyalog Unicode), 16 bytes

Anonymous tacit prefix function. Requires 0-based indexing (⎕IO←0) which is default on many systems.

⊢⊂⍨≢↑∘∊1↑¨⍨2*⍳∘≢

Try it online!

 the argument…

⊂⍨ partitioned by…

 the length of the argument…

↑∘∊ -sized prefix of the the flattened…

1↑¨⍨ prefixes of 1 (padding with trailing 0s) of lengths…

2* two to the power of…

⍳∘≢ the indices (0…n−1) of the length of the argument

Nibbles, 17 nibbles (8.5 bytes)

| . `,,$ <;^2$ >-$~ _

Attempt This Online!

  .                     # map over
    `,                  # range from zero to
      ,$                # length of input:
         <              #   take the first
           ^2$          #   2^n characters
          ;             #   (and save that number)
                        #   from
               >        #   drop the first
                -$~     #   saved number minus 1
                        #   characters
                        #   from
                    _   #   the input
|                       # and finally filter-out 
                        # any empty strings

Nibbles, 17 nibbles (8.5 bytes)

\ ! ;`. $ </,$~$ >>@ ~ -

Attempt This Online!

A completely different approach for same bytes: successively halve the string and take pairwise differences.

\ ! ;`. $ </,$~$ >>@ ~ -
     `'                     # iterate while unique
        $                   # starting with the input:
          <                 #   select the first
           /,$~             #   half its length
               $            #   characters
    ;                       # and save this list;
  !                         # now, zip this list with
                 >>@        # itself without the first element:
                     ~ -    #   get differences;
\                           # finally, reverse it

This would be 1 nibble shorter if we're allowed to output the divided segments in reverse order.

C (gcc), 54 50 bytes

-4 bytes thanks to Mukundan314

i;f(s,l){for(i=1;i<l;i*=2)puts(strndup(s+i-1,i));}

Try it online!

May have a memory leak or two.

GolfScript, 20 19 bytes

1/.,,{).)&!n*}%]zip

Try it online!

Python 3.8 (pre-release),  66   65   50   49   46   42  41 bytes

-1 byte by doing away with int.bit_length().
-15 bytes: recursion for the win!
-1 byte by using list unpacking instead of list().
-3 bytes by moving some stuff around.
-4 bytes by using and instead of the ternary ... if ... else ....
-1 byte by Jakque.

f=lambda x,n=1:x and[x[:n],*f(x[n:],2*n)]

Try it online!

brainfuck, 26 bytes

+[[->,.>++<<]+++++++++.>>]

Attempt This Online!

Output separated by tabs with some extra tabs at the end.

This is pretty short so I may as well add an explanation:

+        1 is the first segment length
[  
  [-     Repeat that many times:
    >,.    Go right: read and output one character
    >++    Go right: Add two to this cell
             (This is what doubles the length)
    <<]    Go back to the loop counter cell
  +++++  The cell is now zero so we can freely
  ++++.    change it; output a tab (ASCII 9)
  >>]    Go to our new loop counter cell and start
           again

J, 16 12 bytes

</.~2<.@^.#\

Attempt This Online!

This is my first time trying to golf in J! I got a lot of help golfing the forks and whatnot. I tried a different method from Bubbler's way and it ended 4 bytes shorter :)

Thanks to ovs for telling me about #\ which is a much shorter way of getting the length-one-range.

Explanation:

</.~2<.@^.#\
</.~          NB. Group the items of the input by
    2<.@^.    NB. floors of the base-2 logarithms of
          #\  NB. the range of 1 to the input's length.
              NB.   (Literally: length of prefixes)

Brachylog, 12 bytes

{Ẹg|ḍgᵗ↰ʰc}b

Try it online!

Explanation

We rely on ḍ - dichotomize to split the string in 2. When the length is odd, the first string is shorter which is what we want. We then recurse dichotomization on the first string. The tricky part is then to flatten the list recursively up in the same predicate. We use the same idea as @Dlosc answer here, integrated directly in the predicate thas splits the string instead of applied after (which is longer).

{         }     Apply the following predicate on the input string:
 Ẹ                If the input is the empty string ""…
  g                …output [""]
   |              Else
    ḍ             Dichotomize the string [<first half>, <second half>]
     gᵗ           Wrap the second half in a list
       ↰ʰ         Recursive call on the first half
         c        Concatenate to flatten the current level

           b    Remove the first element which is the empty string at the end

Excel, 35 34 bytes

-1 byte thanks to @doubleunary

=LET(i,2^(ROW(A:A)-1),MID(A1,i,i))

enter image description here

Julia 1.0, 54 bytes

~s=[s[2^i:2*2^i-1] for i=0:floor(Int,log2(length(s)))]

Try it online!

Uses array comprehension to generate pairs of indices. The related solution with map takes the same number of bytes:

Julia 1.0, 54 bytes

~s=map(i->s[2^i:2*2^i-1],0:floor(Int,log2(length(s))))

Try it online!

Perl 5 -n, 28 bytes

($.*=2)&say$&while s/.{$.}//

Try it online!

MathGolf, 12 11 bytes

hâΣÆïó‼<≥;]

Try it online.

Explanation:

Step 1: Calculate the amount of parts we need to output, basically \$\log_2(length+1)\$ manually:

          #  (e.g. input = "abcdefghijklmno")
h         # Push the length of the (implicit) input-string
          #  → 15
 â        # Convert it to a binary list
          #  → [1,1,1,1]
  Σ       # Sum this list of 1-bits
          #  → 4

Step 2: Actually split the input into the power of 2 parts:

Æ         # Loop in the range [0,value],
          # using 5 characters as inner code-block:
 ï        #  Push the current 0-based loop-index
  ó       #  Pop and convert it to 2 to the power this index
   ‼      #  Apply the next two operators separately on the current stack:
    <     #   Slice to substring [0,val)
     ≥    #   Slice to substring [val,length)
      ;   # After the loop: discard the trailing no-op part
       ]  # Wrap all correct parts on the stack into a list
          # (after which the entire stack is output implicitly as result)

Husk, 5 bytes

C:1İ2

Try it online!

C       # cut input into chunks with lengths:
 :1     # prepend 1 to
   İ2   # infinite sequence of powers of 2
        # (starting at 2)

05AB1E, 6 bytes

gÝo£õÜ

Try it online.

Or minor alternative:

ā<o£ʒĀ

Try it online.

Explanation:

g       #  Push the length of the (implicit) input-list
 Ý      #  Pop and push a list in the range [0,length]
        # OR:
ā       #  Push a list in the range [1, (implicit) input-length]
 <      #  Decrease each by 1 to the range [0,length)
  o     # Map each value to 2 to the power this value
   £    # Split the (implicit) input-string into parts of those sizes
    õÜ  #  Trim all trailing ""
        # OR:
    ʒ   #  Filter these string-parts:
     Ā  #   Check if truthy (where "" is falsey)
        # (after which the result is output implicitly)

PowerShell, 43 bytes

%{for($i=1;$_[$i];$i*=2){$_|% S*g($i-1)$i}}

Try it online!

Straightforward: extract substrings of doubling length at doubling start indexes.
Relevant golfing:

K (ngn/k), 15 bytes

{x@.=+|\2\!-#x}

Try it online!

x:"abcdefg"
!-#x          / integers from -length to -1
  -7 -6 -5 -4 -3 -2 -1
2\!-#x        / convert to base 2
  -1 -1 -1 -1 -1 -1 -1
   0  0  0  1  1  1  1
   0  1  1  0  0  1  1
   1  0  1  0  1  0  1
|\2\!-#x      / maximum scan
  -1 -1 -1 -1 -1 -1 -1
   0  0  0  1  1  1  1
   0  1  1  1  1  1  1
   1  1  1  1  1  1  1
.=+|\2\!-#x   / group identical columns
   (,0; 1 2; 3 4 5 6)
x@.=+|\2\!-#x / index back into the input string
   (,"a"; "bc"; "defg")

Google Sheets, 41 bytes

=index(let(i,2^(row(A:A)-1),mid(A1,i,i)))

screenshot

Japt -m, 9 7 5 bytes

Input as a character array, output as a 2D character array

Wv2pV

Try it

Arturo, 34 32 bytes

$=>[i:1chunk&=>[2i'i+1ceil log]]

Try it!

Explanation

$=>[]        ; a function where input is assigned to &
i:1          ; assign 1 to i
chunk&=>[]   ; split input by...
2i ceil log  ; bit length of i
'i+1         ; increment i

R, 46 bytes

\(x)substring(x,a<-2^(0:log2(nchar(x))),2*a-1)

Attempt This Online!

Takes input as a string and outputs a vector of strings.


R, 44 bytes

\(x)split(x,rep(i<-2^(0:log2(length(x))),i))

Attempt This Online!

Takes input as a vector of characters and outputs a list of vectors of characters.

APL+WIN, 20 bytes

Prompts for string. Outputs a nested vector of segments. Index origin = 0

(∊n⍴¨n←2*⍳⌈2⍟⍴s)⊂s←⎕

Try it online! Thanks to Dyalog Classic

Charcoal, 13 bytes

E↨Lθ²×ψX²κ↑¤θ

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

E↨Lθ²×ψX²κ

Reserve a number of lines corresponding to the 1s in the base-2 representation of the input length, with each line's length being each power of 2 in turn, according to its index.

↑¤θ

Fill that reserved area using the original input string, thereby partitioning it as required.

C (gcc), 58

f(s,i)char*s;{while(putchar(*s++))if(!(++i&i-1))puts("");}

Try it online!

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"}

Nekomata, 5 bytes

JxËᶻL

Attempt This Online!

JxËᶻL
J       Split the input into a list of substrings
 x      Push [0, ..., length of the list - 1]
  Ë     Power of 2
   ᶻL   Check that each substring has the corresponding length

JavaScript (V8), 38 bytes

x=>x.replace(/|/g,_=>i&++i?'':' ',i=0)

Try it online!

Separate by space

K (ngn/k), 16 bytes

{(&*/'2\'!#x)_x}

Try it online!

A near-backport from my own J solution. Instead of checking each 1-based index has exactly one 1 bit, this checks if each 0-based index is all ones in binary. This works in K (2\0 is an empty array and its product is 1) but not in J (#:0 is 0 instead of an empty array).

K (ngn/k), 17 bytes

{(|1_(-2!)\#x)_x}

Try it online!

Similar to Jelly (x_y cuts y at the indices specified in x), but had to be careful to avoid generating large indices or indices in non-increasing order (which give domain error).

My initial approach used 2\ (integer into binary vector) and 2/ (binary vector into integer), but I realized that simply repeatedly dividing the length by 2 gives the correct cut indices.

{(|1_(-2!)\#x)_x}    Input: a string of length 2^n-1 (example: "abcdefg")
 (         #x)       length of x = 7
     (-2!)\          repeatedly floor-divide by 2 until convergence and collect:
                     (7 3 1 0)
   1_                remove head which is too large (3 1 0)
  |                  reverse (0 1 3)
              _x     cut x with those indices ("a"; "bc"; "defg")

J, 16 bytes

<;.1~1=1#.[:#:#\

Attempt This Online!

<;.1~1=1#.[:#:#\     Input: string of length 2^n-1 (example: 'abcdefg')
              #\     1-based indices (1 2 3 4 5 6 7)
          [:#:       each number to binary (0 0 1; 0 1 0; 0 1 1; 1 0 0; ...; 1 1 1)
       1#.           sum the bits of each number (1 1 2 1 2 2 3)
     1=              is it 1? (1 1 0 1 0 0 0)
<;.1~                cut at 1s and box each word ('a'; 'bc'; 'defg')

Retina 0.8.2, 21 bytes

!`(?<=(.)*).(?<-1>.)*

Try it online! Explanation: The last stage is by default a Match stage if there is no replacement pattern for it to be a Replace stage. The ! changes the output from the number of matches (in decimal) to the matches themselves (on separate lines). The pattern then uses a .NET balancing group to count its match index (which will be one less than a power of 2) and allow one character more than that to be matched.

Jelly, 5 bytes

J2*œṖ

A monadic Link that accepts a list and yields a list of lists.

Try it online!

How?

J2*œṖ - Link: List of characters, S
J     - indices -> [1..len(S)]
 2*   - two exponentiate {that}
   œṖ - partition {S} at {those} indices

Vyxal, 3 bytes

ẏEẇ

Try it Online!

Golf pilled sbcs maxxer.

Explained

ẏEẇ­⁡​‎‎⁡⁠⁡‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁢‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁣‏‏​⁡⁠⁡‌­
ẏ    # ‎⁡Range [0, len input)
 E   # ‎⁢Each to the power of 2
  ẇ  # ‎⁣Partition the string into groups corresponding to each length
💎

Created with the help of Luminespire.