Hilbert curve: Difference between revisions
m
→JS Functional
(→JavaScript Functional: Updated primitives, tidied.) |
m (→JS Functional) |
||
Line 1,803:
// hilbertTree :: Dict Char [Char] -> Int -> Tree Char
const hilbertTree = rule => n => {
const go = tree => {
Boolean(tree.nest.length) ? (▼
return
) : rule[tree.root].map(
)
);
};▼
const seed = Node("a")([]);
return
take(n)(iterate(go)(seed)).slice(-1)[0]
) : seed;
Line 1,833 ⟶ 1,836:
return Boolean(t.nest.length) ? (
zipWith(go(r))(centres)(t.nest)
▲ )(t.nest)
.flat()
) : centres;
Line 1,843 ⟶ 1,844:
return go(d)([d, d], tree);
};
// svgFromPoints :: Int -> [(Int, Int)] -> String
Line 1,856 ⟶ 1,858:
// -------------------- TEST ---------------------
const main = () =>
a: ["d", "a", "a", "b"],▼
b: ["c", "b", "b", "a"],▼
c: ["b", "c", "c", "d"],▼
d: ["a", "d", "d", "c"]▼
▲ };
"a": [
[-1, 1],
Line 1,891 ⟶ 1,884:
[-1, -1]
]
})
▲ a: ["d", "a", "a", "b"],
▲ b: ["c", "b", "b", "a"],
▲ c: ["b", "c", "c", "d"],
};▼
▲ d: ["a", "d", "d", "c"]
▲ })(6);
Line 1,909 ⟶ 1,904:
nest: xs || []
});
// flip :: (a -> b -> c) -> b -> a -> c
const flip = op =>
// The binary function op with
// its arguments reversed.
1 !== op.length ? (
(a, b) => op(b, a)
) : (a => b => op(b)(a));
Line 1,924 ⟶ 1,928:
};
// length :: [a] -> Int
|