P Pr Pre Pref Prefi Prefix Prefixe Prefixes












33














Given some finite list, return a list of all its prefixes, including an empty list, in ascending order of their length.



(Basically implementing the Haskell function inits.)



Details




  • The input list contains numbers (or another type if more convenient).

  • The output must be a list of lists.

  • The submission can, but does not have to be a function, any default I/O can be used.

  • There is a CW answer for all trivial solutions.


Example



 -> []
[42] -> [,[42]]
[1,2,3,4] -> [, [1], [1,2], [1,2,3], [1,2,3,4]]
[4,3,2,1] -> [, [4], [4,3], [4,3,2], [4,3,2,1]]









share|improve this question
























  • If a language does not define any types except for characters, can I take input as a string and separate the input by newlines, in the case of a full program?
    – NieDzejkob
    Dec 8 '18 at 20:37










  • @NieDzejkob I'm not sure what consensus there is for this case, but the Brainfuck answer seems to do something like that.
    – flawr
    Dec 8 '18 at 21:18










  • Can we expect the list to be null-terminated?
    – Rogem
    Dec 9 '18 at 10:02










  • It's especially common in C/C++, main use being strings.
    – Rogem
    Dec 13 '18 at 14:46










  • @Rogem If it is that common I think allowing it is reasonable.
    – flawr
    Dec 13 '18 at 14:49
















33














Given some finite list, return a list of all its prefixes, including an empty list, in ascending order of their length.



(Basically implementing the Haskell function inits.)



Details




  • The input list contains numbers (or another type if more convenient).

  • The output must be a list of lists.

  • The submission can, but does not have to be a function, any default I/O can be used.

  • There is a CW answer for all trivial solutions.


Example



 -> []
[42] -> [,[42]]
[1,2,3,4] -> [, [1], [1,2], [1,2,3], [1,2,3,4]]
[4,3,2,1] -> [, [4], [4,3], [4,3,2], [4,3,2,1]]









share|improve this question
























  • If a language does not define any types except for characters, can I take input as a string and separate the input by newlines, in the case of a full program?
    – NieDzejkob
    Dec 8 '18 at 20:37










  • @NieDzejkob I'm not sure what consensus there is for this case, but the Brainfuck answer seems to do something like that.
    – flawr
    Dec 8 '18 at 21:18










  • Can we expect the list to be null-terminated?
    – Rogem
    Dec 9 '18 at 10:02










  • It's especially common in C/C++, main use being strings.
    – Rogem
    Dec 13 '18 at 14:46










  • @Rogem If it is that common I think allowing it is reasonable.
    – flawr
    Dec 13 '18 at 14:49














33












33








33


3





Given some finite list, return a list of all its prefixes, including an empty list, in ascending order of their length.



(Basically implementing the Haskell function inits.)



Details




  • The input list contains numbers (or another type if more convenient).

  • The output must be a list of lists.

  • The submission can, but does not have to be a function, any default I/O can be used.

  • There is a CW answer for all trivial solutions.


Example



 -> []
[42] -> [,[42]]
[1,2,3,4] -> [, [1], [1,2], [1,2,3], [1,2,3,4]]
[4,3,2,1] -> [, [4], [4,3], [4,3,2], [4,3,2,1]]









share|improve this question















Given some finite list, return a list of all its prefixes, including an empty list, in ascending order of their length.



(Basically implementing the Haskell function inits.)



Details




  • The input list contains numbers (or another type if more convenient).

  • The output must be a list of lists.

  • The submission can, but does not have to be a function, any default I/O can be used.

  • There is a CW answer for all trivial solutions.


Example



 -> []
[42] -> [,[42]]
[1,2,3,4] -> [, [1], [1,2], [1,2,3], [1,2,3,4]]
[4,3,2,1] -> [, [4], [4,3], [4,3,2], [4,3,2,1]]






code-golf array-manipulation function functional-programming






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 7 '18 at 21:52

























asked Dec 7 '18 at 19:16









flawr

26.6k665188




26.6k665188












  • If a language does not define any types except for characters, can I take input as a string and separate the input by newlines, in the case of a full program?
    – NieDzejkob
    Dec 8 '18 at 20:37










  • @NieDzejkob I'm not sure what consensus there is for this case, but the Brainfuck answer seems to do something like that.
    – flawr
    Dec 8 '18 at 21:18










  • Can we expect the list to be null-terminated?
    – Rogem
    Dec 9 '18 at 10:02










  • It's especially common in C/C++, main use being strings.
    – Rogem
    Dec 13 '18 at 14:46










  • @Rogem If it is that common I think allowing it is reasonable.
    – flawr
    Dec 13 '18 at 14:49


















  • If a language does not define any types except for characters, can I take input as a string and separate the input by newlines, in the case of a full program?
    – NieDzejkob
    Dec 8 '18 at 20:37










  • @NieDzejkob I'm not sure what consensus there is for this case, but the Brainfuck answer seems to do something like that.
    – flawr
    Dec 8 '18 at 21:18










  • Can we expect the list to be null-terminated?
    – Rogem
    Dec 9 '18 at 10:02










  • It's especially common in C/C++, main use being strings.
    – Rogem
    Dec 13 '18 at 14:46










  • @Rogem If it is that common I think allowing it is reasonable.
    – flawr
    Dec 13 '18 at 14:49
















If a language does not define any types except for characters, can I take input as a string and separate the input by newlines, in the case of a full program?
– NieDzejkob
Dec 8 '18 at 20:37




If a language does not define any types except for characters, can I take input as a string and separate the input by newlines, in the case of a full program?
– NieDzejkob
Dec 8 '18 at 20:37












@NieDzejkob I'm not sure what consensus there is for this case, but the Brainfuck answer seems to do something like that.
– flawr
Dec 8 '18 at 21:18




@NieDzejkob I'm not sure what consensus there is for this case, but the Brainfuck answer seems to do something like that.
– flawr
Dec 8 '18 at 21:18












Can we expect the list to be null-terminated?
– Rogem
Dec 9 '18 at 10:02




Can we expect the list to be null-terminated?
– Rogem
Dec 9 '18 at 10:02












It's especially common in C/C++, main use being strings.
– Rogem
Dec 13 '18 at 14:46




It's especially common in C/C++, main use being strings.
– Rogem
Dec 13 '18 at 14:46












@Rogem If it is that common I think allowing it is reasonable.
– flawr
Dec 13 '18 at 14:49




@Rogem If it is that common I think allowing it is reasonable.
– flawr
Dec 13 '18 at 14:49










63 Answers
63






active

oldest

votes













1 2
3
next












15















Haskell, 20 bytes



Edit: Yet a byte shorter with a completely different scan.



An anonymous function slightly beating the trivial import.





scanr(_->init)=<<id


