7 kyu

Parts of a list

589 of 17,739g964

Description:

Write a function partlist that gives all the ways to divide a list (an array) of at least two elements into two non-empty parts.

  • Each two non empty parts will be in a pair (or an array for languages without tuples or a structin C - C: see Examples test Cases - )
  • Each part will be in a string
  • Elements of a pair must be in the same order as in the original array.

Examples of returns in different languages:

a = ["az", "toto", "picaro", "zone", "kiwi"] -->
[["az", "toto picaro zone kiwi"], ["az toto", "picaro zone kiwi"], ["az toto picaro", "zone kiwi"], ["az toto picaro zone", "kiwi"]] 
or
 a = {"az", "toto", "picaro", "zone", "kiwi"} -->
{{"az", "toto picaro zone kiwi"}, {"az toto", "picaro zone kiwi"}, {"az toto picaro", "zone kiwi"}, {"az toto picaro zone", "kiwi"}}
or
a = ["az", "toto", "picaro", "zone", "kiwi"] -->
[("az", "toto picaro zone kiwi"), ("az toto", "picaro zone kiwi"), ("az toto picaro", "zone kiwi"), ("az toto picaro zone", "kiwi")]
or 
a = [|"az", "toto", "picaro", "zone", "kiwi"|] -->
[("az", "toto picaro zone kiwi"), ("az toto", "picaro zone kiwi"), ("az toto picaro", "zone kiwi"), ("az toto picaro zone", "kiwi")]
or
a = ["az", "toto", "picaro", "zone", "kiwi"] -->
"(az, toto picaro zone kiwi)(az toto, picaro zone kiwi)(az toto picaro, zone kiwi)(az toto picaro zone, kiwi)"

Note

You can see other examples for each language in "Your test cases"

Arrays
Lists
Data Structures
Algorithms

More By Author:

Check out these other kata created by g964

Stats:

CreatedMar 24, 2016
PublishedMar 24, 2016
Warriors Trained49501
Total Skips9888
Total Code Submissions57786
Total Times Completed17739
Ruby Completions589
Python Completions4501
JavaScript Completions5465
CoffeeScript Completions23
Haskell Completions290
Clojure Completions165
Java Completions1319
C# Completions553
Elixir Completions250
TypeScript Completions486
C++ Completions960
PHP Completions823
Crystal Completions19
F# Completions94
C Completions196
OCaml Completions47
Shell Completions123
Kotlin Completions485
Julia Completions40
PowerShell Completions78
Go Completions751
Nim Completions20
Rust Completions496
Reason Completions12
Racket Completions31
Scala Completions131
VB Completions44
Dart Completions445
Perl Completions21
D Completions10
Erlang Completions17
Prolog Completions11
Total Stars506
% of votes with a positive feedback rating90% of 2193
Total "Very Satisfied" Votes1787
Total "Somewhat Satisfied" Votes358
Total "Not Satisfied" Votes48
Ad
Contributors
  • g964 Avatar
  • jcsahnwaldt Avatar
  • NaMe613 Avatar
  • imjasonmiller Avatar
  • kazk Avatar
  • Blind4Basics Avatar
  • Voile Avatar
  • monadius Avatar
  • hobovsky Avatar
  • xavierguihot Avatar
  • user8436785 Avatar
  • Just4FunCoder Avatar
  • KayleighWasTaken Avatar
Ad