Menu

#10 Subarrays

0.6.2
later
aditsu
2015-11-30
2014-09-02
Dennis
No

It would be useful to have an operator returning all (non-empty?) subarrays (as in subsets) of a given array.

Example:

[1 2 1]eS "returns [[1] [2] [1 2] [1 1] [1 2 1]] ";

Discussion

  • aditsu

    aditsu - 2015-04-17
    • status: open --> later
    • assigned_to: aditsu
     
  • Martin Büttner

    Martin Büttner - 2015-11-30

    Alternatively, getting all (non-unique) subsequences might be good too. The result for input [1 2 1] would be

    [[1] [2] [1] [1 2] [1 1] [2 1] [1 2 1]]
    

    I also considered all substrings, but I suppose that can be achieved reasonable well with few, like

    _,f{)ew~}
    

    Not particularly golfy, but certainly doable. In fact, getting all subarrays as in subsets can be done from there with :$_&, so getting an operator for subsequences might actually be more useful. I'm not sure how I'd implement that conveniently at the moment.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.