Spell out the Revu'a

16

1

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 "נחמן חמן מן ן".

Adám

Posted 2016-01-08T15:20:11.283

Reputation: 37 779

Answers

2

05AB1E, 1 byte

η

Builtins ftw ¯\_(ツ)_/¯

Outputs as a list of prefixes.

Try it online or verify all test cases.

Explanation:

η  # Push a list of prefixes of the (implicit) input-string
   # (and output this list implicitly as result)

Kevin Cruijssen

Posted 2016-01-08T15:20:11.283

Reputation: 67 575

17

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.

lirtosiast

Posted 2016-01-08T15:20:11.283

Reputation: 20 331

2Exactly the same solution works for the same reason in K. – JohnE – 2016-01-08T16:18:25.883

@JohnE Does K handle Unicode? – Adám – 2016-09-08T05:52:30.890

13

JavaScript (ES6), 27 26 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.

ETHproductions

Posted 2016-01-08T15:20:11.283

Reputation: 47 880

I saved another byte: f=x=>x.replace(/.?/g,"$ ")`. You get an extra leading space but that's allowed. – Neil – 2016-01-09T13:09:26.507

@Neil Thanks, I had no clue that would work! – ETHproductions – 2016-01-10T22:59:08.333

Ugh, I forgot to quote my ` properly, but I see you worked out what I meant. – Neil – 2016-01-11T09:46:31.207

6

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

ETHproductions

Posted 2016-01-08T15:20:11.283

Reputation: 47 880

7

Is using the phrase "Try it online!" and not linking to Try it online! morally acceptable? :P

– Martin Ender – 2016-01-08T17:03:20.323

3@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 – 2016-01-08T17:06:31.497

6

Retina, 11 7 bytes

.
 $`$0

Output is space-separated, with a leading space and a trailing linefeed.

Try it online!

Martin Ender

Posted 2016-01-08T15:20:11.283

Reputation: 184 808

For posterity, it's portable to Perl for 5 more bytes : perl -pE 's/./$$&\n/g'`. (I'm 11 months late, I know) – Dada – 2016-11-08T21:21:23.820

6

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
]

YoYoYonnY

Posted 2016-01-08T15:20:11.283

Reputation: 1 173

14You can post them as separate answers. – nicael – 2016-01-08T16:54:22.590

21You should post them as separate answers. – Timwi – 2016-01-08T17:06:06.823

18You *must* post them as separate answers. – nicael – 2016-01-08T17:06:46.103

22You *WILL* post them as separate answers. – Timwi – 2016-01-08T17:07:30.997

12You CONVINCED me to post them as separate answers. – YoYoYonnY – 2016-01-08T22:30:23.003

