Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
22
Task/Convex-hull/Jq/convex-hull-1.jq
Normal file
22
Task/Convex-hull/Jq/convex-hull-1.jq
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# ccw returns true if the three points make a counter-clockwise turn
|
||||
def ccw(a; b; c):
|
||||
a as [$ax, $ay]
|
||||
| b as [$bx, $by]
|
||||
| c as [$cx, $cy]
|
||||
| (($bx - $ax) * ($cy - $ay)) > (($by - $ay) * ($cx - $ax)) ;
|
||||
|
||||
def convexHull:
|
||||
if . == [] then []
|
||||
else sort as $pts
|
||||
# lower hull:
|
||||
| reduce $pts[] as $pt ([];
|
||||
until (length < 2 or ccw(.[-2]; .[-1]; $pt); .[:-1] )
|
||||
| . + [$pt] )
|
||||
# upper hull
|
||||
| (length + 1) as $t
|
||||
| reduce range($pts|length-2; -1; -1) as $i (.;
|
||||
$pts[$i] as $pt
|
||||
| until (length < $t or ccw(.[-2]; .[-1]; $pt); .[:-1] )
|
||||
| . + [$pt])
|
||||
| .[:-1]
|
||||
end ;
|
||||
8
Task/Convex-hull/Jq/convex-hull-2.jq
Normal file
8
Task/Convex-hull/Jq/convex-hull-2.jq
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
def pts: [
|
||||
[16, 3], [12, 17], [ 0, 6], [-4, -6], [16, 6],
|
||||
[16, -7], [16, -3], [17, -4], [ 5, 19], [19, -8],
|
||||
[ 3, 16], [12, 13], [ 3, -4], [17, 5], [-3, 15],
|
||||
[-3, -9], [ 0, 11], [-9, -3], [-4, -2], [12, 10]
|
||||
];
|
||||
|
||||
"Convex Hull: \(pts|convexHull)"
|
||||
Loading…
Add table
Add a link
Reference in a new issue