Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -0,0 +1,40 @@
|
|||
(function (strList) {
|
||||
|
||||
// [a] -> [[a]]
|
||||
function permutations(xs) {
|
||||
return xs.length ? (
|
||||
chain(xs, function (x) {
|
||||
return chain(permutations(deleted(x, xs)), function (ys) {
|
||||
return [[x].concat(ys).join('')];
|
||||
})
|
||||
})) : [[]];
|
||||
}
|
||||
|
||||
// Monadic bind/chain for lists
|
||||
// [a] -> (a -> b) -> [b]
|
||||
function chain(xs, f) {
|
||||
return [].concat.apply([], xs.map(f));
|
||||
}
|
||||
|
||||
// a -> [a] -> [a]
|
||||
function deleted(x, xs) {
|
||||
return xs.length ? (
|
||||
x === xs[0] ? xs.slice(1) : [xs[0]].concat(
|
||||
deleted(x, xs.slice(1))
|
||||
)
|
||||
) : [];
|
||||
}
|
||||
|
||||
// Provided subset
|
||||
var lstSubSet = strList.split('\n');
|
||||
|
||||
// Any missing permutations
|
||||
// (we can use fold/reduce, filter, or chain (concat map) here)
|
||||
return chain(permutations('ABCD'.split('')), function (x) {
|
||||
return lstSubSet.indexOf(x) === -1 ? [x] : [];
|
||||
});
|
||||
|
||||
})(
|
||||
'ABCD\nCABD\nACDB\nDACB\nBCDA\nACBD\nADCB\nCDAB\nDABC\nBCAD\nCADB\n\
|
||||
CDBA\nCBAD\nABDC\nADBC\nBDCA\nDCBA\nBACD\nBADC\nBDAC\nCBDA\nDBCA\nDCAB'
|
||||
);
|
||||
|
|
@ -0,0 +1 @@
|
|||
["DBAC"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue