PeterT
PeterT

Reputation: 507

94 characters one line task, circle-intersection

I found a challenge here:

https://www.codewars.com/kata/one-line-task-circle-intersection/train/javascript

Write a function that that takes two points and the radius of the two same size circles and return the area of the intersection of two circles.

with(Math)circleIntersection=([a,b],[c,d],r)=>(l=hypot(a-c,b-d)/2/r)>1?0:2*r*r*(acos(l)-l*sqrt(1-l*l))|0

It said that the function should have no more than 94 characters. I have done my best to shorten the function, still got 104 characters( function name can't been changed). Any idea to improve it?

Upvotes: 1

Views: 1907

Answers (1)

מתן ל
מתן ל

Reputation: 234

I really think that my answer is the best :-)

with(Math)circleIntersection=([a,b],[c,d],r)=>(-sin(x=2*acos(hypot(a-c,b-d)/2/r))+x)*r*r|0

Upvotes: 1

Related Questions