#!/usr/bin/env setl
--
-- Find the missing permutation in SETL.
--
-- From http://rosettacode.org/wiki/Find_the_missing_permutation
-- """
-- These are all of the permutations of the symbols A, B, C and D,
-- except for one that's not listed. Find that missing permutation.
-- """
--
--
-- This SETL program was created by Hakan Kjellerstrand (hakank@bonetmail.com)
-- Also see my SETL page: http://www.hakank.org/setl/
--
p1 := {
"ABCD","CABD","ACDB","DACB","BCDA","ACBD",
"ADCB","CDAB","DABC","BCAD","CADB","CDBA",
"CBAD","ABDC","ADBC","BDCA","DCBA","BACD",
"BADC","BDAC","CBDA","DBCA","DCAB"};
print( {join(pp,"") : pp in perms({"A","B","C","D"})} - p1);
-- another version
print([p : p in [join(pp,"") : pp in perms({"A","B","C","D"})] | p notin p1](1));
procedure perms(S);
if S = {} then
return {[]};
else
return { [a]+b : a in S, b in perms(S less a) };
end if;
end perms;