Skip to main content
Became Hot Network Question
Source Link
noodle person
  • 8.6k
  • 1
  • 18
  • 69

Segments of a string, doubling in length

Simple task today. Given a string whose length is one less than a whole power of 2, divide it into segments with doubling length.

For example for the string abcdefghijklmno, the result should be a, bc, defg, hijklmno:

abcdefghijklmno  (length 15)

a                 length 1
 bc               length 2
   defg           length 4
       hijklmno   length 8

The input will not be the empty string.

This is ; shortest solution per language wins.