An array A of points in a 2D plane is given. These points represent a polygon: every two consecutive points describe an edge of the polygon, and there is an edge connecting the last point and the first point in the array.
A set of points in a 2D plane, whose boundary is a straight line, is called a semiplane. More precisely, any set of the form {(x, y) : ax + by ≥ c} is a semiplane. The semiplane contains its boundary.
A polygon is convex if and only if, no line segment between two points on the boundary ever goes outside the polygon.
For example, the polygon consisting of vertices whose Cartesian coordinates are consecutively:
(-1, 3) (3, 1) (0, -1) (-2, 1)is convex.
The convex hull of a finite set of points in a 2D plane is the smallest convex polygon that contains all points in this set. For example, the convex hull of a set consisting of seven points whose Cartesian coordinates are:
(-1, 3) (1, 2) (3, 1) (1, 1) (0, -1) (-2, 1) (-1, 2)is a polygon that has five vertices. When traversed clockwise, its vertices are:
(-1, 3) (1, 2) (3, 1) (0, -1) (-2, 1)If a polygon is concave (that is, it is not convex), it has a vertex which does not lie on its convex hull border. Your assignment is to find such a vertex.
Assume that the following declarations are given:
// Point2D obj is an Object with attributes // obj.x - type: int // obj.y - type: int
Write a function:
function solution(A);
that, given a non-empty array A consisting of N elements describing a polygon, returns −1 if the polygon is convex. Otherwise, the function should return the index of any point that doesn't belong to the convex hull border. Note that consecutive edges of the polygon may be collinear (that is, the polygon might have 180−degrees angles).
To access the coordinates of the K-th point (where 0 ≤ K < N), use the following syntax:
- A[K].x to access the x-coordinate,
- A[K].y to access the y-coordinate.
For example, given array A such that:
A[0].x = -1 A[0].y = 3 A[1].x = 1 A[1].y = 2 A[2].x = 3 A[2].y = 1 A[3].x = 0 A[3].y = -1 A[4].x = -2 A[4].y = 1the function should return −1, as explained in the example above.
However, given array A such that:
A[0].x = -1 A[0].y = 3 A[1].x = 1 A[1].y = 2 A[2].x = 1 A[2].y = 1 A[3].x = 3 A[3].y = 1 A[4].x = 0 A[4].y = -1 A[5].x = -2 A[5].y = 1 A[6].x = -1 A[6].y = 2the function should return either 2 or 6. These are the indices of the polygon lying strictly in its convex hull (that is, not on the convex hull border).
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [3..10,000];
- the coordinates of each point in array A are integers within the range [−1,000,000,000..1,000,000,000];
- no two edges of the polygon A intersect, other than meeting at their endpoints;
- array A does not contain duplicate points.
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x - P.x, y: Q.y - P.y}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.x - Q.y - P.y}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator =
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = math.sqrt(v1.x)
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = math.sqrt(v1.x*v1.x + v1.y*v1.y)
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = math.sqrt(v1.x * v1.x + v1.y * v1.y);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = math.sqrt(v2.x * v2.x + v2.y * v2.y);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator /
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if qoutient < -1) {
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient )
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
angle
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = math
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = ath
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos()
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y )
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y >)
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s'
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {'l', angle}
} else if (value > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {'l', angle}
} else if (value > constant) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {'l', angle}
} else if (value > constant) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (value < constant) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {'l', angle}
} else if (value > constant) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (value < constant) {
return {'r', angle}
} else if (value > constant) {
return {'l', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
le
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {'l', angle}
} else if (value > constant) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (value < constant) {
return {'r', angle}
} else if (value > constant) {
return {'l', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {'l', angle}
} else if (value > constant) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (value < constant) {
return {'r', angle}
} else if (value > constant) {
return {'l', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
for (let i = 0)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {'l', angle}
} else if (value > constant) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (value < constant) {
return {'r', angle}
} else if (value > constant) {
return {'l', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
for (let i = 0; i < A.length - 1)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {'l', angle}
} else if (value > constant) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (value < constant) {
return {'r', angle}
} else if (value > constant) {
return {'l', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
for (let i = 1; i < A.length - 1)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {'l', angle}
} else if (value > constant) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (value < constant) {
return {'r', angle}
} else if (value > constant) {
return {'l', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
for (let i = 1; i < A.length - 1; i++) {
}
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {'l', angle}
} else if (value > constant) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (value < constant) {
return {'r', angle}
} else if (value > constant) {
return {'l', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A))
}
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {'l', angle}
} else if (value > constant) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (value < constant) {
return {'r', angle}
} else if (value > constant) {
return {'l', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
}
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {'l', angle}
} else if (value > constant) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (value < constant) {
return {'r', angle}
} else if (value > constant) {
return {'l', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
}
angles.push
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {'l', angle}
} else if (value > constant) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (value < constant) {
return {'r', angle}
} else if (value > constant) {
return {'l', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
}
angles.push(turn(A[A.length-2], ))
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {'l', angle}
} else if (value > constant) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (value < constant) {
return {'r', angle}
} else if (value > constant) {
return {'l', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]))
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {'l', angle}
} else if (value > constant) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (value < constant) {
return {'r', angle}
} else if (value > constant) {
return {'l', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {'l', angle}
} else if (value > constant) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (value < constant) {
return {'r', angle}
} else if (value > constant) {
return {'l', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {'l', angle}
} else if (value > constant) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (value < constant) {
return {'r', angle}
} else if (value > constant) {
return {'l', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {'l', angle}
} else if (value > constant) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (value < constant) {
return {'r', angle}
} else if (value > constant) {
return {'l', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
let totalAngles
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {'l', angle}
} else if (value > constant) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (value < constant) {
return {'r', angle}
} else if (value > constant) {
return {'l', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
let totalAngles =
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', angle}
} else if (R.x > Q.x) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {'l', angle}
} else if (value > constant) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (value < constant) {
return {'r', angle}
} else if (value > constant) {
return {'l', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
let totalAngles =
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', angle}
} else {
return {'s', angle}
}
} else {
if (R.x < Q.x) {
return {'r', angle}
} else if (R.x > Q.x) {
return {'l', angle}
} else {
return {'s', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {'l', angle}
} else if (value > constant) {
return {'r', angle}
} else {
return {'s', angle}
}
} else {
if (value < constant) {
return {'r', angle}
} else if (value > constant) {
return {'l', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
let totalAngles =
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', angle}
} else {
return {dir: 's', angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', angle}
} else if (R.x > Q.x) {
return {dir: 'l', angle}
} else {
return {dir: 's', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', angle}
} else if (value > constant) {
return {dir: 'r', angle}
} else {
return {dir: 's', angle}
}
} else {
if (value < constant) {
return {dir: 'r', angle}
} else if (value > constant) {
return {dir: 'l', angle}
} else {
return {'s', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
let totalAngles =
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', angle}
} else if (R.x > Q.x) {
return {dir: 'l', angle}
} else {
return {dir: 's', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', angle}
} else if (value > constant) {
return {dir: 'r', angle}
} else {
return {dir: 's', angle}
}
} else {
if (value < constant) {
return {dir: 'r', angle}
} else if (value > constant) {
return {dir: 'l', angle}
} else {
return {dir: 's', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
let totalAngles =
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', angle}
} else {
return {dir: 's', angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', angle}
} else if (value > constant) {
return {dir: 'r', angle}
} else {
return {dir: 's', angle}
}
} else {
if (value < constant) {
return {dir: 'r', angle}
} else if (value > constant) {
return {dir: 'l', angle}
} else {
return {dir: 's', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
let totalAngles =
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', angle}
}
} else {
if (value < constant) {
return {dir: 'r', angle}
} else if (value > constant) {
return {dir: 'l', angle}
} else {
return {dir: 's', angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
let totalAngles =
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
let totalAngles = 0
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
totalAngles
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
totalAngles
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
totalAngles += angles[i-1].dir
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
totalAngles += angles[i-1].dir ===
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
totalAngles += angles[i-1].dir === 'r'
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
totalAngles += angles[i-1].dir === 'r' ? angles[i-1].ang :
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
if (angles[i - 1].dir === 'r')
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
if (angles[i - 1].dir === 'r') {
total
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]))
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.lenght - 2].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
if (total)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
let exterior = 'l';
if (totalAngles)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; )
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < A)
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < Angles.length; i++) {
if (Angles[i].dir === )
}
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < Angles.length; i++) {
if (Angles[i].dir === exterior) {
return i;
}
}
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < Angles.length; i++) {
if (Angles[i].dir === exterior) {
return i;
}
}
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
ReferenceError: Angles is not defined at solution (solution.js:34:25) at solutionWrapper (/tmp/exec.js:404:28) at Promise.resolve.then (/tmp/exec.js:430:24) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
ReferenceError: Angles is not defined at solution (solution.js:34:25) at solutionWrapper (/tmp/exec.js:404:28) at Promise.resolve.then (/tmp/exec.js:430:24) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (Angles[i].dir === exterior) {
return i;
}
}
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
second example test
Got 1, but 1 is an index of vertex that belongs to convex hull
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
con
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient);
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
1.0382922284930458
second example test
Got 1, but 1 is an index of vertex that belongs to convex hull
0.39479111969976133
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient)*;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient)*180/Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient)*180/Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient) * 180 / Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'r', ang: angle}
} else if (value > constant) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
59.489762593884464
second example test
Got 1, but 1 is an index of vertex that belongs to convex hull
22.619864948040444
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient) * 180 / Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
}
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?stdout:
360
second example test
Got 1, but 1 is an index of vertex that belongs to convex hull
360
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient) * 180 / Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (v1.x > 0) {
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient) * 180 / Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient) * 180 / Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient) * 180 / Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?stdout:
360
second example test
Got 1, but 1 is an index of vertex that belongs to convex hull
360
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
return -1;
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient) * 180 / Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
360
second example test
Got 1, but 1 is an index of vertex that belongs to convex hull
360
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
cons
console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
return -1;
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient) * 180 / Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.push(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
console.log(angles)
console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
return -1;
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient) * 180 / Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
[ { dir: 's', ang: 0.0000012074182697257333 }, { dir: 'r', ang: 119.74488129694224 }, { dir: 'r', ang: 78.69006752597979 }, { dir: 'r', ang: 71.56505117707799 }, { dir: 'r', ang: 90 } ] 360
second example test
Got 1, but 1 is an index of vertex that belongs to convex hull
[ { dir: 'r', ang: 63.43494882292201 }, { dir: 'l', ang: 90 }, { dir: 'r', ang: 146.30993247402023 }, { dir: 'r', ang: 78.69006752597979 }, { dir: 'r', ang: 90 }, { dir: 'l', ang: 45.00000000000001 }, { dir: 'r', ang: 116.56505117707799 } ] 360
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.u(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
console.log(angles)
console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
return -1;
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient) * 180 / Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.unshift(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[angles.length - 1].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
console.log(angles)
console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
return -1;
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient) * 180 / Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.unshift(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[0].dir === 'r') {
totalAngles += angles[angles.length - 1].ang;
} else if (angles[angles.length - 1].dir === 'l') {
totalAngles -= angles[angles.length - 1].ang;
}
console.log(angles)
console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
return -1;
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient) * 180 / Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.unshift(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[0].dir === 'r') {
totalAngles += angles[0].ang;
} else if (angles[0].dir === 'l') {
totalAngles -= angles[0].ang;
}
console.log(angles)
console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
return -1;
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient) * 180 / Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
[ { dir: 'r', ang: 90 }, { dir: 's', ang: 0.0000012074182697257333 }, { dir: 'r', ang: 119.74488129694224 }, { dir: 'r', ang: 78.69006752597979 }, { dir: 'r', ang: 71.56505117707799 } ] 367.1250163489018
[ { dir: 'r', ang: 116.56505117707799 }, { dir: 'r', ang: 63.43494882292201 }, { dir: 'l', ang: 90 }, { dir: 'r', ang: 146.30993247402023 }, { dir: 'r', ang: 78.69006752597979 }, { dir: 'r', ang: 90 }, { dir: 'l', ang: 45.00000000000001 } ] 495
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.unshift(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[0].dir === 'r') {
totalAngles += angles[0].ang;
} else if (angles[0].dir === 'l') {
totalAngles -= angles[0].ang;
}
console.log(angles)
console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
return -1;
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient) * 180 / Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.unshift(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[0].dir === 'r') {
totalAngles += angles[0].ang;
} else if (angles[0].dir === 'l') {
totalAngles -= angles[0].ang;
}
console.log(angles)
console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
return -1;
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient) * 180 / Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.unshift(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[0].dir === 'r') {
totalAngles += angles[0].ang;
} else if (angles[0].dir === 'l') {
totalAngles -= angles[0].ang;
}
console.log(angles)
console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
return -1;
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient) * 180 / Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.unshift(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[0].dir === 'r') {
totalAngles += angles[0].ang;
} else if (angles[0].dir === 'l') {
totalAngles -= angles[0].ang;
}
console.log(angles)
console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
return -1;
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient) * 180 / Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.unshift(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[0].dir === 'r') {
totalAngles += angles[0].ang;
} else if (angles[0].dir === 'l') {
totalAngles -= angles[0].ang;
}
console.log(angles)
console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
return -1;
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient) * 180 / Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.unshift(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[0].dir === 'r') {
totalAngles += angles[0].ang;
} else if (angles[0].dir === 'l') {
totalAngles -= angles[0].ang;
}
console.log(angles)
console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
return -1;
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient) * 180 / Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.unshift(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[0].dir === 'r') {
totalAngles += angles[0].ang;
} else if (angles[0].dir === 'l') {
totalAngles -= angles[0].ang;
}
console.log(angles)
console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
return -1;
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient) * 180 / Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.unshift(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[0].dir === 'r') {
totalAngles += angles[0].ang;
} else if (angles[0].dir === 'l') {
totalAngles -= angles[0].ang;
}
console.log(angles)
console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
return -1;
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient) * 180 / Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
[(2, 2), (0, 1), (-2, 2), (-1, 0), (-2, -2), (0, -1), (2, -2), (1, 0)]
[ { dir: 'r', ang: 90 }, { dir: 's', ang: 0.0000012074182697257333 }, { dir: 'r', ang: 119.74488129694224 }, { dir: 'r', ang: 78.69006752597979 }, { dir: 'r', ang: 71.56505117707799 } ] 367.1250163489018
[ { dir: 'r', ang: 116.56505117707799 }, { dir: 'r', ang: 63.43494882292201 }, { dir: 'l', ang: 90 }, { dir: 'r', ang: 146.30993247402023 }, { dir: 'r', ang: 78.69006752597979 }, { dir: 'r', ang: 90 }, { dir: 'l', ang: 45.00000000000001 } ] 495
function result: 1
[ { dir: 'l', ang: 143.13010235415598 }, { dir: 'r', ang: 53.130102354155994 }, { dir: 'l', ang: 143.13010235415598 }, { dir: 'r', ang: 53.130102354155994 }, { dir: 'l', ang: 143.13010235415598 }, { dir: 'r', ang: 53.130102354155994 }, { dir: 'l', ang: 143.13010235415598 }, { dir: 'r', ang: 53.130102354155994 } ] -556.2602047083119
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.unshift(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[0].dir === 'r') {
totalAngles += angles[0].ang;
} else if (angles[0].dir === 'l') {
totalAngles -= angles[0].ang;
}
// console.log(angles)
// console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
return -1;
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient) * 180 / Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.unshift(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[0].dir === 'r') {
totalAngles += angles[0].ang;
} else if (angles[0].dir === 'l') {
totalAngles -= angles[0].ang;
}
// console.log(angles)
// console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
return -1;
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient) * 180 / Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
[(2, 2), (0, 1), (-2, 2), (-1, 0), (-2, -2), (0, -1), (2, -2), (1, 0)]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.unshift(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[0].dir === 'r') {
totalAngles += angles[0].ang;
} else if (angles[0].dir === 'l') {
totalAngles -= angles[0].ang;
}
// console.log(angles)
// console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
return -1;
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient) * 180 / Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
[(2, 2), (0, 1), (-2, 2), (-1, 0), (-2, -2), (0, -1), (2, -2), (1, 0)]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let angles = [];
let totalAngles = 0
for (let i = 1; i < A.length - 1; i++) {
angles.push(turn(A[i-1], A[i], A[i+1]));
if (angles[i - 1].dir === 'r') {
totalAngles += angles[i - 1].ang;
} else if (angles[i - 1].dir === 'l') {
totalAngles -= angles[i - 1].ang;
}
}
angles.push(turn(A[A.length-2], A[A.length-1], A[0]));
angles.unshift(turn(A[A.length-1], A[0], A[1]));
if (angles[angles.length - 2].dir === 'r') {
totalAngles += angles[angles.length - 2].ang;
} else if (angles[angles.length - 2].dir === 'l') {
totalAngles -= angles[angles.length - 2].ang;
}
if (angles[0].dir === 'r') {
totalAngles += angles[0].ang;
} else if (angles[0].dir === 'l') {
totalAngles -= angles[0].ang;
}
// console.log(angles)
// console.log(totalAngles);
let exterior = 'l';
if (totalAngles < 0) {
exterior = 'r';
}
for (let i = 0; i < angles.length; i++) {
if (angles[i].dir === exterior) {
return i;
}
}
return -1;
}
function turn(P, Q, R) {
const v1 = {x: Q.x - P.x, y: Q.y - P.y};
const v2 = {x: R.x - Q.x, y: R.y - Q.y};
const numerator = v1.x * v2.x + v1.y * v2.y;
const lenv1 = Math.sqrt(v1.x * v1.x + v1.y * v1.y);
const lenv2 = Math.sqrt(v2.x * v2.x + v2.y * v2.y);
let quotient = numerator / (lenv1 * lenv2);
if (quotient < -1) {
quotient = -1;
} else if (quotient > 1) {
quotient = 1
}
const angle = Math.acos(quotient) * 180 / Math.PI;
if (v1.x === 0) {
if (v1.y > 0) {
if (R.x < Q.x) {
return {dir: 'l', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
} else {
if (R.x < Q.x) {
return {dir: 'r', ang: angle}
} else if (R.x > Q.x) {
return {dir: 'l', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
} else {
const constant = v1.y * P.x - v1.x * P.y;
const value = v1.y * R.x - v1.x * R.y;
if (value < constant) {
return {dir: 'l', ang: angle}
} else if (value > constant) {
return {dir: 'r', ang: angle}
} else {
return {dir: 's', ang: angle}
}
}
}
The solution obtained perfect score.