2
\$\begingroup\$

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\$
3
  • \$\begingroup\$ Related. \$\endgroup\$ Nov 8, 2016 at 20:30
  • \$\begingroup\$ Is a trailing new line at the end acceptable? \$\endgroup\$
    – Fatalize
    Nov 8, 2016 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, 2016 at 20:37

4 Answers 4

3
\$\begingroup\$

05AB1E, 3 bytes

Uses CP-1252 encoding.

.p»

Try it online!

Explanation

     # implicit input
.p   # list of prefixes
  »  # join by newlines
\$\endgroup\$
1
  • \$\begingroup\$ Wow! Only 3 bytes! \$\endgroup\$ Nov 8, 2016 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\$
2
  • \$\begingroup\$ Nice job! Do I update the winner as new code is posted? \$\endgroup\$ Nov 8, 2016 at 20:31
  • \$\begingroup\$ Usually we wait for about a week until accepting an answer as winner \$\endgroup\$
    – Luis Mendo
    Nov 8, 2016 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\$
1
  • \$\begingroup\$ A trailing new line is fine. \$\endgroup\$ Nov 8, 2016 at 20:36
0
\$\begingroup\$

Pyth, 3 bytes

j._

Try it here.

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

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