Mian-Chowla sequence: Difference between revisions
→{{header|JavaScript}}: Tidied.
Alextretyak (talk | contribs) (Added 11l) |
(→{{header|JavaScript}}: Tidied.) |
||
Line 935:
'use strict';
const main = () => {
const genMianChowla = mianChowlas();
console.log([
'Mian-Chowla terms 1-30:',
take(30
),
'\nMian-Chowla terms 91-100:',
(
drop(60
)
)
].join('\n') + '\n');
};
Line 971 ⟶ 975:
return true;
};
const x = until(valid
return [
sumList(mcs
.reduce(
(a, n) => (a.add(n), a),
Line 980 ⟶ 984:
mcs.concat(x),
x
];
};
// sumList :: [Int] -> Int -> [Int]
const sumList =
// Series so far -> additional term -> new sums
n => [2 * n].concat(xs.map(x => n + x
//
// drop :: Int -> [a] -> [a]
// drop :: Int -> Generator [a] -> Generator [a]
// drop :: Int -> String -> String
const drop =
xs => Infinity > length(xs) ? (
xs.slice(n)
) : (take(n
// 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 =>
// like cycle, repeat etc
.constructor.name ? (
xs.length
) : Infinity;
▲ xs
▲ // succ :: Int -> Int
// take :: Int -> [a] -> [a]
// take :: Int -> String -> String
const take =
// 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 =
};
// MAIN ---
Line 1,047 ⟶ 1,048:
Mian-Chowla terms 91-100:
22526,23291,23564,23881,24596,24768,25631,26037,26255,27219</pre>
=={{header|Julia}}==
|