Spell out the Revu'a

Actually not inspired neither by Atbash Self Palindromes nor by Generalized Gematria Calculator.

Given a string s of length n, output the Revu'a sequence, which is the first character of s, the first two characters of s, ... the first n–2 characters of s, the first n–1 characters of s, the entire s.

The string will only consist of Unicode (any encoding you want) characters that have strong directionality and are found in the range 0x0000 through 0xFFFF. However, no directionality control characters will occur. All characters in any given string will have the same directionality.

You may return in array notation ["t","te","tes","test"], as a space-separated string "t te tes test", as multi-line text
t
te
tes
test
, a pre-formatted array

t
te
tes
test
, or anything similar. Amounts of leading, separating, and trailing spacing is not important, and neither are trailing newline. Ask if in doubt.

Right-to-Left input must result in Right-to-Left output in proper order:
Input: "נחמן"
Output: "נ נח נחמ נחמן" or

נ
נח
נחמ
נחמן

, or ["נ","נח","נחמ","נחמן"]. Among invalid results are "נחמן נחמ נח נ" ,"ן מן חמן נחמן", and "נחמן חמן מן ן".

Dyalog APL, 2 bytes

,\


Cumulative reduce by concatenate. Try it here.

The formatting of the output is nicer when you prefix a ⍕, but it clearly shows the correct order without.

• Exactly the same solution works for the same reason in K. – JohnE Jan 8 '16 at 16:18
• @JohnE Does K handle Unicode? – Adám Sep 8 '16 at 5:52

JavaScript (ES6), 2726 25 bytes

Saved one byte thanks to @nicael and @MartinBüttner, one thanks to @Neil

x=>x.replace(/.?/g,"$ ")  Takes advantage of some built-in features of JS's .replace function. Specifically, in the replacement, $ becomes everything preceding the matched character. Using the regex /.?/g rather than /./g means it also matches the empty string at the end.

• I saved another byte: f=x=>x.replace(/.?/g,"$ "). You get an extra leading space but that's allowed. – Neil Jan 9 '16 at 13:09 • @Neil Thanks, I had no clue that would work! – ETHproductions Jan 10 '16 at 22:59 • Ugh, I forgot to quote my  properly, but I see you worked out what I meant. – Neil Jan 11 '16 at 9:46 Japt, 10 4 bytes I didn't realize that a cumulative reduce would be so useful in this case. :-) U¬å+  Outputs as an array, comma-separated by default. If this is not allowed, use this 6-byte code instead: U¬å+ ·  Try it online! How it works  // Implicit: U = input string U¬ // Split U into chars. å+ // Cumulative reduce: loop through each item in the array, concatenating it to the total. // ["t","e","s","t"] => ["t","te","tes","test"]. // Implicit: output last expression  • Is using the phrase "Try it online!" and not linking to Try it online! morally acceptable? :P – Martin Ender Jan 8 '16 at 17:03 • @MartinBüttner I'd been using that phrase in Japt answers for about a month before Dennis trademarked it. I feel I should have some moral right to keep using it :P – ETHproductions Jan 8 '16 at 17:06 Brainfuck, 40 bytes My console doesn't support Right-to-Left characters, but I don't think it will work :c ++++++++++>,[>,]<[<]>[[<+>-]<[<]>[.>]>]  Ungolfed: ++++++++++> # Store 10 (Newline) ,[>,] # Store input <[<]> # Goto first character [ # While next character [<+>-] # Copy character to the left <[<]> # Goto first character [.>] # Print all charaters > # Go to next character ]  • You can post them as separate answers. – nicael Jan 8 '16 at 16:54 • You should post them as separate answers. – Timwi Jan 8 '16 at 17:06 • You must post them as separate answers. – nicael Jan 8 '16 at 17:06 • You WILL post them as separate answers. – Timwi Jan 8 '16 at 17:07 • You CONVINCED me to post them as separate answers. – YoYoYonnY Jan 8 '16 at 22:30 Retina, 11 7 bytes .$$0  Output is space-separated, with a leading space and a trailing linefeed. Try it online! • For posterity, it's portable to Perl for 5 more bytes : perl -pE 's/./$$&\n/g'. (I'm 11 months late, I know) – Dada Nov 8 '16 at 21:21 Python, 35 f=lambda s:f(s[:-1])+[s]if s else[]  Couldn't find a way to use and/or to simplify the recursion because [] is falsy. Recursive solution, returns a list of strings. Try it online Prolog (SWI), 60 49 bytes Code: p(X):-findall(S,atom_prefix(X,S),[_|R]),write(R).  Explained: atom_prefix with X set to input and S as a variable gives 1 prefix of the atom X starting with the empty atom. findall gets all solutions and puts them in a list. [_|R] throws away the head (the empty atom) and stores the tail in R Examples: p('נחמן'). [נ, נח, נחמ, נחמן] p('test'). [t, te, tes, test]  Try it online here Edit: saved 11 bytes by only storing the tail in R. Pyth, 3 ._z  Prefix builtin does the trick. Test Suite GNU Sed, 21 Score includes +1 for -E option to sed: : s/^(\S+)\S/\1 &/ t  Works for LTR, but not RTL - I missed that bit.. Actually it does work, the RTL was just not rendering correctly in my terminal. It works fine with IO viewed in a sensible text editor (e.g. emacs). It also works in Ideone: Try it online. Brachylog, 5 bytes (Non-competing) @[@w\  Try it online! Explanation @[ Take a prefix of the input @w Write this prefix to STDOUT followed by a linebreak \ False: try another prefix  Right-to-left strings seem to work properly, even though I never even considered them. • Why non-competing? – Adám Nov 8 '16 at 21:58 • @Adám @[ and @w were implemented necessarily after April/May 2016. One could find the exact date on the Github commits but it surely isn't before this challenge was submitted. – Fatalize Nov 8 '16 at 22:01 CJam, 9 bytes l{N2$@+}*


