Aquest exercici explora la generació exhaustiva de permutacions.
Observació
Per tal que no importi l’ordre en que genereu la solució, els jocs de proves ordenen el resultat. Per a això, importeu la funció sort del mòdul Data.List encara que no la feu servir.
Puntuació
Cada funció puntua 20 punts.
Input
sort $ permutations1 ["pa", "amb", "oli"] sort $ permutations2 3 sort $ permutations3 ["pa", "amb", "oli"] sort $ permutations4 3 sort $ permutations5 "mpt" "aeo"
Output
[["amb","oli","pa"],["amb","pa","oli"],["oli","amb","pa"],["oli","pa","amb"],["pa","amb","oli"],["pa","oli","amb"]] [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] [["amb","amb","amb"],["amb","amb","oli"],["amb","amb","pa"],["amb","oli","amb"],["amb","oli","oli"],["amb","oli","pa"],["amb","pa","amb"],["amb","pa","oli"],["amb","pa","pa"],["oli","amb","amb"],["oli","amb","oli"],["oli","amb","pa"],["oli","oli","amb"],["oli","oli","oli"],["oli","oli","pa"],["oli","pa","amb"],["oli","pa","oli"],["oli","pa","pa"],["pa","amb","amb"],["pa","amb","oli"],["pa","amb","pa"],["pa","oli","amb"],["pa","oli","oli"],["pa","oli","pa"],["pa","pa","amb"],["pa","pa","oli"],["pa","pa","pa"]] [[1,1,1],[1,1,2],[1,1,3],[1,2,1],[1,2,2],[1,2,3],[1,3,1],[1,3,2],[1,3,3],[2,1,1],[2,1,2],[2,1,3],[2,2,1],[2,2,2],[2,2,3],[2,3,1],[2,3,2],[2,3,3],[3,1,1],[3,1,2],[3,1,3],[3,2,1],[3,2,2],[3,2,3],[3,3,1],[3,3,2],[3,3,3]] ["mapeto","mapote","matepo","matope","mepato","mepota","metapo","metopa","mopate","mopeta","motape","motepa","pameto","pamote","patemo","patome","pemato","pemota","petamo","petoma","pomate","pometa","potame","potema","tamepo","tamope","tapemo","tapome","temapo","temopa","tepamo","tepoma","tomape","tomepa","topame","topema"]