@combinatorics/set-partition
Version:
Set partition algorithms for JavaScript
3 lines (2 loc) • 810 B
JavaScript
import{nth as t}from"@iterable-iterator/select";import{list as o}from"@iterable-iterator/list";import{map as e}from"@iterable-iterator/map";function*r(t){yield t;const o=[t];for(;;){const t=o.length;let e=o[t-1];yield e;for(let r=0;r<t;++r){const t=e+o[r];o[r]=e,e=t}o.push(e)}}const n=(o,e)=>t(r(o),e);function*i(t,r=t.length){if(0===r)yield[];else{const n=t[r-1];for(const c of i(t,r-1)){yield c.concat([[n]]);for(const t of c)yield o(e(o=>o===t?o.concat([n]):o,c))}}}const c=t=>n(1n,t),f=t=>i(o(t)),l=(t,o)=>{const e=new Set(t);for(const t of o){let o=!0;for(const r of t){if(o=!1,!e.has(r))return!1;e.delete(r)}if(o)return!1}return 0===e.size},s=()=>r(1n);export{n as _count,i as _enumerate,r as _sequence,c as count,f as enumerate,l as isPartition,s as sequence};
//# sourceMappingURL=index.modern.js.map