Leonardo numbers: Difference between revisions
→JS ES6: Tidied generator version, updated output.
(Added Rust solution) |
(→JS ES6: Tidied generator version, updated output.) |
||
Line 1,020:
while (true) {
yield x;
[x, y] = [y,
}
}
// main :: IO ()
const main = () => {
Line 1,030 ⟶ 1,031:
fibonacci = leo(0, 1, 0);
'First 25 Fibonacci
]);▼
▲ );
};
// indentWrapped :: [Int] -> String
▲ // FORMATTING -----------------------------------------
map(x => '\t' + x.join(','))(
▲ const twoLines = xs =>
)
▲ // GENERIC FUNCTIONS ----------------------------------
// ----------------- GENERIC FUNCTIONS -----------------
// chunksOf :: Int -> [a] -> [[a]]
const chunksOf =
xs => enumFromThenTo(0
xs.
(a, i) => a.concat([xs.slice(i, (n + i))]),
[]
);
// enumFromThenTo :: Int -> Int -> Int -> [Int]
const enumFromThenTo =
}, (_, i) => x1 + (d * i));
};
// map :: (a -> b) -> [a] -> [b]
const map =
// The list obtained by applying f
// to each element of xs.
// (The image of xs under f).
xs => [...xs].map(f);
//
const
x.toString();
// 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
xs.slice(0, n)
) : [].concat.apply([], Array.from({
Line 1,096 ⟶ 1,106:
{{Out}}
<pre>First 25 Leonardo numbers:
First 25 Fibonacci numbers:
=={{header|jq}}==
|