Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let data = input.slice(0).filter(x => x !== "");
- class Circle {
- constructor(center, radius) {
- this.center = center;
- this.radius = radius;
- }
- }
- class Point {
- constructor(x, y) {
- this.x = x;
- this.y = y;
- }
- }
- const intersect = (circle1, cirlce2) => {
- let d = 0;
- let x1 = circle1.center.x;
- let y1 = circle1.center.y;
- let x2 = cirlce2.center.x;
- let y2 = circle2.center.y;
- if (x1 === x2) {
- d = Math.abs(y1 - y2);
- } else if (y1 === y2) {
- d = Math.abs(x1 - x2);
- } else {
- let a = Math.abs(x1 - x2);
- let b = Math.abs(y1 - y2);
- d = Math.sqrt(a ** 2 + b ** 2);
- }
- return d <= circle1.radius + circle2.radius;
- };
- let [x1, y1, r1] = data[0].split(" ").map(Number);
- let circle1 = new Circle(new Point(x1,y1), r1);
- let [x2, y2, r2] = data[1].split(" ").map(Number);
- let circle2 = new Circle(new Point(x2,y2), r2);
- console.log(intersect(circle1, circle2) ? "Yes" : "No");
- }
Advertisement
Add Comment
Please, Sign In to add comment