Mian-Chowla sequence: Difference between revisions

(Added 11l)
Line 935:
'use strict';
 
// succmain :: IntIO -> Int()
const main = () => {
 
const genMianChowla = mianChowlas();
console.log([
'Mian-Chowla terms 1-30:',
take(30, genMianChowla),(
xs genMianChowla
),
 
'\nMian-Chowla terms 91-100:',
(() => {
drop(60, )(genMianChowla);,
return take(10, genMianChowla);(
})() genMianChowla
)
)
].join('\n') + '\n');
};
Line 971 ⟶ 975:
return true;
};
const x = until(valid,)(x succ,=> 1 + x)(n);
return [
sumList(mcs, )(x)
.reduce(
(a, n) => (a.add(n), a),
Line 980 ⟶ 984:
mcs.concat(x),
x
];
 
};
 
// sumList :: [Int] -> Int -> [Int]
const sumList = (xs, n) =>
// Series so far -> additional term -> new sums
n => [2 * n].concat(xs.map(x => n + x, xs));
 
 
// GENERIC FUNCTIONS ---------------- GENERIC FUNCTIONS ----------------
 
// drop :: Int -> [a] -> [a]
// drop :: Int -> Generator [a] -> Generator [a]
// drop :: Int -> String -> String
const drop = (n, xs) =>
xs => Infinity > length(xs) ? (
xs.slice(n)
) : (take(n, )(xs), xs);
 
 
// Returns Infinity over objects without finite length.
// This enables zip and zipWith to choose the shorter
// argument when one is non-finite, like cycle, repeat etc
 
// length :: [a] -> Int
const length = xs =>
// Returns Infinity over objects without finite length.
(Array.isArray(xs) || 'string' === typeof xs) ? (
// length. This enables zip and zipWith to choose the shorter
// the shorter argument when one is non-finite, like cycle, repeat etc
// like cycle, repeat etc
'GeneratorFunction' !== xs.constructor.constructor.name ? (
.constructor.name ? (
xs.length
) : Infinity;
 
// map :: (a -> b) -> [a] -> [b]
const map = (f, xs) =>
(Array.isArray(xs) ? (
xs
) : xs.split('')).map(f);
 
// succ :: Int -> Int
const succ = x => 1 + x;
 
// take :: Int -> [a] -> [a]
// take :: Int -> String -> String
const take = (n, xs) =>
// The first n elements of a list,
'GeneratorFunction' !== xs.constructor.constructor.name ? (
// string of characters, or stream.
xs => 'GeneratorFunction' !== xs
.constructor.constructor.name ? (
xs.slice(0, n)
) : [].concat.apply([], Array.from({
Line 1,031 ⟶ 1,030:
return x.done ? [] : [x.value];
}));
 
 
// until :: (a -> Bool) -> (a -> a) -> a -> a
const until = (p, f, x) => {
let vf => x; => {
while (!p(v)) let v = f(v)x;
return while (!p(v)) v = f(v);
} return v;
};
 
// MAIN ---
Line 1,047 ⟶ 1,048:
 
Mian-Chowla terms 91-100:
22526,23291,23564,23881,24596,24768,25631,26037,26255,27219</pre>
 
[Finished in 0.184s]
 
(Executed in the Atom editor, using Run Script)</pre>
 
=={{header|Julia}}==
9,655

edits