Find the missing permutation: Difference between revisions

Content added Content deleted
(→‎{{header|Clojure}}: added alternate implementation; update library name in first impl)
(Added Erlang)
Line 406:
DBAC
DBAC</pre>
 
=={{header|Erlang}}==
The obvious method. It seems fast enough (no waiting time).
<lang Erlang>
-module( find_missing_permutation ).
 
-export( [difference/2, task/0] ).
 
difference( Permutate_this, Existing_permutations ) -> all_permutations( Permutate_this ) -- Existing_permutations.
 
task() -> difference( "ABCD", existing_permutations() ).
 
 
 
all_permutations( String ) -> [[A, B, C, D] || A <- String, B <- String, C <- String, D <- String, is_different([A, B, C, D])].
 
existing_permutations() -> ["ABCD", "CABD", "ACDB", "DACB", "BCDA", "ACBD", "ADCB", "CDAB", "DABC", "BCAD", "CADB", "CDBA", "CBAD", "ABDC", "ADBC", "BDCA", "DCBA", "BACD", "BADC", "BDAC", "CBDA", "DBCA", "DCAB"].
 
is_different( [_H] ) -> true;
is_different( [H | T] ) -> not lists:member(H, T) andalso is_different( T ).
</lang>
{{out}}
<pre>
6> find_the_missing_permutation:task().
["DBAC"]
</pre>
 
=={{header|Fortran}}==