Try it online!




  • Uses =<< for the abbreviation (scanr(_->init)=<<id) l = scanr(_->init) l l.

  • Scans a list l from right to left, collecting intermediate results with the function _->init.

  • That function ignores the elements scanned through (they're only used to get the right total length for the collected results), so really iterates applying init to the initial value of the scan, which is also l.






share|improve this answer































    13















    brainfuck, 21 12 bytes



    -9 bytes thanks to Arnauld suggesting the separator ÿ instead of newlines



    -[[<]>[.>],]


    Try it online!



    Takes bytes through STDIN with no null bytes and prints a series of prefixes separated by the ÿ character with a leading ÿ character. For example, for the input Prefixes, the output is ÿÿPÿPrÿPreÿPrefÿPrefiÿPrefixÿPrefixeÿPrefixes.



    For readability, here's a version with newlines instead.



    Explanation:



    -              Create a ÿ character in cell 0
    [ ,] While input, starting with the ÿ
    [<]> Go to the start of the string
    [.>] Print the string
    , Append the input to the end of the string





    share|improve this answer



















    • 1




      This only works on BF implementations with 8-bit, unsigned, wrapping cells.
      – Dev
      Dec 10 '18 at 3:11



















    10














    JavaScript (ES6), 33 bytes



    a=>[b=,...a.map(n=>b=[...b,n])]


    Try it online!



    How?



    +--- a = input array
    |
    | +--- initialize b to an empty array and include it as the first entry
    | | of the output (whatever the input is)
    | |
    | | +--- for each value n in a:
    | | |
    | | | +--- append n to b and include this new array in
    | | | | the final output
    | | | |
    a => [b = , ...a.map(n => b = [...b, n])]
    | |
    +---------+--------+
    |
    spread syntax: expands all elements of
    the child array within the parent array





    share|improve this answer























    • wow, that's a whole new level of code explanation, awesome job :O
      – Brian H.
      Dec 10 '18 at 12:54










    • @BrianH. Thank you! Simple tasks are good opportunities to write detailed explanations that can't be brought up in denser code.
      – Arnauld
      Dec 10 '18 at 13:05










    • Did you make it by hand? or did you get help from any weird software i've never heard about?
      – Brian H.
      Dec 10 '18 at 13:08






    • 2




      Just Notepad++ with some column mode editing.
      – Arnauld
      Dec 10 '18 at 13:30



















    7














    CW for all trivial entries




    Clean, 19 bytes



    Haskell version works in Clean too.



    import StdLib
    inits


    Try it online!




    Haskell, 22 bytes





    import Data.List
    inits


    Try it online!




    Prolog (SWI), 6 bytes



    prefix


    Try it online!






    share|improve this answer























    • So torn - to upvote or not. On the one hand, I appreciate all the built-in solutions in one place. On the other, I really dislike builtins because they're so basic...
      – Rogem
      5 hours ago



















    6















    Jelly, 3 bytes



    ṭṖƤ


    Try it online!



    How it works



    ṭṖƤ  Main link. Argument: A

    Ƥ Map the link to the left over all non-empty(!) prefixes of A.
    Ṗ Pop; remove the last element.
    ṭ Tack; append A to the resulting list.





    share|improve this answer





























      6















      Japt, 4 bytes



      ²£¯Y


      Try it online!



      Explanation:



      ²       :Add an arbitrary extra item to the end of the array
      £ :For each item in the new array:
      ¯Y : Get an array of the items that are before it





      share|improve this answer































        6















        Perl 6, 13 bytes



        {(),|[,] @_}


        Try it online!



        To explain:



        In Perl 6 you can wrap an operator in square brackets as an alternate way to write a list reduction. [+] @array returns the sum of the elements in @array, [*] @array returns the product, etc. You can also precede the operator with a backslash to make a "triangular" reduction, which some languages call "scan." So [+] @array returns a list consisting of the first element of @array, then the sum of the first two elements, then the sum of the first three elements, etc.



        Here [,] @_ is a triangular reduction over the input array @_ using the list construction operator ,. So it evaluates to a lists of lists: the first element of @_, the first two elements of @_, etc. That's almost what's needed, but the problem calls for a single empty list first. So the first element of the return list is a literal empty list (),, then the reduction over the input list is flattened into the rest of the return list with |.






        share|improve this answer



















        • 2




          O_o what is even happening here
          – ASCII-only
          Dec 8 '18 at 4:12






        • 1




          @ASCII-only triangular reduction
          – user202729
          Dec 8 '18 at 4:33



















        5















        Python 2, 32 bytes





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


        Try it online!






        share|improve this answer

















        • 1




          Also works in Python 3
          – ASCII-only
          Dec 8 '18 at 4:14



















        5















        R, 40 39 bytes





        function(L)lapply(0:length(L),head,x=L)


        Try it online!



        -1 byte thanks to digEmAll



        The output of R's list type is a bit weird; it uses sequential indexing, so for instance, the output for



        list(1,2) is



        [[1]]                     # first list element
        list()

        [[2]] # second list element
        [[2]][[1]] # first element of second list element
        [1] 1


        [[3]] # third list element
        [[3]][[1]] # first element of third list element
        [1] 1

        [[3]][[2]] # etc.
        [1] 2


        Taking input as a vector instead gives a neater output format, although then the inputs are not technically lists.






        share|improve this answer



















        • 1




          39 using lapply
          – digEmAll
          Dec 8 '18 at 12:46










        • @digEmAll thanks!
          – Giuseppe
          Dec 10 '18 at 14:41



















        4














        JavaScript, 36 bytes





        a=>[...a,0].map((x,y)=>a.slice(0,y))


        Try it online!






        share|improve this answer































          4














          Mathematica, 22 21 bytes



          -1 byte thanks to Misha Lavrov!



          {}~FoldList@Append~#&


          Pure function. Takes a list as input and returns a list of lists as output. I believe this is the shortest possible solution.






          share|improve this answer























          • We can write the same solution more compactly as {}~FoldList@Append~#&.
            – Misha Lavrov
            Dec 7 '18 at 21:59










          • @MishaLavrov Thanks! I didn't think to use the curried 1+2-argument form like that.
            – LegionMammal978
            Dec 7 '18 at 22:46



















          3















          J, 5 bytes



          a:,<


          Try it online!






          share|improve this answer





























            3















            PowerShell, 65 bytes





            param($a)'';$x=,0*($y=$a.count);0..--$y|%{$x[$_]=@($a[0..$_])};$x


            Try it online!



            PowerShell helpfully unrolls lists-of-lists when the default Write-Output happens at program completion, so you get one item per line. Tack on a -join',' to see the list-of-lists better, by converting the inner lists into strings.



            (Ab)uses the fact that attempting to output an empty array (e.g., @()) results in no output, so an empty array input just has '' as the output, since the $a[0..$_] will result in nothing. It will also throw out some spectacular error messages.






            share|improve this answer























            • Wrapping it in parens instead of assigning it saves 20 bytes. Unless you don't think that counts as returning a list of lists. I've always been fuzzy on that distinction.
              – Veskah
              Dec 8 '18 at 2:59












            • @veskah Yeah, that's almost what I had before my edit to this version. The problem with your solution or my earlier solution -- it doesn't return a list-of-lists. TIO1 vs TIO2
              – AdmBorkBork
              Dec 10 '18 at 13:44



















            3















            K (ngn/k), 8 bytes



            ,(,!0),


            Try it online!






            share|improve this answer

















            • 1




              This is some kind of voodoo. ,(,()), in K4. Joining enlisted null along enlisted input? howsitwork?
              – streetster
              Dec 7 '18 at 20:46






            • 1




              @streetster () is an empty list. (,()),x prepends it to x. finally , does a concat-scan. the x is omitted to form a composition. note that the trailing , is dyadic, so it's "concat", not "enlist".
              – ngn
              Dec 7 '18 at 21:07








            • 1




              @streetster in k4 it can be a byte shorter: 1_',, but my parser isn't smart enough to handle this...
              – ngn
              Dec 7 '18 at 21:13





















            3















            Common Lisp, 39 bytes





            (defun f(l)`(,@(if l(f(butlast l))),l))


            Try it online!



            Explanation



            (defun f(l)                           )  ; Define a function f
            `( ) ; With the list (essentially capable of interpolation), containing:
            ,@ ; The value of, flattened to one level
            (if l ) ; If l is not the empty list (which is the representation of nil, i.e. the only falsy value)
            (f(butlast l)) ; Recurse with all of l but the tail
            ,l ; The value of l





            share|improve this answer





























              3














              F#, 53 bytes



              I've actually got two pretty similar answers for this, both the same length. They both take a generic sequence s as a parameter.



              First solution:



              let i s=Seq.init(Seq.length s+1)(fun n->Seq.take n s)


              Try it online!



              Seq.take takes the first n elements of the sequence. Seq.init creates a new sequence with a count (in this case) of the length of sequence s plus 1, and for each element in the sequence takes the first n elements in s.



              Second solution:



              let i s=Seq.map(fun n->Seq.take n s){0..Seq.length s}


              Similar to before, except it creates a sequence from 0 to the length of s. Then takes that number of elements from s.



              Try this online too!






              share|improve this answer























              • fun s->Seq.map(fun n->Seq.take n s){0..Seq.length s} saves 1 byte
                – Embodiment of Ignorance
                Dec 9 '18 at 6:41





















              3















              Husk, 2 bytes



              Θḣ


              Gets all the eads and then prepends Θ (in this case ):



              Try it online!



              (needs type annotation for empty list: Try it online!)






              share|improve this answer





























                3














                MATL, 15 12 bytes



                3 bytes saved thanks to @Giuseppe



                vin:"G@:)]Xh


                Try it at MATL Online.



                Due to the way that MATL displays the output, you can't explicitly see the empty array in the cell array. Here is a version that shows the output a little more explicitly.



                Explanation



                v       # Vertically concatenate the (empty) stack to create the array 
                i # Explicitly grab the input
                n # Compute the number of elements in the input (N)
                : # Create an array from [1, ..., N]
                " # Loop through this array
                G # For each of these numbers, M
                @: # Create an array from [1, ..., M]
                ) # Use this to index into the initial array
                ] # End of the for loop
                Xh # Concatenate the entire stack into a cell array





                share|improve this answer























                • use v instead of . And doesn't : use 1 as the default first argument? So this could be vin:"G@:)]Xh for 12 bytes.
                  – Giuseppe
                  Dec 10 '18 at 18:34










                • @Giuseppe Thanks! My MATL is a little rusty it seems :(
                  – Suever
                  Dec 10 '18 at 22:04



















                3















                SWI PROLOG 22 bytes



                i(X,Y):-append(X,_,Y).






                share|improve this answer





























                  2















                  Charcoal, 6 bytes



                  Eθ…θκθ


                  Try it online! Link is to verbose version of code. Explanation:



                   θ      Input array
                  E Map over elements
                  θ Input array
                  … Moulded to length
                  κ Current loop index
                  Implicitly print each array double-spaced
                  θ Input array
                  Implicitly print


                  It's possible at a cost of 1 byte to ask Charcoal to print an n+1-element array which includes the input as its last element, but the output is the same, although the cursor position would be different if you then went on to print something else.






                  share|improve this answer





























                    2















                    Groovy, 37 bytes



                    {x->(0..x.size()).collect{x[0..<it]}}


                    Try it online!






                    share|improve this answer





















                    • {it.inits().reverse()} will work once we get groovy 2.5 on TIO
                      – ASCII-only
                      yesterday



















                    2















                    Japt, 5 bytes



                    Êò@¯Y


                    Try it online!






                    share|improve this answer





























                      2















                      brainfuck, 43 bytes



                      Take a list of non-null characters as input and returns all prefixes separated by newline. Requires double-infinite or wrapping tape.



                      ,>-[+>,]<[-<]<<++++++++++[[<]>[.>]>[-<+>]<]


                      Try it online!






                      share|improve this answer























                      • Another answer outgolfed me by more than a half, because I didn't think about printing output while reading. Of course that method won't work with printing increasing suffixes.
                        – user202729
                        Dec 8 '18 at 9:58










                      • 40 bytes with some rearranging
                        – Jo King
                        Dec 8 '18 at 10:19



















                      2















                      C# (Visual C# Interactive Compiler), 39 bytes





                      x=>x.Select((_,i)=>x.Take(i)).Append(x)


                      Try it online!






                      share|improve this answer





















                      • You need to include the using System.Linq; in your bytecount. And it seems some of your output logic is in your outputting of the arrays. Because empty array just returns empty array.
                        – LiefdeWen
                        Dec 11 '18 at 9:51










                      • @LiefdeWen - my understanding is that since this interpreter includes a reference to System.Linq, I don't have to include this in the byte count. My submission would be considered a different language than say .NET Core. github.com/dotnet/roslyn/wiki/C%23-Interactive-Walkthrough - You mention printing which is a separate issue, I'd like to get clarity on this first.
                        – dana
                        Dec 11 '18 at 10:35










                      • With regards to printing, here is a version that basically dumps the result to the console - tio.run/##XY29CsIwGEX3PEXGBGKhtVt/… - not as pretty for sure! The question I have is when is it acceptable to use Array vs IList vs IEnumerable.
                        – dana
                        Dec 11 '18 at 10:59



















                      2















                      C (gcc), 102 bytes





                      Pretty long, as C quite obviously isn't well-suited to manipulating lists of lists.



                      Takes in a pointer to the first element of the input array, the length of the array, and a pointer to the variable in which the pointer to output will be stored. Produces a list of lists such that the first integer in the linear array stores the number of sub-lists. Sub-lists start with the number of elements, and are stored in memory in a contiguous manner.



                      p(r,e,f,i,x)int*e,**r,*x;{x=*r=malloc(++f*-~f+2<<1);*x++=f;for(i=0;i<f;x+=++i)*x=i,memcpy(x+1,e,4*i);}


                      Try it online!



                      Degolf



                      p(r,e,f,i,x) int*e,**r,*x; { // Declare function p. e is the input array, 
                      // r is a pointer to the variable that will store output,
                      // and x is a local iterator for r.
                      x=*r=malloc(++f*-~f+2<<1);// Allocate 2*(n+1)*(n+2)+4 bytes of memory,
                      // and store pointers in r and x.
                      *x++=f; // Store the number of arrays in the first variable (n+1)
                      for(i=0;i<f;x+=++i) // Iterate from 0 to f; x is incremented by i+1 every loop.
                      *x=i, // Store the length of the current sub-list.
                      memcpy(x+1,e,4*i); // Copy the data.
                      }





                      share|improve this answer





















                      • 97 bytes
                        – ceilingcat
                        18 hours ago










                      • @ceilingcat Thanks, will edit it in later when I get back onto a PC.
                        – Rogem
                        5 hours ago



















                      2















                      F# (Mono), 45 bytes





                      fun x->List.mapi(fun i y->List.take i x)x@[x]


                      Try it online!



                      I am not totally sure if this is valid, but it seems like it follows the same "anonymous lambda" syntax that I've seem used in several other languages.






                      share|improve this answer































                        2















                        Java 8+, 86 77 bytes



                        -9 bytes thanks to Kevin Cruijssen (getting rid of the import)!





                        x->java.util.stream.IntStream.range(0,x.size()+1).mapToObj(t->x.subList(0,t))


                        Try it online!



                        Alternative, 65 bytes



                        The following will print the results to stdout (due to Olivier Grégoire):



                        x->{for(int i=0;i<=x.size();)System.out.print(x.subList(0,i++));}


                        Try it online






                        share|improve this answer























                        • You can golf it to 77 bytes by just using java.util.stream.IntStream directly and drop the import.
                          – Kevin Cruijssen
                          Dec 10 '18 at 7:44










                        • @KevinCruijssen: Oh thanks! I didn't even know that this was possible, that's certainly helpful (at least for golfing purposes).
                          – BMO
                          Dec 10 '18 at 14:19










                        • x->{for(int i=0;i<=x.size();)System.out.println(x.subList(0,i++));} (67 bytes). This prints instead of using streams. Printing is usually the shortest way to output complex structures.
                          – Olivier Grégoire
                          Dec 10 '18 at 17:01












                        • @OlivierGrégoire: In that case you can probably get away with System.out.print since the output is still unambiguous.
                          – BMO
                          Dec 10 '18 at 17:55










                        • @BMO Indeed, that would be possible!
                          – Olivier Grégoire
                          Dec 10 '18 at 23:28



















                        2















                        Ruby, 31 29 bytes





                        ->a{[a*i=0]+a.map{a[0,i+=1]}}


                        Try it online!



                        Explanation:



                        ->a{             # take array input a
                        [a*i=0]+ # set i to 0 and add whatever comes next to [] (a*0 == )
                        a.map{ # for every element in a (basically do a.length times)
                        a[0,i+=1] # increment i and return the first i-1 elements of a to map
                        }
                        }





                        share|improve this answer































                          1















                          05AB1E, 3 bytes



                          η¯š


                          Explanation:



                          η    Prefixes
                          š Prepend
                          ¯ Global array (empty by default)


                          Try it online!






                          share|improve this answer





























                            1















                            RAD, 7 bytes



                            (⊂⍬),,


                            Try it online!



                            This also works in Dyalog APL as a function.



                            How?



                            This works the same for both APL and RAD, given their close relation.





                            • (⊂⍬) the empty array


                            • , prepended to


                            • , the prefixes (which exclude the empty array.)






                            share|improve this answer



























                              1 2
                              3
                              next



                              Your Answer





                              StackExchange.ifUsing("editor", function () {
                              return StackExchange.using("mathjaxEditing", function () {
                              StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
                              StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
                              });
                              });
                              }, "mathjax-editing");

                              StackExchange.ifUsing("editor", function () {
                              StackExchange.using("externalEditor", function () {
                              StackExchange.using("snippets", function () {
                              StackExchange.snippets.init();
                              });
                              });
                              }, "code-snippets");

                              StackExchange.ready(function() {
                              var channelOptions = {
                              tags: "".split(" "),
                              id: "200"
                              };
                              initTagRenderer("".split(" "), "".split(" "), channelOptions);

                              StackExchange.using("externalEditor", function() {
                              // Have to fire editor after snippets, if snippets enabled
                              if (StackExchange.settings.snippets.snippetsEnabled) {
                              StackExchange.using("snippets", function() {
                              createEditor();
                              });
                              }
                              else {
                              createEditor();
                              }
                              });

                              function createEditor() {
                              StackExchange.prepareEditor({
                              heartbeatType: 'answer',
                              autoActivateHeartbeat: false,
                              convertImagesToLinks: false,
                              noModals: true,
                              showLowRepImageUploadWarning: true,
                              reputationToPostImages: null,
                              bindNavPrevention: true,
                              postfix: "",
                              imageUploader: {
                              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                              allowUrls: true
                              },
                              onDemand: true,
                              discardSelector: ".discard-answer"
                              ,immediatelyShowMarkdownHelp:true
                              });


                              }
                              });














                              draft saved

                              draft discarded


















                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f177146%2fp-pr-pre-pref-prefi-prefix-prefixe-prefixes%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown

























                              63 Answers
                              63






                              active

                              oldest

                              votes








                              63 Answers
                              63






                              active

                              oldest

                              votes









                              active

                              oldest

                              votes






                              active

                              oldest

                              votes








                              1 2
                              3
                              next










                              15















                              Haskell, 20 bytes



                              Edit: Yet a byte shorter with a completely different scan.



                              An anonymous function slightly beating the trivial import.





                              scanr(_->init)=<<id


                              Try it online!




                              • Uses =<< for the abbreviation (scanr(_->init)=<<id) l = scanr(_->init) l l.

                              • Scans a list l from right to left, collecting intermediate results with the function _->init.

                              • That function ignores the elements scanned through (they're only used to get the right total length for the collected results), so really iterates applying init to the initial value of the scan, which is also l.






                              share|improve this answer




























                                15















                                Haskell, 20 bytes



                                Edit: Yet a byte shorter with a completely different scan.



                                An anonymous function slightly beating the trivial import.





                                scanr(_->init)=<<id


                                Try it online!




                                • Uses =<< for the abbreviation (scanr(_->init)=<<id) l = scanr(_->init) l l.

                                • Scans a list l from right to left, collecting intermediate results with the function _->init.

                                • That function ignores the elements scanned through (they're only used to get the right total length for the collected results), so really iterates applying init to the initial value of the scan, which is also l.






                                share|improve this answer


























                                  15












                                  15








                                  15







                                  Haskell, 20 bytes



                                  Edit: Yet a byte shorter with a completely different scan.



                                  An anonymous function slightly beating the trivial import.





                                  scanr(_->init)=<<id


                                  Try it online!




                                  • Uses =<< for the abbreviation (scanr(_->init)=<<id) l = scanr(_->init) l l.

                                  • Scans a list l from right to left, collecting intermediate results with the function _->init.

                                  • That function ignores the elements scanned through (they're only used to get the right total length for the collected results), so really iterates applying init to the initial value of the scan, which is also l.






                                  share|improve this answer















                                  Haskell, 20 bytes



                                  Edit: Yet a byte shorter with a completely different scan.



                                  An anonymous function slightly beating the trivial import.





                                  scanr(_->init)=<<id


                                  Try it online!




                                  • Uses =<< for the abbreviation (scanr(_->init)=<<id) l = scanr(_->init) l l.

                                  • Scans a list l from right to left, collecting intermediate results with the function _->init.

                                  • That function ignores the elements scanned through (they're only used to get the right total length for the collected results), so really iterates applying init to the initial value of the scan, which is also l.







                                  share|improve this answer














                                  share|improve this answer



                                  share|improve this answer








                                  edited Dec 7 '18 at 20:05

























                                  answered Dec 7 '18 at 19:43









                                  Ørjan Johansen

                                  6,44411131




                                  6,44411131























                                      13















                                      brainfuck, 21 12 bytes



                                      -9 bytes thanks to Arnauld suggesting the separator ÿ instead of newlines



                                      -[[<]>[.>],]


                                      Try it online!



                                      Takes bytes through STDIN with no null bytes and prints a series of prefixes separated by the ÿ character with a leading ÿ character. For example, for the input Prefixes, the output is ÿÿPÿPrÿPreÿPrefÿPrefiÿPrefixÿPrefixeÿPrefixes.



                                      For readability, here's a version with newlines instead.



                                      Explanation:



                                      -              Create a ÿ character in cell 0
                                      [ ,] While input, starting with the ÿ
                                      [<]> Go to the start of the string
                                      [.>] Print the string
                                      , Append the input to the end of the string





                                      share|improve this answer



















                                      • 1




                                        This only works on BF implementations with 8-bit, unsigned, wrapping cells.
                                        – Dev
                                        Dec 10 '18 at 3:11
















                                      13















                                      brainfuck, 21 12 bytes



                                      -9 bytes thanks to Arnauld suggesting the separator ÿ instead of newlines



                                      -[[<]>[.>],]


                                      Try it online!



                                      Takes bytes through STDIN with no null bytes and prints a series of prefixes separated by the ÿ character with a leading ÿ character. For example, for the input Prefixes, the output is ÿÿPÿPrÿPreÿPrefÿPrefiÿPrefixÿPrefixeÿPrefixes.



                                      For readability, here's a version with newlines instead.



                                      Explanation:



                                      -              Create a ÿ character in cell 0
                                      [ ,] While input, starting with the ÿ
                                      [<]> Go to the start of the string
                                      [.>] Print the string
                                      , Append the input to the end of the string





                                      share|improve this answer



















                                      • 1




                                        This only works on BF implementations with 8-bit, unsigned, wrapping cells.
                                        – Dev
                                        Dec 10 '18 at 3:11














                                      13












                                      13








                                      13







                                      brainfuck, 21 12 bytes



                                      -9 bytes thanks to Arnauld suggesting the separator ÿ instead of newlines



                                      -[[<]>[.>],]


                                      Try it online!



                                      Takes bytes through STDIN with no null bytes and prints a series of prefixes separated by the ÿ character with a leading ÿ character. For example, for the input Prefixes, the output is ÿÿPÿPrÿPreÿPrefÿPrefiÿPrefixÿPrefixeÿPrefixes.



                                      For readability, here's a version with newlines instead.



                                      Explanation:



                                      -              Create a ÿ character in cell 0
                                      [ ,] While input, starting with the ÿ
                                      [<]> Go to the start of the string
                                      [.>] Print the string
                                      , Append the input to the end of the string





                                      share|improve this answer















                                      brainfuck, 21 12 bytes



                                      -9 bytes thanks to Arnauld suggesting the separator ÿ instead of newlines



                                      -[[<]>[.>],]


                                      Try it online!



                                      Takes bytes through STDIN with no null bytes and prints a series of prefixes separated by the ÿ character with a leading ÿ character. For example, for the input Prefixes, the output is ÿÿPÿPrÿPreÿPrefÿPrefiÿPrefixÿPrefixeÿPrefixes.



                                      For readability, here's a version with newlines instead.



                                      Explanation:



                                      -              Create a ÿ character in cell 0
                                      [ ,] While input, starting with the ÿ
                                      [<]> Go to the start of the string
                                      [.>] Print the string
                                      , Append the input to the end of the string






                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Dec 9 '18 at 22:28

























                                      answered Dec 8 '18 at 8:56









                                      Jo King

                                      20.8k247109




                                      20.8k247109








                                      • 1




                                        This only works on BF implementations with 8-bit, unsigned, wrapping cells.
                                        – Dev
                                        Dec 10 '18 at 3:11














                                      • 1




                                        This only works on BF implementations with 8-bit, unsigned, wrapping cells.
                                        – Dev
                                        Dec 10 '18 at 3:11








                                      1




                                      1




                                      This only works on BF implementations with 8-bit, unsigned, wrapping cells.
                                      – Dev
                                      Dec 10 '18 at 3:11




                                      This only works on BF implementations with 8-bit, unsigned, wrapping cells.
                                      – Dev
                                      Dec 10 '18 at 3:11











                                      10














                                      JavaScript (ES6), 33 bytes



                                      a=>[b=,...a.map(n=>b=[...b,n])]


                                      Try it online!



                                      How?



                                      +--- a = input array
                                      |
                                      | +--- initialize b to an empty array and include it as the first entry
                                      | | of the output (whatever the input is)
                                      | |
                                      | | +--- for each value n in a:
                                      | | |
                                      | | | +--- append n to b and include this new array in
                                      | | | | the final output
                                      | | | |
                                      a => [b = , ...a.map(n => b = [...b, n])]
                                      | |
                                      +---------+--------+
                                      |
                                      spread syntax: expands all elements of
                                      the child array within the parent array





                                      share|improve this answer























                                      • wow, that's a whole new level of code explanation, awesome job :O
                                        – Brian H.
                                        Dec 10 '18 at 12:54










                                      • @BrianH. Thank you! Simple tasks are good opportunities to write detailed explanations that can't be brought up in denser code.
                                        – Arnauld
                                        Dec 10 '18 at 13:05










                                      • Did you make it by hand? or did you get help from any weird software i've never heard about?
                                        – Brian H.
                                        Dec 10 '18 at 13:08






                                      • 2




                                        Just Notepad++ with some column mode editing.
                                        – Arnauld
                                        Dec 10 '18 at 13:30
















                                      10














                                      JavaScript (ES6), 33 bytes



                                      a=>[b=,...a.map(n=>b=[...b,n])]


                                      Try it online!



                                      How?



                                      +--- a = input array
                                      |
                                      | +--- initialize b to an empty array and include it as the first entry
                                      | | of the output (whatever the input is)
                                      | |
                                      | | +--- for each value n in a:
                                      | | |
                                      | | | +--- append n to b and include this new array in
                                      | | | | the final output
                                      | | | |
                                      a => [b = , ...a.map(n => b = [...b, n])]
                                      | |
                                      +---------+--------+
                                      |
                                      spread syntax: expands all elements of
                                      the child array within the parent array





                                      share|improve this answer























                                      • wow, that's a whole new level of code explanation, awesome job :O
                                        – Brian H.
                                        Dec 10 '18 at 12:54










                                      • @BrianH. Thank you! Simple tasks are good opportunities to write detailed explanations that can't be brought up in denser code.
                                        – Arnauld
                                        Dec 10 '18 at 13:05










                                      • Did you make it by hand? or did you get help from any weird software i've never heard about?
                                        – Brian H.
                                        Dec 10 '18 at 13:08






                                      • 2




                                        Just Notepad++ with some column mode editing.
                                        – Arnauld
                                        Dec 10 '18 at 13:30














                                      10












                                      10








                                      10






                                      JavaScript (ES6), 33 bytes



                                      a=>[b=,...a.map(n=>b=[...b,n])]


                                      Try it online!



                                      How?



                                      +--- a = input array
                                      |
                                      | +--- initialize b to an empty array and include it as the first entry
                                      | | of the output (whatever the input is)
                                      | |
                                      | | +--- for each value n in a:
                                      | | |
                                      | | | +--- append n to b and include this new array in
                                      | | | | the final output
                                      | | | |
                                      a => [b = , ...a.map(n => b = [...b, n])]
                                      | |
                                      +---------+--------+
                                      |
                                      spread syntax: expands all elements of
                                      the child array within the parent array





                                      share|improve this answer














                                      JavaScript (ES6), 33 bytes



                                      a=>[b=,...a.map(n=>b=[...b,n])]


                                      Try it online!



                                      How?



                                      +--- a = input array
                                      |
                                      | +--- initialize b to an empty array and include it as the first entry
                                      | | of the output (whatever the input is)
                                      | |
                                      | | +--- for each value n in a:
                                      | | |
                                      | | | +--- append n to b and include this new array in
                                      | | | | the final output
                                      | | | |
                                      a => [b = , ...a.map(n => b = [...b, n])]
                                      | |
                                      +---------+--------+
                                      |
                                      spread syntax: expands all elements of
                                      the child array within the parent array






                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Dec 8 '18 at 8:15

























                                      answered Dec 7 '18 at 19:22









                                      Arnauld

                                      72.4k689305




                                      72.4k689305












                                      • wow, that's a whole new level of code explanation, awesome job :O
                                        – Brian H.
                                        Dec 10 '18 at 12:54










                                      • @BrianH. Thank you! Simple tasks are good opportunities to write detailed explanations that can't be brought up in denser code.
                                        – Arnauld
                                        Dec 10 '18 at 13:05










                                      • Did you make it by hand? or did you get help from any weird software i've never heard about?
                                        – Brian H.
                                        Dec 10 '18 at 13:08






                                      • 2




                                        Just Notepad++ with some column mode editing.
                                        – Arnauld
                                        Dec 10 '18 at 13:30


















                                      • wow, that's a whole new level of code explanation, awesome job :O
                                        – Brian H.
                                        Dec 10 '18 at 12:54










                                      • @BrianH. Thank you! Simple tasks are good opportunities to write detailed explanations that can't be brought up in denser code.
                                        – Arnauld
                                        Dec 10 '18 at 13:05










                                      • Did you make it by hand? or did you get help from any weird software i've never heard about?
                                        – Brian H.
                                        Dec 10 '18 at 13:08






                                      • 2




                                        Just Notepad++ with some column mode editing.
                                        – Arnauld
                                        Dec 10 '18 at 13:30
















                                      wow, that's a whole new level of code explanation, awesome job :O
                                      – Brian H.
                                      Dec 10 '18 at 12:54




                                      wow, that's a whole new level of code explanation, awesome job :O
                                      – Brian H.
                                      Dec 10 '18 at 12:54












                                      @BrianH. Thank you! Simple tasks are good opportunities to write detailed explanations that can't be brought up in denser code.
                                      – Arnauld
                                      Dec 10 '18 at 13:05




                                      @BrianH. Thank you! Simple tasks are good opportunities to write detailed explanations that can't be brought up in denser code.
                                      – Arnauld
                                      Dec 10 '18 at 13:05












                                      Did you make it by hand? or did you get help from any weird software i've never heard about?
                                      – Brian H.
                                      Dec 10 '18 at 13:08




                                      Did you make it by hand? or did you get help from any weird software i've never heard about?
                                      – Brian H.
                                      Dec 10 '18 at 13:08




                                      2




                                      2




                                      Just Notepad++ with some column mode editing.
                                      – Arnauld
                                      Dec 10 '18 at 13:30




                                      Just Notepad++ with some column mode editing.
                                      – Arnauld
                                      Dec 10 '18 at 13:30











                                      7














                                      CW for all trivial entries




                                      Clean, 19 bytes



                                      Haskell version works in Clean too.



                                      import StdLib
                                      inits


                                      Try it online!




                                      Haskell, 22 bytes





                                      import Data.List
                                      inits


                                      Try it online!




                                      Prolog (SWI), 6 bytes



                                      prefix


                                      Try it online!






                                      share|improve this answer























                                      • So torn - to upvote or not. On the one hand, I appreciate all the built-in solutions in one place. On the other, I really dislike builtins because they're so basic...
                                        – Rogem
                                        5 hours ago
















                                      7














                                      CW for all trivial entries




                                      Clean, 19 bytes



                                      Haskell version works in Clean too.



                                      import StdLib
                                      inits


                                      Try it online!




                                      Haskell, 22 bytes





                                      import Data.List
                                      inits


                                      Try it online!




                                      Prolog (SWI), 6 bytes



                                      prefix


                                      Try it online!






                                      share|improve this answer























                                      • So torn - to upvote or not. On the one hand, I appreciate all the built-in solutions in one place. On the other, I really dislike builtins because they're so basic...
                                        – Rogem
                                        5 hours ago














                                      7












                                      7








                                      7






                                      CW for all trivial entries




                                      Clean, 19 bytes



                                      Haskell version works in Clean too.



                                      import StdLib
                                      inits


                                      Try it online!




                                      Haskell, 22 bytes





                                      import Data.List
                                      inits


                                      Try it online!




                                      Prolog (SWI), 6 bytes



                                      prefix


                                      Try it online!






                                      share|improve this answer














                                      CW for all trivial entries




                                      Clean, 19 bytes



                                      Haskell version works in Clean too.



                                      import StdLib
                                      inits


                                      Try it online!




                                      Haskell, 22 bytes





                                      import Data.List
                                      inits


                                      Try it online!




                                      Prolog (SWI), 6 bytes



                                      prefix


                                      Try it online!







                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited yesterday


























                                      community wiki





                                      8 revs, 5 users 28%
                                      ASCII-only













                                      • So torn - to upvote or not. On the one hand, I appreciate all the built-in solutions in one place. On the other, I really dislike builtins because they're so basic...
                                        – Rogem
                                        5 hours ago


















                                      • So torn - to upvote or not. On the one hand, I appreciate all the built-in solutions in one place. On the other, I really dislike builtins because they're so basic...
                                        – Rogem
                                        5 hours ago
















                                      So torn - to upvote or not. On the one hand, I appreciate all the built-in solutions in one place. On the other, I really dislike builtins because they're so basic...
                                      – Rogem
                                      5 hours ago




                                      So torn - to upvote or not. On the one hand, I appreciate all the built-in solutions in one place. On the other, I really dislike builtins because they're so basic...
                                      – Rogem
                                      5 hours ago











                                      6















                                      Jelly, 3 bytes



                                      ṭṖƤ


                                      Try it online!



                                      How it works



                                      ṭṖƤ  Main link. Argument: A

                                      Ƥ Map the link to the left over all non-empty(!) prefixes of A.
                                      Ṗ Pop; remove the last element.
                                      ṭ Tack; append A to the resulting list.





                                      share|improve this answer


























                                        6















                                        Jelly, 3 bytes



                                        ṭṖƤ


                                        Try it online!



                                        How it works



                                        ṭṖƤ  Main link. Argument: A

                                        Ƥ Map the link to the left over all non-empty(!) prefixes of A.
                                        Ṗ Pop; remove the last element.
                                        ṭ Tack; append A to the resulting list.





                                        share|improve this answer
























                                          6












                                          6








                                          6







                                          Jelly, 3 bytes



                                          ṭṖƤ


                                          Try it online!



                                          How it works



                                          ṭṖƤ  Main link. Argument: A

                                          Ƥ Map the link to the left over all non-empty(!) prefixes of A.
                                          Ṗ Pop; remove the last element.
                                          ṭ Tack; append A to the resulting list.





                                          share|improve this answer













                                          Jelly, 3 bytes



                                          ṭṖƤ


                                          Try it online!



                                          How it works



                                          ṭṖƤ  Main link. Argument: A

                                          Ƥ Map the link to the left over all non-empty(!) prefixes of A.
                                          Ṗ Pop; remove the last element.
                                          ṭ Tack; append A to the resulting list.






                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Dec 7 '18 at 20:03









                                          Dennis

                                          186k32296735




                                          186k32296735























                                              6















                                              Japt, 4 bytes



                                              ²£¯Y


                                              Try it online!



                                              Explanation:



                                              ²       :Add an arbitrary extra item to the end of the array
                                              £ :For each item in the new array:
                                              ¯Y : Get an array of the items that are before it





                                              share|improve this answer




























                                                6















                                                Japt, 4 bytes



                                                ²£¯Y


                                                Try it online!



                                                Explanation:



                                                ²       :Add an arbitrary extra item to the end of the array
                                                £ :For each item in the new array:
                                                ¯Y : Get an array of the items that are before it





                                                share|improve this answer


























                                                  6












                                                  6








                                                  6







                                                  Japt, 4 bytes



                                                  ²£¯Y


                                                  Try it online!



                                                  Explanation:



                                                  ²       :Add an arbitrary extra item to the end of the array
                                                  £ :For each item in the new array:
                                                  ¯Y : Get an array of the items that are before it





                                                  share|improve this answer















                                                  Japt, 4 bytes



                                                  ²£¯Y


                                                  Try it online!



                                                  Explanation:



                                                  ²       :Add an arbitrary extra item to the end of the array
                                                  £ :For each item in the new array:
                                                  ¯Y : Get an array of the items that are before it






                                                  share|improve this answer














                                                  share|improve this answer



                                                  share|improve this answer








                                                  edited Dec 8 '18 at 9:31

























                                                  answered Dec 7 '18 at 20:05









                                                  Kamil Drakari

                                                  2,971416




                                                  2,971416























                                                      6















                                                      Perl 6, 13 bytes



                                                      {(),|[,] @_}


                                                      Try it online!



                                                      To explain:



                                                      In Perl 6 you can wrap an operator in square brackets as an alternate way to write a list reduction. [+] @array returns the sum of the elements in @array, [*] @array returns the product, etc. You can also precede the operator with a backslash to make a "triangular" reduction, which some languages call "scan." So [+] @array returns a list consisting of the first element of @array, then the sum of the first two elements, then the sum of the first three elements, etc.



                                                      Here [,] @_ is a triangular reduction over the input array @_ using the list construction operator ,. So it evaluates to a lists of lists: the first element of @_, the first two elements of @_, etc. That's almost what's needed, but the problem calls for a single empty list first. So the first element of the return list is a literal empty list (),, then the reduction over the input list is flattened into the rest of the return list with |.






                                                      share|improve this answer



















                                                      • 2




                                                        O_o what is even happening here
                                                        – ASCII-only
                                                        Dec 8 '18 at 4:12






                                                      • 1




                                                        @ASCII-only triangular reduction
                                                        – user202729
                                                        Dec 8 '18 at 4:33
















                                                      6















                                                      Perl 6, 13 bytes



                                                      {(),|[,] @_}


                                                      Try it online!



                                                      To explain:



                                                      In Perl 6 you can wrap an operator in square brackets as an alternate way to write a list reduction. [+] @array returns the sum of the elements in @array, [*] @array returns the product, etc. You can also precede the operator with a backslash to make a "triangular" reduction, which some languages call "scan." So [+] @array returns a list consisting of the first element of @array, then the sum of the first two elements, then the sum of the first three elements, etc.



                                                      Here [,] @_ is a triangular reduction over the input array @_ using the list construction operator ,. So it evaluates to a lists of lists: the first element of @_, the first two elements of @_, etc. That's almost what's needed, but the problem calls for a single empty list first. So the first element of the return list is a literal empty list (),, then the reduction over the input list is flattened into the rest of the return list with |.






                                                      share|improve this answer



















                                                      • 2




                                                        O_o what is even happening here
                                                        – ASCII-only
                                                        Dec 8 '18 at 4:12






                                                      • 1




                                                        @ASCII-only triangular reduction
                                                        – user202729
                                                        Dec 8 '18 at 4:33














                                                      6












                                                      6








                                                      6







                                                      Perl 6, 13 bytes



                                                      {(),|[,] @_}


                                                      Try it online!



                                                      To explain:



                                                      In Perl 6 you can wrap an operator in square brackets as an alternate way to write a list reduction. [+] @array returns the sum of the elements in @array, [*] @array returns the product, etc. You can also precede the operator with a backslash to make a "triangular" reduction, which some languages call "scan." So [+] @array returns a list consisting of the first element of @array, then the sum of the first two elements, then the sum of the first three elements, etc.



                                                      Here [,] @_ is a triangular reduction over the input array @_ using the list construction operator ,. So it evaluates to a lists of lists: the first element of @_, the first two elements of @_, etc. That's almost what's needed, but the problem calls for a single empty list first. So the first element of the return list is a literal empty list (),, then the reduction over the input list is flattened into the rest of the return list with |.






                                                      share|improve this answer















                                                      Perl 6, 13 bytes



                                                      {(),|[,] @_}


                                                      Try it online!



                                                      To explain:



                                                      In Perl 6 you can wrap an operator in square brackets as an alternate way to write a list reduction. [+] @array returns the sum of the elements in @array, [*] @array returns the product, etc. You can also precede the operator with a backslash to make a "triangular" reduction, which some languages call "scan." So [+] @array returns a list consisting of the first element of @array, then the sum of the first two elements, then the sum of the first three elements, etc.



                                                      Here [,] @_ is a triangular reduction over the input array @_ using the list construction operator ,. So it evaluates to a lists of lists: the first element of @_, the first two elements of @_, etc. That's almost what's needed, but the problem calls for a single empty list first. So the first element of the return list is a literal empty list (),, then the reduction over the input list is flattened into the rest of the return list with |.







                                                      share|improve this answer














                                                      share|improve this answer



                                                      share|improve this answer








                                                      edited Dec 11 '18 at 18:21

























                                                      answered Dec 7 '18 at 22:53









                                                      Sean

                                                      3,44637




                                                      3,44637








                                                      • 2




                                                        O_o what is even happening here
                                                        – ASCII-only
                                                        Dec 8 '18 at 4:12






                                                      • 1




                                                        @ASCII-only triangular reduction
                                                        – user202729
                                                        Dec 8 '18 at 4:33














                                                      • 2




                                                        O_o what is even happening here
                                                        – ASCII-only
                                                        Dec 8 '18 at 4:12






                                                      • 1




                                                        @ASCII-only triangular reduction
                                                        – user202729
                                                        Dec 8 '18 at 4:33








                                                      2




                                                      2




                                                      O_o what is even happening here
                                                      – ASCII-only
                                                      Dec 8 '18 at 4:12




                                                      O_o what is even happening here
                                                      – ASCII-only
                                                      Dec 8 '18 at 4:12




                                                      1




                                                      1




                                                      @ASCII-only triangular reduction
                                                      – user202729
                                                      Dec 8 '18 at 4:33




                                                      @ASCII-only triangular reduction
                                                      – user202729
                                                      Dec 8 '18 at 4:33











                                                      5















                                                      Python 2, 32 bytes





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


                                                      Try it online!






                                                      share|improve this answer

















                                                      • 1




                                                        Also works in Python 3
                                                        – ASCII-only
                                                        Dec 8 '18 at 4:14
















                                                      5















                                                      Python 2, 32 bytes





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


                                                      Try it online!






                                                      share|improve this answer

















                                                      • 1




                                                        Also works in Python 3
                                                        – ASCII-only
                                                        Dec 8 '18 at 4:14














                                                      5












                                                      5








                                                      5







                                                      Python 2, 32 bytes





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


                                                      Try it online!






                                                      share|improve this answer













                                                      Python 2, 32 bytes





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


                                                      Try it online!







                                                      share|improve this answer












                                                      share|improve this answer



                                                      share|improve this answer










                                                      answered Dec 7 '18 at 20:15









                                                      ovs

                                                      18.7k21059




                                                      18.7k21059








                                                      • 1




                                                        Also works in Python 3
                                                        – ASCII-only
                                                        Dec 8 '18 at 4:14














                                                      • 1




                                                        Also works in Python 3
                                                        – ASCII-only
                                                        Dec 8 '18 at 4:14








                                                      1




                                                      1




                                                      Also works in Python 3
                                                      – ASCII-only
                                                      Dec 8 '18 at 4:14




                                                      Also works in Python 3
                                                      – ASCII-only
                                                      Dec 8 '18 at 4:14











                                                      5















                                                      R, 40 39 bytes





                                                      function(L)lapply(0:length(L),head,x=L)


                                                      Try it online!



                                                      -1 byte thanks to digEmAll



                                                      The output of R's list type is a bit weird; it uses sequential indexing, so for instance, the output for



                                                      list(1,2) is



                                                      [[1]]                     # first list element
                                                      list()

                                                      [[2]] # second list element
                                                      [[2]][[1]] # first element of second list element
                                                      [1] 1


                                                      [[3]] # third list element
                                                      [[3]][[1]] # first element of third list element
                                                      [1] 1

                                                      [[3]][[2]] # etc.
                                                      [1] 2


                                                      Taking input as a vector instead gives a neater output format, although then the inputs are not technically lists.






                                                      share|improve this answer



















                                                      • 1




                                                        39 using lapply
                                                        – digEmAll
                                                        Dec 8 '18 at 12:46










                                                      • @digEmAll thanks!
                                                        – Giuseppe
                                                        Dec 10 '18 at 14:41
















                                                      5















                                                      R, 40 39 bytes





                                                      function(L)lapply(0:length(L),head,x=L)


                                                      Try it online!



                                                      -1 byte thanks to digEmAll



                                                      The output of R's list type is a bit weird; it uses sequential indexing, so for instance, the output for



                                                      list(1,2) is



                                                      [[1]]                     # first list element
                                                      list()

                                                      [[2]] # second list element
                                                      [[2]][[1]] # first element of second list element
                                                      [1] 1


                                                      [[3]] # third list element
                                                      [[3]][[1]] # first element of third list element
                                                      [1] 1

                                                      [[3]][[2]] # etc.
                                                      [1] 2


                                                      Taking input as a vector instead gives a neater output format, although then the inputs are not technically lists.






                                                      share|improve this answer



















                                                      • 1




                                                        39 using lapply
                                                        – digEmAll
                                                        Dec 8 '18 at 12:46










                                                      • @digEmAll thanks!
                                                        – Giuseppe
                                                        Dec 10 '18 at 14:41














                                                      5












                                                      5








                                                      5







                                                      R, 40 39 bytes





                                                      function(L)lapply(0:length(L),head,x=L)


                                                      Try it online!



                                                      -1 byte thanks to digEmAll



                                                      The output of R's list type is a bit weird; it uses sequential indexing, so for instance, the output for



                                                      list(1,2) is



                                                      [[1]]                     # first list element
                                                      list()

                                                      [[2]] # second list element
                                                      [[2]][[1]] # first element of second list element
                                                      [1] 1


                                                      [[3]] # third list element
                                                      [[3]][[1]] # first element of third list element
                                                      [1] 1

                                                      [[3]][[2]] # etc.
                                                      [1] 2


                                                      Taking input as a vector instead gives a neater output format, although then the inputs are not technically lists.






                                                      share|improve this answer















                                                      R, 40 39 bytes





                                                      function(L)lapply(0:length(L),head,x=L)


                                                      Try it online!



                                                      -1 byte thanks to digEmAll



                                                      The output of R's list type is a bit weird; it uses sequential indexing, so for instance, the output for



                                                      list(1,2) is



                                                      [[1]]                     # first list element
                                                      list()

                                                      [[2]] # second list element
                                                      [[2]][[1]] # first element of second list element
                                                      [1] 1


                                                      [[3]] # third list element
                                                      [[3]][[1]] # first element of third list element
                                                      [1] 1

                                                      [[3]][[2]] # etc.
                                                      [1] 2


                                                      Taking input as a vector instead gives a neater output format, although then the inputs are not technically lists.







                                                      share|improve this answer














                                                      share|improve this answer



                                                      share|improve this answer








                                                      edited Dec 10 '18 at 14:40

























                                                      answered Dec 7 '18 at 20:12









                                                      Giuseppe

                                                      16.6k31052




                                                      16.6k31052








                                                      • 1




                                                        39 using lapply
                                                        – digEmAll
                                                        Dec 8 '18 at 12:46










                                                      • @digEmAll thanks!
                                                        – Giuseppe
                                                        Dec 10 '18 at 14:41














                                                      • 1




                                                        39 using lapply
                                                        – digEmAll
                                                        Dec 8 '18 at 12:46










                                                      • @digEmAll thanks!
                                                        – Giuseppe
                                                        Dec 10 '18 at 14:41








                                                      1




                                                      1




                                                      39 using lapply
                                                      – digEmAll
                                                      Dec 8 '18 at 12:46




                                                      39 using lapply
                                                      – digEmAll
                                                      Dec 8 '18 at 12:46












                                                      @digEmAll thanks!
                                                      – Giuseppe
                                                      Dec 10 '18 at 14:41




                                                      @digEmAll thanks!
                                                      – Giuseppe
                                                      Dec 10 '18 at 14:41











                                                      4














                                                      JavaScript, 36 bytes





                                                      a=>[...a,0].map((x,y)=>a.slice(0,y))


                                                      Try it online!






                                                      share|improve this answer




























                                                        4














                                                        JavaScript, 36 bytes





                                                        a=>[...a,0].map((x,y)=>a.slice(0,y))


                                                        Try it online!






                                                        share|improve this answer


























                                                          4












                                                          4








                                                          4






                                                          JavaScript, 36 bytes





                                                          a=>[...a,0].map((x,y)=>a.slice(0,y))


                                                          Try it online!






                                                          share|improve this answer














                                                          JavaScript, 36 bytes





                                                          a=>[...a,0].map((x,y)=>a.slice(0,y))


                                                          Try it online!







                                                          share|improve this answer














                                                          share|improve this answer



                                                          share|improve this answer








                                                          edited Dec 7 '18 at 21:27

























                                                          answered Dec 7 '18 at 21:16









                                                          Oliver

                                                          4,7401831




                                                          4,7401831























                                                              4














                                                              Mathematica, 22 21 bytes



                                                              -1 byte thanks to Misha Lavrov!



                                                              {}~FoldList@Append~#&


                                                              Pure function. Takes a list as input and returns a list of lists as output. I believe this is the shortest possible solution.






                                                              share|improve this answer























                                                              • We can write the same solution more compactly as {}~FoldList@Append~#&.
                                                                – Misha Lavrov
                                                                Dec 7 '18 at 21:59










                                                              • @MishaLavrov Thanks! I didn't think to use the curried 1+2-argument form like that.
                                                                – LegionMammal978
                                                                Dec 7 '18 at 22:46
















                                                              4














                                                              Mathematica, 22 21 bytes



                                                              -1 byte thanks to Misha Lavrov!



                                                              {}~FoldList@Append~#&


                                                              Pure function. Takes a list as input and returns a list of lists as output. I believe this is the shortest possible solution.






                                                              share|improve this answer























                                                              • We can write the same solution more compactly as {}~FoldList@Append~#&.
                                                                – Misha Lavrov
                                                                Dec 7 '18 at 21:59










                                                              • @MishaLavrov Thanks! I didn't think to use the curried 1+2-argument form like that.
                                                                – LegionMammal978
                                                                Dec 7 '18 at 22:46














                                                              4












                                                              4








                                                              4






                                                              Mathematica, 22 21 bytes



                                                              -1 byte thanks to Misha Lavrov!



                                                              {}~FoldList@Append~#&


                                                              Pure function. Takes a list as input and returns a list of lists as output. I believe this is the shortest possible solution.






                                                              share|improve this answer














                                                              Mathematica, 22 21 bytes



                                                              -1 byte thanks to Misha Lavrov!



                                                              {}~FoldList@Append~#&


                                                              Pure function. Takes a list as input and returns a list of lists as output. I believe this is the shortest possible solution.







                                                              share|improve this answer














                                                              share|improve this answer



                                                              share|improve this answer








                                                              edited Dec 7 '18 at 22:47

























                                                              answered Dec 7 '18 at 21:33









                                                              LegionMammal978

                                                              15.1k41852




                                                              15.1k41852












                                                              • We can write the same solution more compactly as {}~FoldList@Append~#&.
                                                                – Misha Lavrov
                                                                Dec 7 '18 at 21:59










                                                              • @MishaLavrov Thanks! I didn't think to use the curried 1+2-argument form like that.
                                                                – LegionMammal978
                                                                Dec 7 '18 at 22:46


















                                                              • We can write the same solution more compactly as {}~FoldList@Append~#&.
                                                                – Misha Lavrov
                                                                Dec 7 '18 at 21:59










                                                              • @MishaLavrov Thanks! I didn't think to use the curried 1+2-argument form like that.
                                                                – LegionMammal978
                                                                Dec 7 '18 at 22:46
















                                                              We can write the same solution more compactly as {}~FoldList@Append~#&.
                                                              – Misha Lavrov
                                                              Dec 7 '18 at 21:59




                                                              We can write the same solution more compactly as {}~FoldList@Append~#&.
                                                              – Misha Lavrov
                                                              Dec 7 '18 at 21:59












                                                              @MishaLavrov Thanks! I didn't think to use the curried 1+2-argument form like that.
                                                              – LegionMammal978
                                                              Dec 7 '18 at 22:46




                                                              @MishaLavrov Thanks! I didn't think to use the curried 1+2-argument form like that.
                                                              – LegionMammal978
                                                              Dec 7 '18 at 22:46











                                                              3















                                                              J, 5 bytes



                                                              a:,<


                                                              Try it online!






                                                              share|improve this answer


























                                                                3















                                                                J, 5 bytes



                                                                a:,<


                                                                Try it online!






                                                                share|improve this answer
























                                                                  3












                                                                  3








                                                                  3







                                                                  J, 5 bytes



                                                                  a:,<


                                                                  Try it online!






                                                                  share|improve this answer













                                                                  J, 5 bytes



                                                                  a:,<


                                                                  Try it online!







                                                                  share|improve this answer












                                                                  share|improve this answer



                                                                  share|improve this answer










                                                                  answered Dec 7 '18 at 19:26









                                                                  FrownyFrog

                                                                  2,4471518




                                                                  2,4471518























                                                                      3















                                                                      PowerShell, 65 bytes





                                                                      param($a)'';$x=,0*($y=$a.count);0..--$y|%{$x[$_]=@($a[0..$_])};$x


                                                                      Try it online!



                                                                      PowerShell helpfully unrolls lists-of-lists when the default Write-Output happens at program completion, so you get one item per line. Tack on a -join',' to see the list-of-lists better, by converting the inner lists into strings.



                                                                      (Ab)uses the fact that attempting to output an empty array (e.g., @()) results in no output, so an empty array input just has '' as the output, since the $a[0..$_] will result in nothing. It will also throw out some spectacular error messages.






                                                                      share|improve this answer























                                                                      • Wrapping it in parens instead of assigning it saves 20 bytes. Unless you don't think that counts as returning a list of lists. I've always been fuzzy on that distinction.
                                                                        – Veskah
                                                                        Dec 8 '18 at 2:59












                                                                      • @veskah Yeah, that's almost what I had before my edit to this version. The problem with your solution or my earlier solution -- it doesn't return a list-of-lists. TIO1 vs TIO2
                                                                        – AdmBorkBork
                                                                        Dec 10 '18 at 13:44
















                                                                      3















                                                                      PowerShell, 65 bytes





                                                                      param($a)'';$x=,0*($y=$a.count);0..--$y|%{$x[$_]=@($a[0..$_])};$x


                                                                      Try it online!



                                                                      PowerShell helpfully unrolls lists-of-lists when the default Write-Output happens at program completion, so you get one item per line. Tack on a -join',' to see the list-of-lists better, by converting the inner lists into strings.



                                                                      (Ab)uses the fact that attempting to output an empty array (e.g., @()) results in no output, so an empty array input just has '' as the output, since the $a[0..$_] will result in nothing. It will also throw out some spectacular error messages.






                                                                      share|improve this answer























                                                                      • Wrapping it in parens instead of assigning it saves 20 bytes. Unless you don't think that counts as returning a list of lists. I've always been fuzzy on that distinction.
                                                                        – Veskah
                                                                        Dec 8 '18 at 2:59












                                                                      • @veskah Yeah, that's almost what I had before my edit to this version. The problem with your solution or my earlier solution -- it doesn't return a list-of-lists. TIO1 vs TIO2
                                                                        – AdmBorkBork
                                                                        Dec 10 '18 at 13:44














                                                                      3












                                                                      3








                                                                      3







                                                                      PowerShell, 65 bytes





                                                                      param($a)'';$x=,0*($y=$a.count);0..--$y|%{$x[$_]=@($a[0..$_])};$x


                                                                      Try it online!



                                                                      PowerShell helpfully unrolls lists-of-lists when the default Write-Output happens at program completion, so you get one item per line. Tack on a -join',' to see the list-of-lists better, by converting the inner lists into strings.



                                                                      (Ab)uses the fact that attempting to output an empty array (e.g., @()) results in no output, so an empty array input just has '' as the output, since the $a[0..$_] will result in nothing. It will also throw out some spectacular error messages.






                                                                      share|improve this answer















                                                                      PowerShell, 65 bytes





                                                                      param($a)'';$x=,0*($y=$a.count);0..--$y|%{$x[$_]=@($a[0..$_])};$x


                                                                      Try it online!



                                                                      PowerShell helpfully unrolls lists-of-lists when the default Write-Output happens at program completion, so you get one item per line. Tack on a -join',' to see the list-of-lists better, by converting the inner lists into strings.



                                                                      (Ab)uses the fact that attempting to output an empty array (e.g., @()) results in no output, so an empty array input just has '' as the output, since the $a[0..$_] will result in nothing. It will also throw out some spectacular error messages.







                                                                      share|improve this answer














                                                                      share|improve this answer



                                                                      share|improve this answer








                                                                      edited Dec 7 '18 at 20:08

























                                                                      answered Dec 7 '18 at 19:38









                                                                      AdmBorkBork

                                                                      26.3k364228




                                                                      26.3k364228












                                                                      • Wrapping it in parens instead of assigning it saves 20 bytes. Unless you don't think that counts as returning a list of lists. I've always been fuzzy on that distinction.
                                                                        – Veskah
                                                                        Dec 8 '18 at 2:59












                                                                      • @veskah Yeah, that's almost what I had before my edit to this version. The problem with your solution or my earlier solution -- it doesn't return a list-of-lists. TIO1 vs TIO2
                                                                        – AdmBorkBork
                                                                        Dec 10 '18 at 13:44


















                                                                      • Wrapping it in parens instead of assigning it saves 20 bytes. Unless you don't think that counts as returning a list of lists. I've always been fuzzy on that distinction.
                                                                        – Veskah
                                                                        Dec 8 '18 at 2:59












                                                                      • @veskah Yeah, that's almost what I had before my edit to this version. The problem with your solution or my earlier solution -- it doesn't return a list-of-lists. TIO1 vs TIO2
                                                                        – AdmBorkBork
                                                                        Dec 10 '18 at 13:44
















                                                                      Wrapping it in parens instead of assigning it saves 20 bytes. Unless you don't think that counts as returning a list of lists. I've always been fuzzy on that distinction.
                                                                      – Veskah
                                                                      Dec 8 '18 at 2:59






                                                                      Wrapping it in parens instead of assigning it saves 20 bytes. Unless you don't think that counts as returning a list of lists. I've always been fuzzy on that distinction.
                                                                      – Veskah
                                                                      Dec 8 '18 at 2:59














                                                                      @veskah Yeah, that's almost what I had before my edit to this version. The problem with your solution or my earlier solution -- it doesn't return a list-of-lists. TIO1 vs TIO2
                                                                      – AdmBorkBork
                                                                      Dec 10 '18 at 13:44




                                                                      @veskah Yeah, that's almost what I had before my edit to this version. The problem with your solution or my earlier solution -- it doesn't return a list-of-lists. TIO1 vs TIO2
                                                                      – AdmBorkBork
                                                                      Dec 10 '18 at 13:44











                                                                      3















                                                                      K (ngn/k), 8 bytes



                                                                      ,(,!0),


                                                                      Try it online!






                                                                      share|improve this answer

















                                                                      • 1




                                                                        This is some kind of voodoo. ,(,()), in K4. Joining enlisted null along enlisted input? howsitwork?
                                                                        – streetster
                                                                        Dec 7 '18 at 20:46






                                                                      • 1




                                                                        @streetster () is an empty list. (,()),x prepends it to x. finally , does a concat-scan. the x is omitted to form a composition. note that the trailing , is dyadic, so it's "concat", not "enlist".
                                                                        – ngn
                                                                        Dec 7 '18 at 21:07








                                                                      • 1




                                                                        @streetster in k4 it can be a byte shorter: 1_',, but my parser isn't smart enough to handle this...
                                                                        – ngn
                                                                        Dec 7 '18 at 21:13


















                                                                      3















                                                                      K (ngn/k), 8 bytes



                                                                      ,(,!0),


                                                                      Try it online!






                                                                      share|improve this answer

















                                                                      • 1




                                                                        This is some kind of voodoo. ,(,()), in K4. Joining enlisted null along enlisted input? howsitwork?
                                                                        – streetster
                                                                        Dec 7 '18 at 20:46






                                                                      • 1




                                                                        @streetster () is an empty list. (,()),x prepends it to x. finally , does a concat-scan. the x is omitted to form a composition. note that the trailing , is dyadic, so it's "concat", not "enlist".
                                                                        – ngn
                                                                        Dec 7 '18 at 21:07








                                                                      • 1




                                                                        @streetster in k4 it can be a byte shorter: 1_',, but my parser isn't smart enough to handle this...
                                                                        – ngn
                                                                        Dec 7 '18 at 21:13
















                                                                      3












                                                                      3








                                                                      3







                                                                      K (ngn/k), 8 bytes



                                                                      ,(,!0),


                                                                      Try it online!






                                                                      share|improve this answer













                                                                      K (ngn/k), 8 bytes



                                                                      ,(,!0),


                                                                      Try it online!







                                                                      share|improve this answer












                                                                      share|improve this answer



                                                                      share|improve this answer










                                                                      answered Dec 7 '18 at 20:25









                                                                      ngn

                                                                      6,94112559




                                                                      6,94112559








                                                                      • 1




                                                                        This is some kind of voodoo. ,(,()), in K4. Joining enlisted null along enlisted input? howsitwork?
                                                                        – streetster
                                                                        Dec 7 '18 at 20:46






                                                                      • 1




                                                                        @streetster () is an empty list. (,()),x prepends it to x. finally , does a concat-scan. the x is omitted to form a composition. note that the trailing , is dyadic, so it's "concat", not "enlist".
                                                                        – ngn
                                                                        Dec 7 '18 at 21:07








                                                                      • 1




                                                                        @streetster in k4 it can be a byte shorter: 1_',, but my parser isn't smart enough to handle this...
                                                                        – ngn
                                                                        Dec 7 '18 at 21:13
















                                                                      • 1




                                                                        This is some kind of voodoo. ,(,()), in K4. Joining enlisted null along enlisted input? howsitwork?
                                                                        – streetster
                                                                        Dec 7 '18 at 20:46






                                                                      • 1




                                                                        @streetster () is an empty list. (,()),x prepends it to x. finally , does a concat-scan. the x is omitted to form a composition. note that the trailing , is dyadic, so it's "concat", not "enlist".
                                                                        – ngn
                                                                        Dec 7 '18 at 21:07








                                                                      • 1




                                                                        @streetster in k4 it can be a byte shorter: 1_',, but my parser isn't smart enough to handle this...
                                                                        – ngn
                                                                        Dec 7 '18 at 21:13










                                                                      1




                                                                      1




                                                                      This is some kind of voodoo. ,(,()), in K4. Joining enlisted null along enlisted input? howsitwork?
                                                                      – streetster
                                                                      Dec 7 '18 at 20:46




                                                                      This is some kind of voodoo. ,(,()), in K4. Joining enlisted null along enlisted input? howsitwork?
                                                                      – streetster
                                                                      Dec 7 '18 at 20:46




                                                                      1




                                                                      1




                                                                      @streetster () is an empty list. (,()),x prepends it to x. finally , does a concat-scan. the x is omitted to form a composition. note that the trailing , is dyadic, so it's "concat", not "enlist".
                                                                      – ngn
                                                                      Dec 7 '18 at 21:07






                                                                      @streetster () is an empty list. (,()),x prepends it to x. finally , does a concat-scan. the x is omitted to form a composition. note that the trailing , is dyadic, so it's "concat", not "enlist".
                                                                      – ngn
                                                                      Dec 7 '18 at 21:07






                                                                      1




                                                                      1




                                                                      @streetster in k4 it can be a byte shorter: 1_',, but my parser isn't smart enough to handle this...
                                                                      – ngn
                                                                      Dec 7 '18 at 21:13






                                                                      @streetster in k4 it can be a byte shorter: 1_',, but my parser isn't smart enough to handle this...
                                                                      – ngn
                                                                      Dec 7 '18 at 21:13













                                                                      3















                                                                      Common Lisp, 39 bytes





                                                                      (defun f(l)`(,@(if l(f(butlast l))),l))


                                                                      Try it online!



                                                                      Explanation



                                                                      (defun f(l)                           )  ; Define a function f
                                                                      `( ) ; With the list (essentially capable of interpolation), containing:
                                                                      ,@ ; The value of, flattened to one level
                                                                      (if l ) ; If l is not the empty list (which is the representation of nil, i.e. the only falsy value)
                                                                      (f(butlast l)) ; Recurse with all of l but the tail
                                                                      ,l ; The value of l





                                                                      share|improve this answer


























                                                                        3















                                                                        Common Lisp, 39 bytes





                                                                        (defun f(l)`(,@(if l(f(butlast l))),l))


                                                                        Try it online!



                                                                        Explanation



                                                                        (defun f(l)                           )  ; Define a function f
                                                                        `( ) ; With the list (essentially capable of interpolation), containing:
                                                                        ,@ ; The value of, flattened to one level
                                                                        (if l ) ; If l is not the empty list (which is the representation of nil, i.e. the only falsy value)
                                                                        (f(butlast l)) ; Recurse with all of l but the tail
                                                                        ,l ; The value of l





                                                                        share|improve this answer
























                                                                          3












                                                                          3








                                                                          3







                                                                          Common Lisp, 39 bytes





                                                                          (defun f(l)`(,@(if l(f(butlast l))),l))


                                                                          Try it online!



                                                                          Explanation



                                                                          (defun f(l)                           )  ; Define a function f
                                                                          `( ) ; With the list (essentially capable of interpolation), containing:
                                                                          ,@ ; The value of, flattened to one level
                                                                          (if l ) ; If l is not the empty list (which is the representation of nil, i.e. the only falsy value)
                                                                          (f(butlast l)) ; Recurse with all of l but the tail
                                                                          ,l ; The value of l





                                                                          share|improve this answer













                                                                          Common Lisp, 39 bytes





                                                                          (defun f(l)`(,@(if l(f(butlast l))),l))


                                                                          Try it online!



                                                                          Explanation



                                                                          (defun f(l)                           )  ; Define a function f
                                                                          `( ) ; With the list (essentially capable of interpolation), containing:
                                                                          ,@ ; The value of, flattened to one level
                                                                          (if l ) ; If l is not the empty list (which is the representation of nil, i.e. the only falsy value)
                                                                          (f(butlast l)) ; Recurse with all of l but the tail
                                                                          ,l ; The value of l






                                                                          share|improve this answer












                                                                          share|improve this answer



                                                                          share|improve this answer










                                                                          answered Dec 7 '18 at 23:18









                                                                          ASCII-only

                                                                          3,2011136




                                                                          3,2011136























                                                                              3














                                                                              F#, 53 bytes



                                                                              I've actually got two pretty similar answers for this, both the same length. They both take a generic sequence s as a parameter.



                                                                              First solution:



                                                                              let i s=Seq.init(Seq.length s+1)(fun n->Seq.take n s)


                                                                              Try it online!



                                                                              Seq.take takes the first n elements of the sequence. Seq.init creates a new sequence with a count (in this case) of the length of sequence s plus 1, and for each element in the sequence takes the first n elements in s.



                                                                              Second solution:



                                                                              let i s=Seq.map(fun n->Seq.take n s){0..Seq.length s}


                                                                              Similar to before, except it creates a sequence from 0 to the length of s. Then takes that number of elements from s.



                                                                              Try this online too!






                                                                              share|improve this answer























                                                                              • fun s->Seq.map(fun n->Seq.take n s){0..Seq.length s} saves 1 byte
                                                                                – Embodiment of Ignorance
                                                                                Dec 9 '18 at 6:41


















                                                                              3














                                                                              F#, 53 bytes



                                                                              I've actually got two pretty similar answers for this, both the same length. They both take a generic sequence s as a parameter.



                                                                              First solution:



                                                                              let i s=Seq.init(Seq.length s+1)(fun n->Seq.take n s)


                                                                              Try it online!



                                                                              Seq.take takes the first n elements of the sequence. Seq.init creates a new sequence with a count (in this case) of the length of sequence s plus 1, and for each element in the sequence takes the first n elements in s.



                                                                              Second solution:



                                                                              let i s=Seq.map(fun n->Seq.take n s){0..Seq.length s}


                                                                              Similar to before, except it creates a sequence from 0 to the length of s. Then takes that number of elements from s.



                                                                              Try this online too!






                                                                              share|improve this answer























                                                                              • fun s->Seq.map(fun n->Seq.take n s){0..Seq.length s} saves 1 byte
                                                                                – Embodiment of Ignorance
                                                                                Dec 9 '18 at 6:41
















                                                                              3












                                                                              3








                                                                              3






                                                                              F#, 53 bytes



                                                                              I've actually got two pretty similar answers for this, both the same length. They both take a generic sequence s as a parameter.



                                                                              First solution:



                                                                              let i s=Seq.init(Seq.length s+1)(fun n->Seq.take n s)


                                                                              Try it online!



                                                                              Seq.take takes the first n elements of the sequence. Seq.init creates a new sequence with a count (in this case) of the length of sequence s plus 1, and for each element in the sequence takes the first n elements in s.



                                                                              Second solution:



                                                                              let i s=Seq.map(fun n->Seq.take n s){0..Seq.length s}


                                                                              Similar to before, except it creates a sequence from 0 to the length of s. Then takes that number of elements from s.



                                                                              Try this online too!






                                                                              share|improve this answer














                                                                              F#, 53 bytes



                                                                              I've actually got two pretty similar answers for this, both the same length. They both take a generic sequence s as a parameter.



                                                                              First solution:



                                                                              let i s=Seq.init(Seq.length s+1)(fun n->Seq.take n s)


                                                                              Try it online!



                                                                              Seq.take takes the first n elements of the sequence. Seq.init creates a new sequence with a count (in this case) of the length of sequence s plus 1, and for each element in the sequence takes the first n elements in s.



                                                                              Second solution:



                                                                              let i s=Seq.map(fun n->Seq.take n s){0..Seq.length s}


                                                                              Similar to before, except it creates a sequence from 0 to the length of s. Then takes that number of elements from s.



                                                                              Try this online too!







                                                                              share|improve this answer














                                                                              share|improve this answer



                                                                              share|improve this answer








                                                                              edited Dec 7 '18 at 23:57

























                                                                              answered Dec 7 '18 at 23:47









                                                                              Ciaran_McCarthy

                                                                              521118




                                                                              521118












                                                                              • fun s->Seq.map(fun n->Seq.take n s){0..Seq.length s} saves 1 byte
                                                                                – Embodiment of Ignorance
                                                                                Dec 9 '18 at 6:41




















                                                                              • fun s->Seq.map(fun n->Seq.take n s){0..Seq.length s} saves 1 byte
                                                                                – Embodiment of Ignorance
                                                                                Dec 9 '18 at 6:41


















                                                                              fun s->Seq.map(fun n->Seq.take n s){0..Seq.length s} saves 1 byte
                                                                              – Embodiment of Ignorance
                                                                              Dec 9 '18 at 6:41






                                                                              fun s->Seq.map(fun n->Seq.take n s){0..Seq.length s} saves 1 byte
                                                                              – Embodiment of Ignorance
                                                                              Dec 9 '18 at 6:41













                                                                              3















                                                                              Husk, 2 bytes



                                                                              Θḣ


                                                                              Gets all the eads and then prepends Θ (in this case ):



                                                                              Try it online!



                                                                              (needs type annotation for empty list: Try it online!)






                                                                              share|improve this answer


























                                                                                3















                                                                                Husk, 2 bytes



                                                                                Θḣ


                                                                                Gets all the eads and then prepends Θ (in this case ):



                                                                                Try it online!



                                                                                (needs type annotation for empty list: Try it online!)






                                                                                share|improve this answer
























                                                                                  3












                                                                                  3








                                                                                  3







                                                                                  Husk, 2 bytes



                                                                                  Θḣ


                                                                                  Gets all the eads and then prepends Θ (in this case ):



                                                                                  Try it online!



                                                                                  (needs type annotation for empty list: Try it online!)






                                                                                  share|improve this answer













                                                                                  Husk, 2 bytes



                                                                                  Θḣ


                                                                                  Gets all the eads and then prepends Θ (in this case ):



                                                                                  Try it online!



                                                                                  (needs type annotation for empty list: Try it online!)







                                                                                  share|improve this answer












                                                                                  share|improve this answer



                                                                                  share|improve this answer










                                                                                  answered Dec 8 '18 at 0:35









                                                                                  BMO

                                                                                  11.4k22186




                                                                                  11.4k22186























                                                                                      3














                                                                                      MATL, 15 12 bytes



                                                                                      3 bytes saved thanks to @Giuseppe



                                                                                      vin:"G@:)]Xh


                                                                                      Try it at MATL Online.



                                                                                      Due to the way that MATL displays the output, you can't explicitly see the empty array in the cell array. Here is a version that shows the output a little more explicitly.



                                                                                      Explanation



                                                                                      v       # Vertically concatenate the (empty) stack to create the array 
                                                                                      i # Explicitly grab the input
                                                                                      n # Compute the number of elements in the input (N)
                                                                                      : # Create an array from [1, ..., N]
                                                                                      " # Loop through this array
                                                                                      G # For each of these numbers, M
                                                                                      @: # Create an array from [1, ..., M]
                                                                                      ) # Use this to index into the initial array
                                                                                      ] # End of the for loop
                                                                                      Xh # Concatenate the entire stack into a cell array





                                                                                      share|improve this answer























                                                                                      • use v instead of . And doesn't : use 1 as the default first argument? So this could be vin:"G@:)]Xh for 12 bytes.
                                                                                        – Giuseppe
                                                                                        Dec 10 '18 at 18:34










                                                                                      • @Giuseppe Thanks! My MATL is a little rusty it seems :(
                                                                                        – Suever
                                                                                        Dec 10 '18 at 22:04
















                                                                                      3














                                                                                      MATL, 15 12 bytes



                                                                                      3 bytes saved thanks to @Giuseppe



                                                                                      vin:"G@:)]Xh


                                                                                      Try it at MATL Online.



                                                                                      Due to the way that MATL displays the output, you can't explicitly see the empty array in the cell array. Here is a version that shows the output a little more explicitly.



                                                                                      Explanation



                                                                                      v       # Vertically concatenate the (empty) stack to create the array 
                                                                                      i # Explicitly grab the input
                                                                                      n # Compute the number of elements in the input (N)
                                                                                      : # Create an array from [1, ..., N]
                                                                                      " # Loop through this array
                                                                                      G # For each of these numbers, M
                                                                                      @: # Create an array from [1, ..., M]
                                                                                      ) # Use this to index into the initial array
                                                                                      ] # End of the for loop
                                                                                      Xh # Concatenate the entire stack into a cell array





                                                                                      share|improve this answer























                                                                                      • use v instead of . And doesn't : use 1 as the default first argument? So this could be vin:"G@:)]Xh for 12 bytes.
                                                                                        – Giuseppe
                                                                                        Dec 10 '18 at 18:34










                                                                                      • @Giuseppe Thanks! My MATL is a little rusty it seems :(
                                                                                        – Suever
                                                                                        Dec 10 '18 at 22:04














                                                                                      3












                                                                                      3








                                                                                      3






                                                                                      MATL, 15 12 bytes



                                                                                      3 bytes saved thanks to @Giuseppe



                                                                                      vin:"G@:)]Xh


                                                                                      Try it at MATL Online.



                                                                                      Due to the way that MATL displays the output, you can't explicitly see the empty array in the cell array. Here is a version that shows the output a little more explicitly.



                                                                                      Explanation



                                                                                      v       # Vertically concatenate the (empty) stack to create the array 
                                                                                      i # Explicitly grab the input
                                                                                      n # Compute the number of elements in the input (N)
                                                                                      : # Create an array from [1, ..., N]
                                                                                      " # Loop through this array
                                                                                      G # For each of these numbers, M
                                                                                      @: # Create an array from [1, ..., M]
                                                                                      ) # Use this to index into the initial array
                                                                                      ] # End of the for loop
                                                                                      Xh # Concatenate the entire stack into a cell array





                                                                                      share|improve this answer














                                                                                      MATL, 15 12 bytes



                                                                                      3 bytes saved thanks to @Giuseppe



                                                                                      vin:"G@:)]Xh


                                                                                      Try it at MATL Online.



                                                                                      Due to the way that MATL displays the output, you can't explicitly see the empty array in the cell array. Here is a version that shows the output a little more explicitly.



                                                                                      Explanation



                                                                                      v       # Vertically concatenate the (empty) stack to create the array 
                                                                                      i # Explicitly grab the input
                                                                                      n # Compute the number of elements in the input (N)
                                                                                      : # Create an array from [1, ..., N]
                                                                                      " # Loop through this array
                                                                                      G # For each of these numbers, M
                                                                                      @: # Create an array from [1, ..., M]
                                                                                      ) # Use this to index into the initial array
                                                                                      ] # End of the for loop
                                                                                      Xh # Concatenate the entire stack into a cell array






                                                                                      share|improve this answer














                                                                                      share|improve this answer



                                                                                      share|improve this answer








                                                                                      edited Dec 10 '18 at 22:04

























                                                                                      answered Dec 9 '18 at 22:22









                                                                                      Suever

                                                                                      9,5421345




                                                                                      9,5421345












                                                                                      • use v instead of . And doesn't : use 1 as the default first argument? So this could be vin:"G@:)]Xh for 12 bytes.
                                                                                        – Giuseppe
                                                                                        Dec 10 '18 at 18:34










                                                                                      • @Giuseppe Thanks! My MATL is a little rusty it seems :(
                                                                                        – Suever
                                                                                        Dec 10 '18 at 22:04


















                                                                                      • use v instead of . And doesn't : use 1 as the default first argument? So this could be vin:"G@:)]Xh for 12 bytes.
                                                                                        – Giuseppe
                                                                                        Dec 10 '18 at 18:34










                                                                                      • @Giuseppe Thanks! My MATL is a little rusty it seems :(
                                                                                        – Suever
                                                                                        Dec 10 '18 at 22:04
















                                                                                      use v instead of . And doesn't : use 1 as the default first argument? So this could be vin:"G@:)]Xh for 12 bytes.
                                                                                      – Giuseppe
                                                                                      Dec 10 '18 at 18:34




                                                                                      use v instead of . And doesn't : use 1 as the default first argument? So this could be vin:"G@:)]Xh for 12 bytes.
                                                                                      – Giuseppe
                                                                                      Dec 10 '18 at 18:34












                                                                                      @Giuseppe Thanks! My MATL is a little rusty it seems :(
                                                                                      – Suever
                                                                                      Dec 10 '18 at 22:04




                                                                                      @Giuseppe Thanks! My MATL is a little rusty it seems :(
                                                                                      – Suever
                                                                                      Dec 10 '18 at 22:04











                                                                                      3















                                                                                      SWI PROLOG 22 bytes



                                                                                      i(X,Y):-append(X,_,Y).






                                                                                      share|improve this answer


























                                                                                        3















                                                                                        SWI PROLOG 22 bytes



                                                                                        i(X,Y):-append(X,_,Y).






                                                                                        share|improve this answer
























                                                                                          3












                                                                                          3








                                                                                          3







                                                                                          SWI PROLOG 22 bytes



                                                                                          i(X,Y):-append(X,_,Y).






                                                                                          share|improve this answer













                                                                                          SWI PROLOG 22 bytes



                                                                                          i(X,Y):-append(X,_,Y).







                                                                                          share|improve this answer












                                                                                          share|improve this answer



                                                                                          share|improve this answer










                                                                                          answered Dec 10 '18 at 22:45









                                                                                          styrofoam fly

                                                                                          1516




                                                                                          1516























                                                                                              2















                                                                                              Charcoal, 6 bytes



                                                                                              Eθ…θκθ


                                                                                              Try it online! Link is to verbose version of code. Explanation:



                                                                                               θ      Input array
                                                                                              E Map over elements
                                                                                              θ Input array
                                                                                              … Moulded to length
                                                                                              κ Current loop index
                                                                                              Implicitly print each array double-spaced
                                                                                              θ Input array
                                                                                              Implicitly print


                                                                                              It's possible at a cost of 1 byte to ask Charcoal to print an n+1-element array which includes the input as its last element, but the output is the same, although the cursor position would be different if you then went on to print something else.






                                                                                              share|improve this answer


























                                                                                                2















                                                                                                Charcoal, 6 bytes



                                                                                                Eθ…θκθ


                                                                                                Try it online! Link is to verbose version of code. Explanation:



                                                                                                 θ      Input array
                                                                                                E Map over elements
                                                                                                θ Input array
                                                                                                … Moulded to length
                                                                                                κ Current loop index
                                                                                                Implicitly print each array double-spaced
                                                                                                θ Input array
                                                                                                Implicitly print


                                                                                                It's possible at a cost of 1 byte to ask Charcoal to print an n+1-element array which includes the input as its last element, but the output is the same, although the cursor position would be different if you then went on to print something else.






                                                                                                share|improve this answer
























                                                                                                  2












                                                                                                  2








                                                                                                  2







                                                                                                  Charcoal, 6 bytes



                                                                                                  Eθ…θκθ


                                                                                                  Try it online! Link is to verbose version of code. Explanation:



                                                                                                   θ      Input array
                                                                                                  E Map over elements
                                                                                                  θ Input array
                                                                                                  … Moulded to length
                                                                                                  κ Current loop index
                                                                                                  Implicitly print each array double-spaced
                                                                                                  θ Input array
                                                                                                  Implicitly print


                                                                                                  It's possible at a cost of 1 byte to ask Charcoal to print an n+1-element array which includes the input as its last element, but the output is the same, although the cursor position would be different if you then went on to print something else.






                                                                                                  share|improve this answer













                                                                                                  Charcoal, 6 bytes



                                                                                                  Eθ…θκθ


                                                                                                  Try it online! Link is to verbose version of code. Explanation:



                                                                                                   θ      Input array
                                                                                                  E Map over elements
                                                                                                  θ Input array
                                                                                                  … Moulded to length
                                                                                                  κ Current loop index
                                                                                                  Implicitly print each array double-spaced
                                                                                                  θ Input array
                                                                                                  Implicitly print


                                                                                                  It's possible at a cost of 1 byte to ask Charcoal to print an n+1-element array which includes the input as its last element, but the output is the same, although the cursor position would be different if you then went on to print something else.







                                                                                                  share|improve this answer












                                                                                                  share|improve this answer



                                                                                                  share|improve this answer










                                                                                                  answered Dec 7 '18 at 20:02









                                                                                                  Neil

                                                                                                  79.4k744177




                                                                                                  79.4k744177























                                                                                                      2















                                                                                                      Groovy, 37 bytes



                                                                                                      {x->(0..x.size()).collect{x[0..<it]}}


                                                                                                      Try it online!






                                                                                                      share|improve this answer





















                                                                                                      • {it.inits().reverse()} will work once we get groovy 2.5 on TIO
                                                                                                        – ASCII-only
                                                                                                        yesterday
















                                                                                                      2















                                                                                                      Groovy, 37 bytes



                                                                                                      {x->(0..x.size()).collect{x[0..<it]}}


                                                                                                      Try it online!






                                                                                                      share|improve this answer





















                                                                                                      • {it.inits().reverse()} will work once we get groovy 2.5 on TIO
                                                                                                        – ASCII-only
                                                                                                        yesterday














                                                                                                      2












                                                                                                      2








                                                                                                      2







                                                                                                      Groovy, 37 bytes



                                                                                                      {x->(0..x.size()).collect{x[0..<it]}}


                                                                                                      Try it online!






                                                                                                      share|improve this answer













                                                                                                      Groovy, 37 bytes



                                                                                                      {x->(0..x.size()).collect{x[0..<it]}}


                                                                                                      Try it online!







                                                                                                      share|improve this answer












                                                                                                      share|improve this answer



                                                                                                      share|improve this answer










                                                                                                      answered Dec 7 '18 at 23:25









                                                                                                      GolfIsAGoodWalkSpoilt

                                                                                                      1012




                                                                                                      1012












                                                                                                      • {it.inits().reverse()} will work once we get groovy 2.5 on TIO
                                                                                                        – ASCII-only
                                                                                                        yesterday


















                                                                                                      • {it.inits().reverse()} will work once we get groovy 2.5 on TIO
                                                                                                        – ASCII-only
                                                                                                        yesterday
















                                                                                                      {it.inits().reverse()} will work once we get groovy 2.5 on TIO
                                                                                                      – ASCII-only
                                                                                                      yesterday




                                                                                                      {it.inits().reverse()} will work once we get groovy 2.5 on TIO
                                                                                                      – ASCII-only
                                                                                                      yesterday











                                                                                                      2















                                                                                                      Japt, 5 bytes



                                                                                                      Êò@¯Y


                                                                                                      Try it online!






                                                                                                      share|improve this answer


























                                                                                                        2















                                                                                                        Japt, 5 bytes



                                                                                                        Êò@¯Y


                                                                                                        Try it online!






                                                                                                        share|improve this answer
























                                                                                                          2












                                                                                                          2








                                                                                                          2







                                                                                                          Japt, 5 bytes



                                                                                                          Êò@¯Y


                                                                                                          Try it online!






                                                                                                          share|improve this answer













                                                                                                          Japt, 5 bytes



                                                                                                          Êò@¯Y


                                                                                                          Try it online!







                                                                                                          share|improve this answer












                                                                                                          share|improve this answer



                                                                                                          share|improve this answer










                                                                                                          answered Dec 8 '18 at 2:11









                                                                                                          Oliver

                                                                                                          4,7401831




                                                                                                          4,7401831























                                                                                                              2















                                                                                                              brainfuck, 43 bytes



                                                                                                              Take a list of non-null characters as input and returns all prefixes separated by newline. Requires double-infinite or wrapping tape.



                                                                                                              ,>-[+>,]<[-<]<<++++++++++[[<]>[.>]>[-<+>]<]


                                                                                                              Try it online!






                                                                                                              share|improve this answer























                                                                                                              • Another answer outgolfed me by more than a half, because I didn't think about printing output while reading. Of course that method won't work with printing increasing suffixes.
                                                                                                                – user202729
                                                                                                                Dec 8 '18 at 9:58










                                                                                                              • 40 bytes with some rearranging
                                                                                                                – Jo King
                                                                                                                Dec 8 '18 at 10:19
















                                                                                                              2















                                                                                                              brainfuck, 43 bytes



                                                                                                              Take a list of non-null characters as input and returns all prefixes separated by newline. Requires double-infinite or wrapping tape.



                                                                                                              ,>-[+>,]<[-<]<<++++++++++[[<]>[.>]>[-<+>]<]


                                                                                                              Try it online!






                                                                                                              share|improve this answer























                                                                                                              • Another answer outgolfed me by more than a half, because I didn't think about printing output while reading. Of course that method won't work with printing increasing suffixes.
                                                                                                                – user202729
                                                                                                                Dec 8 '18 at 9:58










                                                                                                              • 40 bytes with some rearranging
                                                                                                                – Jo King
                                                                                                                Dec 8 '18 at 10:19














                                                                                                              2












                                                                                                              2








                                                                                                              2







                                                                                                              brainfuck, 43 bytes



                                                                                                              Take a list of non-null characters as input and returns all prefixes separated by newline. Requires double-infinite or wrapping tape.



                                                                                                              ,>-[+>,]<[-<]<<++++++++++[[<]>[.>]>[-<+>]<]


                                                                                                              Try it online!






                                                                                                              share|improve this answer















                                                                                                              brainfuck, 43 bytes



                                                                                                              Take a list of non-null characters as input and returns all prefixes separated by newline. Requires double-infinite or wrapping tape.



                                                                                                              ,>-[+>,]<[-<]<<++++++++++[[<]>[.>]>[-<+>]<]


                                                                                                              Try it online!







                                                                                                              share|improve this answer














                                                                                                              share|improve this answer



                                                                                                              share|improve this answer








                                                                                                              edited Dec 8 '18 at 7:13

























                                                                                                              answered Dec 8 '18 at 7:08









                                                                                                              user202729

                                                                                                              13.9k12551




                                                                                                              13.9k12551












                                                                                                              • Another answer outgolfed me by more than a half, because I didn't think about printing output while reading. Of course that method won't work with printing increasing suffixes.
                                                                                                                – user202729
                                                                                                                Dec 8 '18 at 9:58










                                                                                                              • 40 bytes with some rearranging
                                                                                                                – Jo King
                                                                                                                Dec 8 '18 at 10:19


















                                                                                                              • Another answer outgolfed me by more than a half, because I didn't think about printing output while reading. Of course that method won't work with printing increasing suffixes.
                                                                                                                – user202729
                                                                                                                Dec 8 '18 at 9:58










                                                                                                              • 40 bytes with some rearranging
                                                                                                                – Jo King
                                                                                                                Dec 8 '18 at 10:19
















                                                                                                              Another answer outgolfed me by more than a half, because I didn't think about printing output while reading. Of course that method won't work with printing increasing suffixes.
                                                                                                              – user202729
                                                                                                              Dec 8 '18 at 9:58




                                                                                                              Another answer outgolfed me by more than a half, because I didn't think about printing output while reading. Of course that method won't work with printing increasing suffixes.
                                                                                                              – user202729
                                                                                                              Dec 8 '18 at 9:58












                                                                                                              40 bytes with some rearranging
                                                                                                              – Jo King
                                                                                                              Dec 8 '18 at 10:19




                                                                                                              40 bytes with some rearranging
                                                                                                              – Jo King
                                                                                                              Dec 8 '18 at 10:19











                                                                                                              2















                                                                                                              C# (Visual C# Interactive Compiler), 39 bytes





                                                                                                              x=>x.Select((_,i)=>x.Take(i)).Append(x)


                                                                                                              Try it online!






                                                                                                              share|improve this answer





















                                                                                                              • You need to include the using System.Linq; in your bytecount. And it seems some of your output logic is in your outputting of the arrays. Because empty array just returns empty array.
                                                                                                                – LiefdeWen
                                                                                                                Dec 11 '18 at 9:51










                                                                                                              • @LiefdeWen - my understanding is that since this interpreter includes a reference to System.Linq, I don't have to include this in the byte count. My submission would be considered a different language than say .NET Core. github.com/dotnet/roslyn/wiki/C%23-Interactive-Walkthrough - You mention printing which is a separate issue, I'd like to get clarity on this first.
                                                                                                                – dana
                                                                                                                Dec 11 '18 at 10:35










                                                                                                              • With regards to printing, here is a version that basically dumps the result to the console - tio.run/##XY29CsIwGEX3PEXGBGKhtVt/… - not as pretty for sure! The question I have is when is it acceptable to use Array vs IList vs IEnumerable.
                                                                                                                – dana
                                                                                                                Dec 11 '18 at 10:59
















                                                                                                              2















                                                                                                              C# (Visual C# Interactive Compiler), 39 bytes





                                                                                                              x=>x.Select((_,i)=>x.Take(i)).Append(x)


                                                                                                              Try it online!






                                                                                                              share|improve this answer





















                                                                                                              • You need to include the using System.Linq; in your bytecount. And it seems some of your output logic is in your outputting of the arrays. Because empty array just returns empty array.
                                                                                                                – LiefdeWen
                                                                                                                Dec 11 '18 at 9:51










                                                                                                              • @LiefdeWen - my understanding is that since this interpreter includes a reference to System.Linq, I don't have to include this in the byte count. My submission would be considered a different language than say .NET Core. github.com/dotnet/roslyn/wiki/C%23-Interactive-Walkthrough - You mention printing which is a separate issue, I'd like to get clarity on this first.
                                                                                                                – dana
                                                                                                                Dec 11 '18 at 10:35










                                                                                                              • With regards to printing, here is a version that basically dumps the result to the console - tio.run/##XY29CsIwGEX3PEXGBGKhtVt/… - not as pretty for sure! The question I have is when is it acceptable to use Array vs IList vs IEnumerable.
                                                                                                                – dana
                                                                                                                Dec 11 '18 at 10:59














                                                                                                              2












                                                                                                              2








                                                                                                              2







                                                                                                              C# (Visual C# Interactive Compiler), 39 bytes





                                                                                                              x=>x.Select((_,i)=>x.Take(i)).Append(x)


                                                                                                              Try it online!






                                                                                                              share|improve this answer













                                                                                                              C# (Visual C# Interactive Compiler), 39 bytes





                                                                                                              x=>x.Select((_,i)=>x.Take(i)).Append(x)


                                                                                                              Try it online!







                                                                                                              share|improve this answer












                                                                                                              share|improve this answer



                                                                                                              share|improve this answer










                                                                                                              answered Dec 9 '18 at 4:32









                                                                                                              dana

                                                                                                              45135




                                                                                                              45135












                                                                                                              • You need to include the using System.Linq; in your bytecount. And it seems some of your output logic is in your outputting of the arrays. Because empty array just returns empty array.
                                                                                                                – LiefdeWen
                                                                                                                Dec 11 '18 at 9:51










                                                                                                              • @LiefdeWen - my understanding is that since this interpreter includes a reference to System.Linq, I don't have to include this in the byte count. My submission would be considered a different language than say .NET Core. github.com/dotnet/roslyn/wiki/C%23-Interactive-Walkthrough - You mention printing which is a separate issue, I'd like to get clarity on this first.
                                                                                                                – dana
                                                                                                                Dec 11 '18 at 10:35










                                                                                                              • With regards to printing, here is a version that basically dumps the result to the console - tio.run/##XY29CsIwGEX3PEXGBGKhtVt/… - not as pretty for sure! The question I have is when is it acceptable to use Array vs IList vs IEnumerable.
                                                                                                                – dana
                                                                                                                Dec 11 '18 at 10:59


















                                                                                                              • You need to include the using System.Linq; in your bytecount. And it seems some of your output logic is in your outputting of the arrays. Because empty array just returns empty array.
                                                                                                                – LiefdeWen
                                                                                                                Dec 11 '18 at 9:51










                                                                                                              • @LiefdeWen - my understanding is that since this interpreter includes a reference to System.Linq, I don't have to include this in the byte count. My submission would be considered a different language than say .NET Core. github.com/dotnet/roslyn/wiki/C%23-Interactive-Walkthrough - You mention printing which is a separate issue, I'd like to get clarity on this first.
                                                                                                                – dana
                                                                                                                Dec 11 '18 at 10:35










                                                                                                              • With regards to printing, here is a version that basically dumps the result to the console - tio.run/##XY29CsIwGEX3PEXGBGKhtVt/… - not as pretty for sure! The question I have is when is it acceptable to use Array vs IList vs IEnumerable.
                                                                                                                – dana
                                                                                                                Dec 11 '18 at 10:59
















                                                                                                              You need to include the using System.Linq; in your bytecount. And it seems some of your output logic is in your outputting of the arrays. Because empty array just returns empty array.
                                                                                                              – LiefdeWen
                                                                                                              Dec 11 '18 at 9:51




                                                                                                              You need to include the using System.Linq; in your bytecount. And it seems some of your output logic is in your outputting of the arrays. Because empty array just returns empty array.
                                                                                                              – LiefdeWen
                                                                                                              Dec 11 '18 at 9:51












                                                                                                              @LiefdeWen - my understanding is that since this interpreter includes a reference to System.Linq, I don't have to include this in the byte count. My submission would be considered a different language than say .NET Core. github.com/dotnet/roslyn/wiki/C%23-Interactive-Walkthrough - You mention printing which is a separate issue, I'd like to get clarity on this first.
                                                                                                              – dana
                                                                                                              Dec 11 '18 at 10:35




                                                                                                              @LiefdeWen - my understanding is that since this interpreter includes a reference to System.Linq, I don't have to include this in the byte count. My submission would be considered a different language than say .NET Core. github.com/dotnet/roslyn/wiki/C%23-Interactive-Walkthrough - You mention printing which is a separate issue, I'd like to get clarity on this first.
                                                                                                              – dana
                                                                                                              Dec 11 '18 at 10:35












                                                                                                              With regards to printing, here is a version that basically dumps the result to the console - tio.run/##XY29CsIwGEX3PEXGBGKhtVt/… - not as pretty for sure! The question I have is when is it acceptable to use Array vs IList vs IEnumerable.
                                                                                                              – dana
                                                                                                              Dec 11 '18 at 10:59




                                                                                                              With regards to printing, here is a version that basically dumps the result to the console - tio.run/##XY29CsIwGEX3PEXGBGKhtVt/… - not as pretty for sure! The question I have is when is it acceptable to use Array vs IList vs IEnumerable.
                                                                                                              – dana
                                                                                                              Dec 11 '18 at 10:59











                                                                                                              2















                                                                                                              C (gcc), 102 bytes





                                                                                                              Pretty long, as C quite obviously isn't well-suited to manipulating lists of lists.



                                                                                                              Takes in a pointer to the first element of the input array, the length of the array, and a pointer to the variable in which the pointer to output will be stored. Produces a list of lists such that the first integer in the linear array stores the number of sub-lists. Sub-lists start with the number of elements, and are stored in memory in a contiguous manner.



                                                                                                              p(r,e,f,i,x)int*e,**r,*x;{x=*r=malloc(++f*-~f+2<<1);*x++=f;for(i=0;i<f;x+=++i)*x=i,memcpy(x+1,e,4*i);}


                                                                                                              Try it online!



                                                                                                              Degolf



                                                                                                              p(r,e,f,i,x) int*e,**r,*x; { // Declare function p. e is the input array, 
                                                                                                              // r is a pointer to the variable that will store output,
                                                                                                              // and x is a local iterator for r.
                                                                                                              x=*r=malloc(++f*-~f+2<<1);// Allocate 2*(n+1)*(n+2)+4 bytes of memory,
                                                                                                              // and store pointers in r and x.
                                                                                                              *x++=f; // Store the number of arrays in the first variable (n+1)
                                                                                                              for(i=0;i<f;x+=++i) // Iterate from 0 to f; x is incremented by i+1 every loop.
                                                                                                              *x=i, // Store the length of the current sub-list.
                                                                                                              memcpy(x+1,e,4*i); // Copy the data.
                                                                                                              }





                                                                                                              share|improve this answer





















                                                                                                              • 97 bytes
                                                                                                                – ceilingcat
                                                                                                                18 hours ago










                                                                                                              • @ceilingcat Thanks, will edit it in later when I get back onto a PC.
                                                                                                                – Rogem
                                                                                                                5 hours ago
















                                                                                                              2















                                                                                                              C (gcc), 102 bytes





                                                                                                              Pretty long, as C quite obviously isn't well-suited to manipulating lists of lists.



                                                                                                              Takes in a pointer to the first element of the input array, the length of the array, and a pointer to the variable in which the pointer to output will be stored. Produces a list of lists such that the first integer in the linear array stores the number of sub-lists. Sub-lists start with the number of elements, and are stored in memory in a contiguous manner.



                                                                                                              p(r,e,f,i,x)int*e,**r,*x;{x=*r=malloc(++f*-~f+2<<1);*x++=f;for(i=0;i<f;x+=++i)*x=i,memcpy(x+1,e,4*i);}


                                                                                                              Try it online!



                                                                                                              Degolf



                                                                                                              p(r,e,f,i,x) int*e,**r,*x; { // Declare function p. e is the input array, 
                                                                                                              // r is a pointer to the variable that will store output,
                                                                                                              // and x is a local iterator for r.
                                                                                                              x=*r=malloc(++f*-~f+2<<1);// Allocate 2*(n+1)*(n+2)+4 bytes of memory,
                                                                                                              // and store pointers in r and x.
                                                                                                              *x++=f; // Store the number of arrays in the first variable (n+1)
                                                                                                              for(i=0;i<f;x+=++i) // Iterate from 0 to f; x is incremented by i+1 every loop.
                                                                                                              *x=i, // Store the length of the current sub-list.
                                                                                                              memcpy(x+1,e,4*i); // Copy the data.
                                                                                                              }





                                                                                                              share|improve this answer





















                                                                                                              • 97 bytes
                                                                                                                – ceilingcat
                                                                                                                18 hours ago










                                                                                                              • @ceilingcat Thanks, will edit it in later when I get back onto a PC.
                                                                                                                – Rogem
                                                                                                                5 hours ago














                                                                                                              2












                                                                                                              2








                                                                                                              2







                                                                                                              C (gcc), 102 bytes





                                                                                                              Pretty long, as C quite obviously isn't well-suited to manipulating lists of lists.



                                                                                                              Takes in a pointer to the first element of the input array, the length of the array, and a pointer to the variable in which the pointer to output will be stored. Produces a list of lists such that the first integer in the linear array stores the number of sub-lists. Sub-lists start with the number of elements, and are stored in memory in a contiguous manner.



                                                                                                              p(r,e,f,i,x)int*e,**r,*x;{x=*r=malloc(++f*-~f+2<<1);*x++=f;for(i=0;i<f;x+=++i)*x=i,memcpy(x+1,e,4*i);}


                                                                                                              Try it online!



                                                                                                              Degolf



                                                                                                              p(r,e,f,i,x) int*e,**r,*x; { // Declare function p. e is the input array, 
                                                                                                              // r is a pointer to the variable that will store output,
                                                                                                              // and x is a local iterator for r.
                                                                                                              x=*r=malloc(++f*-~f+2<<1);// Allocate 2*(n+1)*(n+2)+4 bytes of memory,
                                                                                                              // and store pointers in r and x.
                                                                                                              *x++=f; // Store the number of arrays in the first variable (n+1)
                                                                                                              for(i=0;i<f;x+=++i) // Iterate from 0 to f; x is incremented by i+1 every loop.
                                                                                                              *x=i, // Store the length of the current sub-list.
                                                                                                              memcpy(x+1,e,4*i); // Copy the data.
                                                                                                              }





                                                                                                              share|improve this answer













                                                                                                              C (gcc), 102 bytes





                                                                                                              Pretty long, as C quite obviously isn't well-suited to manipulating lists of lists.



                                                                                                              Takes in a pointer to the first element of the input array, the length of the array, and a pointer to the variable in which the pointer to output will be stored. Produces a list of lists such that the first integer in the linear array stores the number of sub-lists. Sub-lists start with the number of elements, and are stored in memory in a contiguous manner.



                                                                                                              p(r,e,f,i,x)int*e,**r,*x;{x=*r=malloc(++f*-~f+2<<1);*x++=f;for(i=0;i<f;x+=++i)*x=i,memcpy(x+1,e,4*i);}


                                                                                                              Try it online!



                                                                                                              Degolf



                                                                                                              p(r,e,f,i,x) int*e,**r,*x; { // Declare function p. e is the input array, 
                                                                                                              // r is a pointer to the variable that will store output,
                                                                                                              // and x is a local iterator for r.
                                                                                                              x=*r=malloc(++f*-~f+2<<1);// Allocate 2*(n+1)*(n+2)+4 bytes of memory,
                                                                                                              // and store pointers in r and x.
                                                                                                              *x++=f; // Store the number of arrays in the first variable (n+1)
                                                                                                              for(i=0;i<f;x+=++i) // Iterate from 0 to f; x is incremented by i+1 every loop.
                                                                                                              *x=i, // Store the length of the current sub-list.
                                                                                                              memcpy(x+1,e,4*i); // Copy the data.
                                                                                                              }






                                                                                                              share|improve this answer












                                                                                                              share|improve this answer



                                                                                                              share|improve this answer










                                                                                                              answered Dec 9 '18 at 12:02









                                                                                                              Rogem

                                                                                                              68112




                                                                                                              68112












                                                                                                              • 97 bytes
                                                                                                                – ceilingcat
                                                                                                                18 hours ago










                                                                                                              • @ceilingcat Thanks, will edit it in later when I get back onto a PC.
                                                                                                                – Rogem
                                                                                                                5 hours ago


















                                                                                                              • 97 bytes
                                                                                                                – ceilingcat
                                                                                                                18 hours ago










                                                                                                              • @ceilingcat Thanks, will edit it in later when I get back onto a PC.
                                                                                                                – Rogem
                                                                                                                5 hours ago
















                                                                                                              97 bytes
                                                                                                              – ceilingcat
                                                                                                              18 hours ago




                                                                                                              97 bytes
                                                                                                              – ceilingcat
                                                                                                              18 hours ago












                                                                                                              @ceilingcat Thanks, will edit it in later when I get back onto a PC.
                                                                                                              – Rogem
                                                                                                              5 hours ago




                                                                                                              @ceilingcat Thanks, will edit it in later when I get back onto a PC.
                                                                                                              – Rogem
                                                                                                              5 hours ago











                                                                                                              2















                                                                                                              F# (Mono), 45 bytes





                                                                                                              fun x->List.mapi(fun i y->List.take i x)x@[x]


                                                                                                              Try it online!



                                                                                                              I am not totally sure if this is valid, but it seems like it follows the same "anonymous lambda" syntax that I've seem used in several other languages.






                                                                                                              share|improve this answer




























                                                                                                                2















                                                                                                                F# (Mono), 45 bytes





                                                                                                                fun x->List.mapi(fun i y->List.take i x)x@[x]


                                                                                                                Try it online!



                                                                                                                I am not totally sure if this is valid, but it seems like it follows the same "anonymous lambda" syntax that I've seem used in several other languages.






                                                                                                                share|improve this answer


























                                                                                                                  2












                                                                                                                  2








                                                                                                                  2







                                                                                                                  F# (Mono), 45 bytes





                                                                                                                  fun x->List.mapi(fun i y->List.take i x)x@[x]


                                                                                                                  Try it online!



                                                                                                                  I am not totally sure if this is valid, but it seems like it follows the same "anonymous lambda" syntax that I've seem used in several other languages.






                                                                                                                  share|improve this answer















                                                                                                                  F# (Mono), 45 bytes





                                                                                                                  fun x->List.mapi(fun i y->List.take i x)x@[x]


                                                                                                                  Try it online!



                                                                                                                  I am not totally sure if this is valid, but it seems like it follows the same "anonymous lambda" syntax that I've seem used in several other languages.







                                                                                                                  share|improve this answer














                                                                                                                  share|improve this answer



                                                                                                                  share|improve this answer








                                                                                                                  edited Dec 9 '18 at 20:27

























                                                                                                                  answered Dec 9 '18 at 11:02









                                                                                                                  dana

                                                                                                                  45135




                                                                                                                  45135























                                                                                                                      2















                                                                                                                      Java 8+, 86 77 bytes



                                                                                                                      -9 bytes thanks to Kevin Cruijssen (getting rid of the import)!





                                                                                                                      x->java.util.stream.IntStream.range(0,x.size()+1).mapToObj(t->x.subList(0,t))


                                                                                                                      Try it online!



                                                                                                                      Alternative, 65 bytes



                                                                                                                      The following will print the results to stdout (due to Olivier Grégoire):



                                                                                                                      x->{for(int i=0;i<=x.size();)System.out.print(x.subList(0,i++));}


                                                                                                                      Try it online






                                                                                                                      share|improve this answer























                                                                                                                      • You can golf it to 77 bytes by just using java.util.stream.IntStream directly and drop the import.
                                                                                                                        – Kevin Cruijssen
                                                                                                                        Dec 10 '18 at 7:44










                                                                                                                      • @KevinCruijssen: Oh thanks! I didn't even know that this was possible, that's certainly helpful (at least for golfing purposes).
                                                                                                                        – BMO
                                                                                                                        Dec 10 '18 at 14:19










                                                                                                                      • x->{for(int i=0;i<=x.size();)System.out.println(x.subList(0,i++));} (67 bytes). This prints instead of using streams. Printing is usually the shortest way to output complex structures.
                                                                                                                        – Olivier Grégoire
                                                                                                                        Dec 10 '18 at 17:01












                                                                                                                      • @OlivierGrégoire: In that case you can probably get away with System.out.print since the output is still unambiguous.
                                                                                                                        – BMO
                                                                                                                        Dec 10 '18 at 17:55










                                                                                                                      • @BMO Indeed, that would be possible!
                                                                                                                        – Olivier Grégoire
                                                                                                                        Dec 10 '18 at 23:28
















                                                                                                                      2















                                                                                                                      Java 8+, 86 77 bytes



                                                                                                                      -9 bytes thanks to Kevin Cruijssen (getting rid of the import)!





                                                                                                                      x->java.util.stream.IntStream.range(0,x.size()+1).mapToObj(t->x.subList(0,t))


                                                                                                                      Try it online!



                                                                                                                      Alternative, 65 bytes



                                                                                                                      The following will print the results to stdout (due to Olivier Grégoire):



                                                                                                                      x->{for(int i=0;i<=x.size();)System.out.print(x.subList(0,i++));}


                                                                                                                      Try it online






                                                                                                                      share|improve this answer























                                                                                                                      • You can golf it to 77 bytes by just using java.util.stream.IntStream directly and drop the import.
                                                                                                                        – Kevin Cruijssen
                                                                                                                        Dec 10 '18 at 7:44










                                                                                                                      • @KevinCruijssen: Oh thanks! I didn't even know that this was possible, that's certainly helpful (at least for golfing purposes).
                                                                                                                        – BMO
                                                                                                                        Dec 10 '18 at 14:19










                                                                                                                      • x->{for(int i=0;i<=x.size();)System.out.println(x.subList(0,i++));} (67 bytes). This prints instead of using streams. Printing is usually the shortest way to output complex structures.
                                                                                                                        – Olivier Grégoire
                                                                                                                        Dec 10 '18 at 17:01












                                                                                                                      • @OlivierGrégoire: In that case you can probably get away with System.out.print since the output is still unambiguous.
                                                                                                                        – BMO
                                                                                                                        Dec 10 '18 at 17:55










                                                                                                                      • @BMO Indeed, that would be possible!
                                                                                                                        – Olivier Grégoire
                                                                                                                        Dec 10 '18 at 23:28














                                                                                                                      2












                                                                                                                      2








                                                                                                                      2







                                                                                                                      Java 8+, 86 77 bytes



                                                                                                                      -9 bytes thanks to Kevin Cruijssen (getting rid of the import)!





                                                                                                                      x->java.util.stream.IntStream.range(0,x.size()+1).mapToObj(t->x.subList(0,t))


                                                                                                                      Try it online!



                                                                                                                      Alternative, 65 bytes



                                                                                                                      The following will print the results to stdout (due to Olivier Grégoire):



                                                                                                                      x->{for(int i=0;i<=x.size();)System.out.print(x.subList(0,i++));}


                                                                                                                      Try it online






                                                                                                                      share|improve this answer















                                                                                                                      Java 8+, 86 77 bytes



                                                                                                                      -9 bytes thanks to Kevin Cruijssen (getting rid of the import)!





                                                                                                                      x->java.util.stream.IntStream.range(0,x.size()+1).mapToObj(t->x.subList(0,t))


                                                                                                                      Try it online!



                                                                                                                      Alternative, 65 bytes



                                                                                                                      The following will print the results to stdout (due to Olivier Grégoire):



                                                                                                                      x->{for(int i=0;i<=x.size();)System.out.print(x.subList(0,i++));}


                                                                                                                      Try it online







                                                                                                                      share|improve this answer














                                                                                                                      share|improve this answer



                                                                                                                      share|improve this answer








                                                                                                                      edited Dec 10 '18 at 17:54

























                                                                                                                      answered Dec 8 '18 at 0:22









                                                                                                                      BMO

                                                                                                                      11.4k22186




                                                                                                                      11.4k22186












                                                                                                                      • You can golf it to 77 bytes by just using java.util.stream.IntStream directly and drop the import.
                                                                                                                        – Kevin Cruijssen
                                                                                                                        Dec 10 '18 at 7:44










                                                                                                                      • @KevinCruijssen: Oh thanks! I didn't even know that this was possible, that's certainly helpful (at least for golfing purposes).
                                                                                                                        – BMO
                                                                                                                        Dec 10 '18 at 14:19










                                                                                                                      • x->{for(int i=0;i<=x.size();)System.out.println(x.subList(0,i++));} (67 bytes). This prints instead of using streams. Printing is usually the shortest way to output complex structures.
                                                                                                                        – Olivier Grégoire
                                                                                                                        Dec 10 '18 at 17:01












                                                                                                                      • @OlivierGrégoire: In that case you can probably get away with System.out.print since the output is still unambiguous.
                                                                                                                        – BMO
                                                                                                                        Dec 10 '18 at 17:55










                                                                                                                      • @BMO Indeed, that would be possible!
                                                                                                                        – Olivier Grégoire
                                                                                                                        Dec 10 '18 at 23:28


















                                                                                                                      • You can golf it to 77 bytes by just using java.util.stream.IntStream directly and drop the import.
                                                                                                                        – Kevin Cruijssen
                                                                                                                        Dec 10 '18 at 7:44










                                                                                                                      • @KevinCruijssen: Oh thanks! I didn't even know that this was possible, that's certainly helpful (at least for golfing purposes).
                                                                                                                        – BMO
                                                                                                                        Dec 10 '18 at 14:19










                                                                                                                      • x->{for(int i=0;i<=x.size();)System.out.println(x.subList(0,i++));} (67 bytes). This prints instead of using streams. Printing is usually the shortest way to output complex structures.
                                                                                                                        – Olivier Grégoire
                                                                                                                        Dec 10 '18 at 17:01












                                                                                                                      • @OlivierGrégoire: In that case you can probably get away with System.out.print since the output is still unambiguous.
                                                                                                                        – BMO
                                                                                                                        Dec 10 '18 at 17:55










                                                                                                                      • @BMO Indeed, that would be possible!
                                                                                                                        – Olivier Grégoire
                                                                                                                        Dec 10 '18 at 23:28
















                                                                                                                      You can golf it to 77 bytes by just using java.util.stream.IntStream directly and drop the import.
                                                                                                                      – Kevin Cruijssen
                                                                                                                      Dec 10 '18 at 7:44




                                                                                                                      You can golf it to 77 bytes by just using java.util.stream.IntStream directly and drop the import.
                                                                                                                      – Kevin Cruijssen
                                                                                                                      Dec 10 '18 at 7:44












                                                                                                                      @KevinCruijssen: Oh thanks! I didn't even know that this was possible, that's certainly helpful (at least for golfing purposes).
                                                                                                                      – BMO
                                                                                                                      Dec 10 '18 at 14:19




                                                                                                                      @KevinCruijssen: Oh thanks! I didn't even know that this was possible, that's certainly helpful (at least for golfing purposes).
                                                                                                                      – BMO
                                                                                                                      Dec 10 '18 at 14:19












                                                                                                                      x->{for(int i=0;i<=x.size();)System.out.println(x.subList(0,i++));} (67 bytes). This prints instead of using streams. Printing is usually the shortest way to output complex structures.
                                                                                                                      – Olivier Grégoire
                                                                                                                      Dec 10 '18 at 17:01






                                                                                                                      x->{for(int i=0;i<=x.size();)System.out.println(x.subList(0,i++));} (67 bytes). This prints instead of using streams. Printing is usually the shortest way to output complex structures.
                                                                                                                      – Olivier Grégoire
                                                                                                                      Dec 10 '18 at 17:01














                                                                                                                      @OlivierGrégoire: In that case you can probably get away with System.out.print since the output is still unambiguous.
                                                                                                                      – BMO
                                                                                                                      Dec 10 '18 at 17:55




                                                                                                                      @OlivierGrégoire: In that case you can probably get away with System.out.print since the output is still unambiguous.
                                                                                                                      – BMO
                                                                                                                      Dec 10 '18 at 17:55












                                                                                                                      @BMO Indeed, that would be possible!
                                                                                                                      – Olivier Grégoire
                                                                                                                      Dec 10 '18 at 23:28




                                                                                                                      @BMO Indeed, that would be possible!
                                                                                                                      – Olivier Grégoire
                                                                                                                      Dec 10 '18 at 23:28











                                                                                                                      2















                                                                                                                      Ruby, 31 29 bytes





                                                                                                                      ->a{[a*i=0]+a.map{a[0,i+=1]}}


                                                                                                                      Try it online!



                                                                                                                      Explanation:



                                                                                                                      ->a{             # take array input a
                                                                                                                      [a*i=0]+ # set i to 0 and add whatever comes next to [] (a*0 == )
                                                                                                                      a.map{ # for every element in a (basically do a.length times)
                                                                                                                      a[0,i+=1] # increment i and return the first i-1 elements of a to map
                                                                                                                      }
                                                                                                                      }





                                                                                                                      share|improve this answer




























                                                                                                                        2















                                                                                                                        Ruby, 31 29 bytes





                                                                                                                        ->a{[a*i=0]+a.map{a[0,i+=1]}}


                                                                                                                        Try it online!



                                                                                                                        Explanation:



                                                                                                                        ->a{             # take array input a
                                                                                                                        [a*i=0]+ # set i to 0 and add whatever comes next to [] (a*0 == )
                                                                                                                        a.map{ # for every element in a (basically do a.length times)
                                                                                                                        a[0,i+=1] # increment i and return the first i-1 elements of a to map
                                                                                                                        }
                                                                                                                        }





                                                                                                                        share|improve this answer


























                                                                                                                          2












                                                                                                                          2








                                                                                                                          2







                                                                                                                          Ruby, 31 29 bytes





                                                                                                                          ->a{[a*i=0]+a.map{a[0,i+=1]}}


                                                                                                                          Try it online!



                                                                                                                          Explanation:



                                                                                                                          ->a{             # take array input a
                                                                                                                          [a*i=0]+ # set i to 0 and add whatever comes next to [] (a*0 == )
                                                                                                                          a.map{ # for every element in a (basically do a.length times)
                                                                                                                          a[0,i+=1] # increment i and return the first i-1 elements of a to map
                                                                                                                          }
                                                                                                                          }





                                                                                                                          share|improve this answer















                                                                                                                          Ruby, 31 29 bytes





                                                                                                                          ->a{[a*i=0]+a.map{a[0,i+=1]}}


                                                                                                                          Try it online!



                                                                                                                          Explanation:



                                                                                                                          ->a{             # take array input a
                                                                                                                          [a*i=0]+ # set i to 0 and add whatever comes next to [] (a*0 == )
                                                                                                                          a.map{ # for every element in a (basically do a.length times)
                                                                                                                          a[0,i+=1] # increment i and return the first i-1 elements of a to map
                                                                                                                          }
                                                                                                                          }






                                                                                                                          share|improve this answer














                                                                                                                          share|improve this answer



                                                                                                                          share|improve this answer








                                                                                                                          edited Dec 11 '18 at 11:52

























                                                                                                                          answered Dec 9 '18 at 11:47









                                                                                                                          Asone Tuhid

                                                                                                                          1,56421




                                                                                                                          1,56421























                                                                                                                              1















                                                                                                                              05AB1E, 3 bytes



                                                                                                                              η¯š


                                                                                                                              Explanation:



                                                                                                                              η    Prefixes
                                                                                                                              š Prepend
                                                                                                                              ¯ Global array (empty by default)


                                                                                                                              Try it online!






                                                                                                                              share|improve this answer


























                                                                                                                                1















                                                                                                                                05AB1E, 3 bytes



                                                                                                                                η¯š


                                                                                                                                Explanation:



                                                                                                                                η    Prefixes
                                                                                                                                š Prepend
                                                                                                                                ¯ Global array (empty by default)


                                                                                                                                Try it online!






                                                                                                                                share|improve this answer
























                                                                                                                                  1












                                                                                                                                  1








                                                                                                                                  1







                                                                                                                                  05AB1E, 3 bytes



                                                                                                                                  η¯š


                                                                                                                                  Explanation:



                                                                                                                                  η    Prefixes
                                                                                                                                  š Prepend
                                                                                                                                  ¯ Global array (empty by default)


                                                                                                                                  Try it online!






                                                                                                                                  share|improve this answer













                                                                                                                                  05AB1E, 3 bytes



                                                                                                                                  η¯š


                                                                                                                                  Explanation:



                                                                                                                                  η    Prefixes
                                                                                                                                  š Prepend
                                                                                                                                  ¯ Global array (empty by default)


                                                                                                                                  Try it online!







                                                                                                                                  share|improve this answer












                                                                                                                                  share|improve this answer



                                                                                                                                  share|improve this answer










                                                                                                                                  answered Dec 7 '18 at 20:43









                                                                                                                                  Okx

                                                                                                                                  12.6k127102




                                                                                                                                  12.6k127102























                                                                                                                                      1















                                                                                                                                      RAD, 7 bytes



                                                                                                                                      (⊂⍬),,


                                                                                                                                      Try it online!



                                                                                                                                      This also works in Dyalog APL as a function.



                                                                                                                                      How?



                                                                                                                                      This works the same for both APL and RAD, given their close relation.





                                                                                                                                      • (⊂⍬) the empty array


                                                                                                                                      • , prepended to


                                                                                                                                      • , the prefixes (which exclude the empty array.)






                                                                                                                                      share|improve this answer




























                                                                                                                                        1















                                                                                                                                        RAD, 7 bytes



                                                                                                                                        (⊂⍬),,


                                                                                                                                        Try it online!



                                                                                                                                        This also works in Dyalog APL as a function.



                                                                                                                                        How?



                                                                                                                                        This works the same for both APL and RAD, given their close relation.





                                                                                                                                        • (⊂⍬) the empty array


                                                                                                                                        • , prepended to


                                                                                                                                        • , the prefixes (which exclude the empty array.)






                                                                                                                                        share|improve this answer


























                                                                                                                                          1












                                                                                                                                          1








                                                                                                                                          1







                                                                                                                                          RAD, 7 bytes



                                                                                                                                          (⊂⍬),,


                                                                                                                                          Try it online!



                                                                                                                                          This also works in Dyalog APL as a function.



                                                                                                                                          How?



                                                                                                                                          This works the same for both APL and RAD, given their close relation.





                                                                                                                                          • (⊂⍬) the empty array


                                                                                                                                          • , prepended to


                                                                                                                                          • , the prefixes (which exclude the empty array.)






                                                                                                                                          share|improve this answer















                                                                                                                                          RAD, 7 bytes



                                                                                                                                          (⊂⍬),,


                                                                                                                                          Try it online!



                                                                                                                                          This also works in Dyalog APL as a function.



                                                                                                                                          How?



                                                                                                                                          This works the same for both APL and RAD, given their close relation.





                                                                                                                                          • (⊂⍬) the empty array


                                                                                                                                          • , prepended to


                                                                                                                                          • , the prefixes (which exclude the empty array.)







                                                                                                                                          share|improve this answer














                                                                                                                                          share|improve this answer



                                                                                                                                          share|improve this answer








                                                                                                                                          edited Dec 7 '18 at 21:01

























                                                                                                                                          answered Dec 7 '18 at 20:55









                                                                                                                                          Zacharý

                                                                                                                                          5,19511035




                                                                                                                                          5,19511035






















                                                                                                                                              1 2
                                                                                                                                              3
                                                                                                                                              next

















                                                                                                                                              draft saved

                                                                                                                                              draft discarded




















































                                                                                                                                              If this is an answer to a challenge…




                                                                                                                                              • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                                                                                                                              • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                                                                                                                                Explanations of your answer make it more interesting to read and are very much encouraged.


                                                                                                                                              • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.



                                                                                                                                              More generally…




                                                                                                                                              • …Please make sure to answer the question and provide sufficient detail.


                                                                                                                                              • …Avoid asking for help, clarification or responding to other answers (use comments instead).






                                                                                                                                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                                                                                                              Please pay close attention to the following guidance:


                                                                                                                                              • Please be sure to answer the question. Provide details and share your research!

                                                                                                                                              But avoid



                                                                                                                                              • Asking for help, clarification, or responding to other answers.

                                                                                                                                              • Making statements based on opinion; back them up with references or personal experience.


                                                                                                                                              To learn more, see our tips on writing great answers.




                                                                                                                                              draft saved


                                                                                                                                              draft discarded














                                                                                                                                              StackExchange.ready(
                                                                                                                                              function () {
                                                                                                                                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f177146%2fp-pr-pre-pref-prefi-prefix-prefixe-prefixes%23new-answer', 'question_page');
                                                                                                                                              }
                                                                                                                                              );

                                                                                                                                              Post as a guest















                                                                                                                                              Required, but never shown





















































                                                                                                                                              Required, but never shown














                                                                                                                                              Required, but never shown












                                                                                                                                              Required, but never shown







                                                                                                                                              Required, but never shown

































                                                                                                                                              Required, but never shown














                                                                                                                                              Required, but never shown












                                                                                                                                              Required, but never shown







                                                                                                                                              Required, but never shown







                                                                                                                                              Popular posts from this blog

                                                                                                                                              Terni

                                                                                                                                              A new problem with tex4ht and tikz

                                                                                                                                              Sun Ra