Mian-Chowla sequence: Difference between revisions

→‎{{header|JavaScript}}: Updated JS for parallel to functional version in Python
m (→‎Functional Python: (uncurried nextMC))
(→‎{{header|JavaScript}}: Updated JS for parallel to functional version in Python)
Line 650:
 
=={{header|JavaScript}}==
{{Trans|Python}} (SecondFunctional Python version)
<lang javascript>(() => {
'use strict';
Line 677:
while (true) {
yield x;
[sumSet, x] = mcSuccnextMC(sumSet, preds, x);
preds = preds.concatpush(x);
}
}
 
// mcSuccnextMC :: Set Int -> [Int] -> Int -> (Set Int, Int)
const mcSuccnextMC = (setSums, predsmcs, n) => {
// Set of sums -> Series up to n -> Next term in series
const valid = x => {
qfor = until(const m of mcs) {
if (setSums.has(x =>+ all(m)) return false;
v => !setSums.has(v),}
return sumList(preds, x)true;
),};
const x = until(valid, succ, n);
succ(n)
);
return [
foldlsumList(mcs, x)
(a, x) => (a.addreduce(x), a),
setSums(a, n) => (a.add(n), a),
sumList(preds, q)setSums
),
qx
];
 
};
 
// sumList :: [Int] -> Int -> [Int]
const sumList = (xs, n) =>
// Series so far -> additional term -> additionnew sums
[2 * n].concat(map(x => n + x, xs));
 
 
// GENERIC FUNCTIONS ----------------------------
 
// all :: (a -> Bool) -> [a] -> Bool
const all = (p, xs) => xs.every(p);
 
// drop :: Int -> [a] -> [a]
Line 723 ⟶ 719:
) : (take(n, xs), xs);
 
// foldl :: (a -> b -> a) -> a -> [b] -> a
const foldl = (f, a, xs) => xs.reduce(f, a);
 
// Returns Infinity over objects without finite length.
Line 774 ⟶ 768:
22526,23291,23564,23881,24596,24768,25631,26037,26255,27219
 
[Finished in 0.393s184s]
 
(Executed in the Atom editor, using Run Script)</pre>
9,655

edits