Solve the no connection puzzle: Difference between revisions
m
→JS ES6: ( tidying )
Alpha bravo (talk | contribs) (Added AutoHotkey) |
m (→JS ES6: ( tidying )) |
||
Line 940:
'use strict';
// GENERIC FUNCTIONS ------------------------------------------------------
//
const
xs.length ? concatMap(x => concatMap(ys => [▼
// all :: (a -> Bool) -> [a] ->
const all = (f, xs) =>
permutations(delete_(x, xs))), xs) : [▼
[]▼
];▼
// concatMap :: (a -> [b]) -> [a] -> [b]
Line 980 ⟶ 977:
};
//
const
n > strText.length ? (▼
(cFiller.repeat(n) + strText)▼
.slice(-n)▼
) : strText;▼
//
const
▲ xs.length ? concatMap(x => concatMap(ys => [
[x].concat(ys)
],
▲ permutations(delete_(x, xs))), xs) : [
▲ []
▲ ];
// show :: a -> String▼
const show = x => JSON.stringify(x);▼
// unlines :: [String] -> String▼
const unlines = xs => xs.join('\n');▼
// until :: (a -> Bool) -> (a -> a) -> a -> a
Line 992 ⟶ 1,005:
return v;
};
// unwords :: [String] -> String▼
const unwords = xs => xs.join(' ');▼
// zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
Line 998 ⟶ 1,014:
return (xs.length <= ny ? xs : xs.slice(0, ny))
.map((x, i) => f(x, ys[i]));
};
▲ n > strText.length ? (
▲ (cFiller.repeat(n) + strText)
▲ .slice(-n)
▲ ) : strText;
// CONNECTION PUZZLE ------------------------------------------------------
▲ // show :: a -> String
▲ const show = x => JSON.stringify(x);
▲ // unwords :: [String] -> String
▲ const unwords = xs => xs.join(' ');
▲ // unlines :: [String] -> String
▲ const unlines = xs => xs.join('\n');
// universe :: [[Int]]
Line 1,034:
0
)];
// TEST -------------------------------------------------------------------
// [Int]
const [a, b, c, d, e, f, g, h] = firstSolution;
return unlines(
zipWith(
|