Output is linefeed-separated.

Test it here.

Explanation

l     e# Read input.
{     e# Fold this block over the input, which is effectively a foreach-loop which skips
e# the first character...
N   e#   Push a linefeed.
2$e# Copy the previous string. @ e# Pull up the current character. + e# Concatenate. }*  • I totally expected CJam to be shorter than that. – Timwi Jan 8 '16 at 16:20 • @Timwi There is neither a "get all prefixes/suffixes" built-in nor a higher-order function for generalised accumulation, so even if this isn't optimal I doubt it can be beaten significantly. – Martin Ender Jan 8 '16 at 16:22 • Ll{+_p}/; is same length, posting because I'm not sure if someone with more experience might be able to golf it more, and also maybe fix the quotes thing :P – FryAmTheEggman Jan 8 '16 at 18:30 JavaScript, 36 bytes x=>[...x].map((c,i)=>x.slice(0,i+1))  Demo: a=x=>[...x].map((c,i)=>x.slice(0,i+1)); document.write( a("test")+"<br>"+ a("נחמן") ) The principle is to map and output the slice of string from the first char to the every char in the word. Surprisingly, this works perfectly for the RTL strings too, no optimization needed. My console doesn't support Right-to-Left characters, but I don't think it will work :c C, 74 bytes (2nd entry) char m[2<<9];i;main(){do{m[i]=getchar();printf("%s ",m);}while(m[i++]>0);}  Ungolfed: #include <stdio.h> // char, because printf("%s", str); expects a array of characters. char str[2<<9]; int str_len = 0; int main(void) { do { str[str_len]=getchar(); printf("%s ", str); } while(m[i++]>0); return 0; }  My console doesn't support Right-to-Left characters, but I don't think it will work :c C, 105 bytes (3th entry) m[2<<9];i;j;k;main(){while((m[i++]=getchar())<0);for(;j<i;j++,putchar(10))for(k=0;k<j;k++)putchar(m[k]);}  Ungolfed: #include <stdio.h> int str[2<<9]; int str_len = 0; int main(void) { do { str[str_len] = getchar(); } while(str[str_len++] != EOF); int i; for(i=0; i<str_len; i++) { int j; for(j=0; j<i; j++) { putchar(str[j]); } putchar(10); } }  TI-BASIC, 18 bytes For(X,1,10^(9 Disp sub(Ans,1,X End  Not technically valid: TI-BASIC doesn't support Unicode. Name this prgmA, and input using Ans. Program recursion would be shorter, but there would be no way to initialize the variables. Therefore, we display a substring of the input at each iteration. The input is never overwritten, since Disp doesn't return a value. Eventually, the program terminates with an error after printing the whole string. Python, 54 Bytes b='';y=input() for a in range(len(y)):b+=y[a];print(b)  Java 7, 95 92 bytes String d(String a){for(int i=a.length();i-->0;a=a.substring(0,i)+(i>0?"\n":"")+a);return a;}  Previous answer (95 bytes): String c(String s){String r="";for(int i=0;++i<=s.length();r+=s.substring(0,i)+"\n");return r;}  I tried a recursive approach, but I couldn't really get it to work. Perhaps someone else will (shorter than this for-loop). Ungolfed & test cases: Try it here. class M{ static String d(String a){ for(int i = a.length(); i-- > 0; a = a.substring(0, i) + (i > 0 ? "\n" : "") + a); return a; } public static void main(String[] a){ System.out.println(c("test")); System.out.println(); System.out.println(c("נחמן")); } }  Output: t te tes test נ נח נחמ נחמן  Dip, 1 byte (non-competing) E  Explanation: . # Implicit input E # Get prefixes . # Implicit print  • Never heard of Dip. – Adám Nov 9 '16 at 0:17 • @Adám There.... – Oliver Ni Nov 9 '16 at 0:30 MATL, 8 bytes Uses current version (8.0.0) of language/compiler jtn1X"YR  Example >> matl > jtn1X"YR > > test t te tes test  Explanation j % input string tn % duplicate and get length, say "N" 1X" % repeat string N times vertically. Gives a char matrix YR % lower triangular part of matrix. Implicitly print  Mathematica, 29 bytes #<>#2&~FoldList~Characters@#&  TODO: explanation 𝔼𝕊𝕄𝕚𝕟, 7 chars / 16 bytes ᴉⓜᵖ ᵴ˖$


Try it here (Firefox only).

There's probably a builtin for this somewhere - I just haven't found it.

Explanation

ᴉⓜᵖ ᵴ˖$// implicit: ᴉ=split input, ᵴ=empty string ᴉⓜ // map over ᴉ ᵖ ᵴ˖$ // push ᵴ+=(mapped item char)
// implicit stack output, separated by newlines


Javascript ES6, 29 bytes

(a,b='')=>[...a].map(x=>b+=x)


This ain't winning anything, but it's a simple solution.

Pyth, 11 Bytes

Vlz=k+k@zNk


Try It Out

Explanation

(z=input)
(k="")
V        for N in Range(
lz       length of z):
=k+k@zN     k=k+z[N]
k           print(k)


Python, 32 bytes

f=lambda s:s and f(s[:-1])+" "+s


Recursive function that outputs a space-separated string with a leading space.

A 34-byte program (Python 2):

s=""
for c in input():s+=c;print s


V, 5 bytes (non-competing)

òÄ$xh  Try it online! This language is newer than the challenge, making this answer non-competing. Explanation: ò " Recursively: Ä " Duplicate this line$     "   Move to the end of this line
x    "   Delete one character
h   "   Move one character to the right, which will throw an error when the line is one character long


PowerShell v2+, 28 bytes

[char[]]$args[0]|%{($o+=$_)}  Takes input $args[0], casts it as a char-array, pipes the characters into a loop |%{...}. Each iteration, we accumulate onto $o via += the current character $_. That expression is encapsulated in parens so a copy is placed on the pipeline. At end of execution, the pipeline is flushed via Write-Output which puts a newline between elements.

PS C:\Tools\Scripts\golfing> .\spell-out-the-revua "נחמן"
נ
נח
נחמ
נחמן

PS C:\Tools\Scripts\golfing> .\spell-out-the-revua "PPCG"
P
PP
PPC
PPCG


PHP, 59 Bytes

for(;$i++<mb_strlen($argn);)echo"\n".mb_substr($argn,0,$i);


Online Version

Unwanted, Unnecessary, Opportunistic, 9 bytes

E<+S0;*P