mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-14 16:47:55 +00:00
Docs: Update benchmark results
This commit is contained in:
29
tests/2_convex_hull/outputs/anthropic_claude-sonnet-4.5.js
Normal file
29
tests/2_convex_hull/outputs/anthropic_claude-sonnet-4.5.js
Normal file
@@ -0,0 +1,29 @@
|
||||
async function findConvexHull(points) {
|
||||
const { sortBy, uniqWith, isEqual } = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.min.js');
|
||||
|
||||
if (points.length < 3) return points;
|
||||
|
||||
const sorted = sortBy(uniqWith(points, isEqual), ['x', 'y']);
|
||||
|
||||
if (sorted.length < 3) return sorted;
|
||||
|
||||
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
|
||||
|
||||
const buildHull = (pts) => {
|
||||
const hull = [];
|
||||
for (const p of pts) {
|
||||
while (hull.length >= 2 && cross(hull[hull.length - 2], hull[hull.length - 1], p) <= 0) {
|
||||
hull.pop();
|
||||
}
|
||||
hull.push(p);
|
||||
}
|
||||
hull.pop();
|
||||
return hull;
|
||||
};
|
||||
|
||||
const lower = buildHull(sorted);
|
||||
const upper = buildHull([...sorted].reverse());
|
||||
|
||||
return [...lower, ...upper].reverse();
|
||||
}
|
||||
export default findConvexHull;
|
||||
Reference in New Issue
Block a user