Skip to main content
Commonmark migration
Source Link

#JavaScript (ES6),  191  189 bytes

JavaScript (ES6),  191  189 bytes

Implements the Jarvis march (aka gift wrapping algorithm).

P=>(r=(g=p=>([X,Y]=P[p],Y*h-X*v)+(P.map(([x,y],i)=>q=(y-Y)*(P[q][0]-x)<(x-X)*(P[q][1]-y)?i:q,q=P[++p]?p:0,h=X,v=Y)|q?g(q):V*h-H*v))(v=h=0,([[H,V]]=P.sort(([x],[X])=>x-X)))/2)+(r%1&&r&1)/2|0

Try it online!

Or 170 bytes without the cumbersome rounding scheme.

#JavaScript (ES6),  191  189 bytes

Implements the Jarvis march (aka gift wrapping algorithm).

P=>(r=(g=p=>([X,Y]=P[p],Y*h-X*v)+(P.map(([x,y],i)=>q=(y-Y)*(P[q][0]-x)<(x-X)*(P[q][1]-y)?i:q,q=P[++p]?p:0,h=X,v=Y)|q?g(q):V*h-H*v))(v=h=0,([[H,V]]=P.sort(([x],[X])=>x-X)))/2)+(r%1&&r&1)/2|0

Try it online!

Or 170 bytes without the cumbersome rounding scheme.

JavaScript (ES6),  191  189 bytes

Implements the Jarvis march (aka gift wrapping algorithm).

P=>(r=(g=p=>([X,Y]=P[p],Y*h-X*v)+(P.map(([x,y],i)=>q=(y-Y)*(P[q][0]-x)<(x-X)*(P[q][1]-y)?i:q,q=P[++p]?p:0,h=X,v=Y)|q?g(q):V*h-H*v))(v=h=0,([[H,V]]=P.sort(([x],[X])=>x-X)))/2)+(r%1&&r&1)/2|0

Try it online!

Or 170 bytes without the cumbersome rounding scheme.

saved 2 bytes
Source Link
Arnauld
  • 194.2k
  • 20
  • 176
  • 639

#JavaScript (ES6), 191 191  189 bytes

Implements the Jarvis march (aka gift wrapping algorithm).

P=>(r=(g=p=>([X,Y]=P[p],Y*h-X*v)+(P.map(([x,y],i)=>q=(y-Y)*(P[q][0]-x)<(x-X)*(P[q][1]-y)?i:q,q=-~p%P.lengthq=P[++p]?p:0,h=X,v=Y)|q?g(q):V*h-H*v))(v=h=0,([[H,V]]=P.sort(([x],[X])=>x-X)))/2)+(r%1&&r&1)/2|0

Try it online!Try it online!

Or 172 bytes170 bytes without the cumbersome rounding scheme.

#JavaScript (ES6), 191 bytes

Implements the Jarvis march (aka gift wrapping algorithm).

P=>(r=(g=p=>([X,Y]=P[p],Y*h-X*v)+(P.map(([x,y],i)=>q=(y-Y)*(P[q][0]-x)<(x-X)*(P[q][1]-y)?i:q,q=-~p%P.length,h=X,v=Y)|q?g(q):V*h-H*v))(v=h=0,([[H,V]]=P.sort(([x],[X])=>x-X)))/2)+(r%1&&r&1)/2|0

Try it online!

Or 172 bytes without the cumbersome rounding scheme.

#JavaScript (ES6),  191  189 bytes

Implements the Jarvis march (aka gift wrapping algorithm).

P=>(r=(g=p=>([X,Y]=P[p],Y*h-X*v)+(P.map(([x,y],i)=>q=(y-Y)*(P[q][0]-x)<(x-X)*(P[q][1]-y)?i:q,q=P[++p]?p:0,h=X,v=Y)|q?g(q):V*h-H*v))(v=h=0,([[H,V]]=P.sort(([x],[X])=>x-X)))/2)+(r%1&&r&1)/2|0

Try it online!

Or 170 bytes without the cumbersome rounding scheme.

Source Link
Arnauld
  • 194.2k
  • 20
  • 176
  • 639

#JavaScript (ES6), 191 bytes

Implements the Jarvis march (aka gift wrapping algorithm).

P=>(r=(g=p=>([X,Y]=P[p],Y*h-X*v)+(P.map(([x,y],i)=>q=(y-Y)*(P[q][0]-x)<(x-X)*(P[q][1]-y)?i:q,q=-~p%P.length,h=X,v=Y)|q?g(q):V*h-H*v))(v=h=0,([[H,V]]=P.sort(([x],[X])=>x-X)))/2)+(r%1&&r&1)/2|0

Try it online!

Or 172 bytes without the cumbersome rounding scheme.