Magic squares of doubly even order: Difference between revisions
Content deleted Content added
→JS ES6: Updated primitives, tidied. |
m →JS ES6: Tidied the test section. |
||
Line 1,311:
const main = () =>
// Magic squares of orders 4, 8 and 12.
lines.concat(
transpose(lines)
map(compose(justifyRight(3)(' '), str))
.join('\n\n');▼
Line 1,394 ⟶ 1,393:
// flatten :: NestedList a -> [a]
const flatten = nest => nest.flat(Infinity);
// intercalate :: String -> [String] -> String
const intercalate = s =>
// isInt :: Int -> Bool
Line 1,427 ⟶ 1,430:
// str :: a -> String
const str = x => x.toString();
// sum :: [Num] -> Num
const sum = xs => xs.reduce((a, x) => a + x, 0);
// transpose :: [[a]] -> [[a]]
const transpose = xs =>
xs[0].map((_, iCol) => xs.map((row) => row[iCol]));
// unlines :: [String] -> String
const unlines = xs => xs.join('\n');
// zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
Line 1,438 ⟶ 1,447:
).map((x, i) => f(x)(ys[i]));
// MAIN ------------------------------------------------
return main();
})();</lang>
|