2
\$\begingroup\$

This question already has an answer here:

Your program must take in a string like:

test string

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

t
te
tes
test
test 
test s
test st
test str
test stri
test strin
test string

notice how spaces count!

Good luck! Least Bytes win. ~N

\$\endgroup\$

marked as duplicate by Adnan code-golf Nov 8 '16 at 20:34

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\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
0
\$\begingroup\$

Pyth, 3 bytes

j._

Try it here.

j       Join by newlines
 ._     all prefixes of implicit input
\$\endgroup\$
  • \$\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
3
\$\begingroup\$

05AB1E, 3 bytes

Uses CP-1252 encoding.

.p»

Try it online!

Explanation

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

MATL, 6 bytes

"GX@:)

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
\$\endgroup\$
  • \$\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
1
\$\begingroup\$

Brachylog, 5 bytes

@[@w\

Try it online!

Assuming that a trailing new line is acceptable

Explanation

@[       Take a prefix of the Input
  @w     Write it to STDOUT followed by a linebreak
    \    False: try another prefix of the input
\$\endgroup\$
  • \$\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.