Your program must take in a string like:

test string

And must output each character adding one at a time like this:

test s
test st
test str
test stri
test strin
test string

notice how spaces count!

Good luck! Least Bytes win. ~N

  • \$\begingroup\$ Related. \$\endgroup\$ – AdmBorkBork Nov 8 '16 at 20:30
  • \$\begingroup\$ Is a trailing new line at the end acceptable? \$\endgroup\$ – Fatalize Nov 8 '16 at 20:31
  • \$\begingroup\$ Welcome to Programming Puzzles and Code Golf! This is a nice first challenge :). Unfortunately this has been done before and is therefore a duplicate :(. \$\endgroup\$ – Adnan Nov 8 '16 at 20:37

Pyth, 3 bytes


Try it here.

j       Join by newlines
 ._     all prefixes of implicit input
  • \$\begingroup\$ You should accept Emigna's answer, because it also has 3 bytes and was posted earlier \$\endgroup\$ – Luis Mendo Nov 8 '16 at 21:20

05AB1E, 3 bytes

Uses CP-1252 encoding.


Try it online!


     # implicit input
.p   # list of prefixes
  »  # join by newlines
  • \$\begingroup\$ Wow! Only 3 bytes! \$\endgroup\$ – Noah Cristino Nov 8 '16 at 20:32

MATL, 6 bytes


Try it online!

         % Implicit input
"        % For each
  G      %   Push input again
  X@:    %   Push [1 2 ... k] where k is iteration index
  )      %   Use as index into the string
         % End for each
         % Implicit display
  • \$\begingroup\$ Nice job! Do I update the winner as new code is posted? \$\endgroup\$ – Noah Cristino Nov 8 '16 at 20:31
  • \$\begingroup\$ Usually we wait for about a week until accepting an answer as winner \$\endgroup\$ – Luis Mendo Nov 8 '16 at 20:34

Brachylog, 5 bytes


Try it online!

Assuming that a trailing new line is acceptable


@[       Take a prefix of the Input
  @w     Write it to STDOUT followed by a linebreak
    \    False: try another prefix of the input
  • \$\begingroup\$ A trailing new line is fine. \$\endgroup\$ – Noah Cristino Nov 8 '16 at 20:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.