Department numbers: Difference between revisions

Content added Content deleted
(Add Draco)
m (→‎JS ES6: Tidied.)
Line 2,293: Line 2,293:
Briefly:
Briefly:
<lang JavaScript>(() => {
<lang JavaScript>(() => {
"use strict";


const
// concatMap :: (a -> [b]) -> [a] -> [b]
label = "(Police, Sanitation, Fire)",
const concatMap = (f, xs) => [].concat.apply([], xs.map(f));
solutions = [2, 4, 6]

.flatMap(
return '(Police, Sanitation, Fire)\n' +
concatMap(x =>
x => [1, 2, 3, 4, 5, 6, 7]
concatMap(y =>
.flatMap(
concatMap(z =>
y => [12 - (x + y)]
z !== y && 1 <= z && z <= 7 ? [
.flatMap(
z => z !== y && 1 <= z && z <= 7 ? [
[x, y, z]
[x, y, z]
] : [], [12 - (x + y)]
] : []
), [1, 2, 3, 4, 5, 6, 7]
)
), [2, 4, 6]
)
)
)
.map(JSON.stringify)
.map(JSON.stringify)
.join('\n');
.join("\n");

return `${label}\n${solutions}`;
})();</lang>
})();</lang>
{{Out}}
{{Out}}