6>

  • People on the interwebs CONVINCED me to improve my post by creating seperate answers.
  • SO asked me if I was sure. They said I could use the edit link to improve my answer.
  • I told SO I was sure.
  • SO asked me again.
  • I told SO I was still sure.
  • SO told me they didn't allow robots.
  • Discrimination against robots, SO is getting sued! – YoYoYonnY – 2016-01-08T22:38:57.157

    4

    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.

    Emigna

    Posted 2016-01-08T15:20:11.283

    Reputation: 50 798

    4

    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

    FryAmTheEggman

    Posted 2016-01-08T15:20:11.283

    Reputation: 16 206

    3

    Pyth, 3

    ._z
    

    Prefix builtin does the trick.

    Test Suite

    FryAmTheEggman

    Posted 2016-01-08T15:20:11.283

    Reputation: 16 206

    3

    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.

    Digital Trauma

    Posted 2016-01-08T15:20:11.283

    Reputation: 64 644

    3

    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.

    Fatalize

    Posted 2016-01-08T15:20:11.283

    Reputation: 32 976

    Why non-competing? – Adám – 2016-11-08T21:58:14.123

    @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 – 2016-11-08T22:01:04.323

    2

    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.
    }*
    

    Martin Ender

    Posted 2016-01-08T15:20:11.283

    Reputation: 184 808

    I totally expected CJam to be shorter than that. – Timwi – 2016-01-08T16:20:54.463

    @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 – 2016-01-08T16:22:07.100

    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 – 2016-01-08T18:30:38.550

    2

    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.

    nicael

    Posted 2016-01-08T15:20:11.283

    Reputation: 4 585

    2

    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.

    lirtosiast

    Posted 2016-01-08T15:20:11.283

    Reputation: 20 331

    2

    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;
    }
    

    YoYoYonnY

    Posted 2016-01-08T15:20:11.283

    Reputation: 1 173

    2

    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);
        }
    }
    

    YoYoYonnY

    Posted 2016-01-08T15:20:11.283

    Reputation: 1 173

    2

    Python, 54 Bytes

    b='';y=input()
    for a in range(len(y)):b+=y[a];print(b)
    

    Dignissimus - Spammy

    Posted 2016-01-08T15:20:11.283

    Reputation: 449

    2

    Java 8, 95 92 58 bytes

    s->{for(int i=0;;)System.out.println(s.substring(0,++i));}
    

    Try it online.

    Explanation:

    s->{                        // Method with String parameter and no return-type
      for(int i=0;              //  Index-integer, starting at 0
          ;)                    //  Loop indefinitely:
        System.out.println(     //   Print with trailing newline:
          s.substring(0,++i     //    Increase the index by 1 first with `++i`
                           ));} //    And print an input-substring in the range [0,i)
    

    Stops the infinite loop with a StringIndexOutOfBoundsException after everything has been printed to STDOUT already, which is allowed according to the meta.

    Kevin Cruijssen

    Posted 2016-01-08T15:20:11.283

    Reputation: 67 575

    1

    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
    

    Luis Mendo

    Posted 2016-01-08T15:20:11.283

    Reputation: 87 464

    1

    Mathematica, 29 bytes

    #<>#2&~FoldList~Characters@#&
    

    TODO: explanation

    LegionMammal978

    Posted 2016-01-08T15:20:11.283

    Reputation: 15 731

    1

    , 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
    

    Mama Fun Roll

    Posted 2016-01-08T15:20:11.283

    Reputation: 7 234

    1

    Javascript ES6, 29 bytes

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

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

    Mama Fun Roll

    Posted 2016-01-08T15:20:11.283

    Reputation: 7 234

    1

    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)
    

    Dignissimus - Spammy

    Posted 2016-01-08T15:20:11.283

    Reputation: 449

    1

    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
    

    xnor

    Posted 2016-01-08T15:20:11.283

    Reputation: 115 687

    1

    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
    

    James

    Posted 2016-01-08T15:20:11.283

    Reputation: 54 537

    1

    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
    

    AdmBorkBork

    Posted 2016-01-08T15:20:11.283

    Reputation: 41 581

    0

    PHP, 59 Bytes

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

    Online Version

    Jörg Hülsermann

    Posted 2016-01-08T15:20:11.283

    Reputation: 13 026

    0

    faso

    Posted 2016-01-08T15:20:11.283

    Reputation: 141

    0

    .+?, 18 bytes

    ^((.+).)
    \2\n\1
    $
    
    

    Explanation

    ^((.+).)   Replace the first line with
    \2         The first line missing the last character
      \n       A newline
        \1     The first line
    $          Repeat until the regex doesn't match (when first line has 1 character)
    

    Try it online! (The second command line argument is input)

    EdgyNerd

    Posted 2016-01-08T15:20:11.283

    Reputation: 1 106

    0

    Burlesque, 2 bytes

    iT
    

    Try it online!

    iT # Generate inits
    

    DeathIncarnate

    Posted 2016-01-08T15:20:11.283

    Reputation: 916

    0

    GolfScript, 10 bytes

    Courtesy to a'_' for saving two bytes by removing redundant bits!

    :i,,{)i<}/
    

    Nice short and cute response :)

    :i,,{)i>}% #Revu'a Sequence
    :i           #Remember the input as i
      ,,         #Array from 0 to i-1
        {   }% #Block, for each element, map this
        {)  }% #Increment the number by 1
        { i }% #Move i to the top of the stack
        {  >}% #Print the characters less than the index i
    

    Try it online!

    Mathgeek

    Posted 2016-01-08T15:20:11.283

    Reputation: 408

    GolfScript, 10 bytes. Explanation. (Because < isn't order-sensitive, and you can return as a list.) – a'_' – 2020-02-22T02:46:43.937

    Oh, durr! Didn't even think about doing listwise comparisons - mental slip there, good find! – Mathgeek – 2020-02-24T13:15:37.043