Given the coordinates of the centres and the radii of 2 circles, output a truthy value of whether they do or do not overlap.
Input
Input may be taken via STDIN or equivalent, function arguments, but not as a variable. You can take them as a single variable (list, string etc) or as multiple inputs / arguments, in whatever order you want.
The input will be six floats. These floats will be up to 3 decimal places. The coordinates can be positive or negative. The radii will be positive.
Output
Output can be via STDOUT or function return.
The program must have exactly 2 distinct outputs - one for a True value (the circles do overlap) and one for a False output (they don't overlap).
Test cases
(Input is given as list of tuples [(x1, y1, r1), (x2, y2, r2)] for the test cases; you can take input in any format)
True
[(5.86, 3.92, 1.670), (11.8, 2.98, 4.571)]
[(8.26, -2.72, 2.488), (4.59, -2.97, 1.345)]
[(9.32, -7.77, 2.8), (6.21, -8.51, 0.4)]
False
[(4.59, -2.97, 1.345), (11.8, 2.98, 4.571)]
[(9.32, -7.77, 2.8), (4.59, -2.97, 1.345)]
[(5.86, 3.92, 1.670), (6.21, -8.51, 0.4)]
This is Code Golf, shortest answer in bytes wins.
-
4\$\begingroup\$ What do we need to return if two circles are touching externally? \$\endgroup\$JungHwan Min– JungHwan Min2017年07月26日 20:55:53 +00:00Commented Jul 26, 2017 at 20:55
-
6\$\begingroup\$ The technical term for "touching but not overlapping" is "tangent" and it is a thing in geometry if nowhere else. \$\endgroup\$dmckee --- ex-moderator kitten– dmckee --- ex-moderator kitten2017年07月27日 04:32:20 +00:00Commented Jul 27, 2017 at 4:32
-
2\$\begingroup\$ Taking floats seems like a pretty stringent requirement. Could you relax it to a more general representation? I would like to solve this in Brain-Flak, but I am unlikely to take the time to implement IEEE floats, and if I did it would be 90% of the byte count anyway so I would just be golfing a float implementation. \$\endgroup\$Wheat Wizard– Wheat Wizard ♦2017年07月27日 04:34:08 +00:00Commented Jul 27, 2017 at 4:34
-
4\$\begingroup\$ I would also like to point out that floats are not accurate up to "three decimal places" in a lot of cases. I'm not sure exactly what you want answers to handle, but its a little confusing right now. \$\endgroup\$Wheat Wizard– Wheat Wizard ♦2017年07月27日 04:39:52 +00:00Commented Jul 27, 2017 at 4:39
-
2\$\begingroup\$ I think you might have a fundamental misunderstanding of how floats work. Because they are fixed-size, as the values get larger, the precision gets lower. There is a point beyond which a float cannot accurately represent all values within 3 decimal places. Also, editing a challenge to remove an unnecessary restriction is not discouraged. \$\endgroup\$user45941– user459412017年07月27日 13:58:25 +00:00Commented Jul 27, 2017 at 13:58
35 Answers 35
Jelly, 5 bytes
IA<S}
Takes two complex numbers (centers) as first argument, and two real numbers (radii) as second argument.
How it works
IA<S} Main link.
Left argument: [x1 + iy1, x2 + iy2]
Right argument: [r1, r2]
I Increments; yield (x2 - x1) + i(y2 - y1).
A Absolute value; yield √((x2 - x1)2 + (y2 - y1)2).
S} Take the sum of the right argument, yielding r1 + r2.
< Compare the results.
-
\$\begingroup\$ Damn, I forgot about using complex numbers for coordinates. Good one! :D \$\endgroup\$2017年07月26日 21:19:04 +00:00Commented Jul 26, 2017 at 21:19
-
\$\begingroup\$ Out of interest would the result of
Ahere be considered the norm of the row vector "centers"? (ÆḊitself errors with complex content.) \$\endgroup\$Jonathan Allan– Jonathan Allan2017年07月27日 01:52:15 +00:00Commented Jul 27, 2017 at 1:52 -
1\$\begingroup\$ @JonathanAllan Yes,
Acomputes the distances of the centers as the norm of their difference vector. \$\endgroup\$Dennis– Dennis2017年07月27日 01:53:40 +00:00Commented Jul 27, 2017 at 1:53
JavaScript (ES6), 38 bytes
Takes input as 6 distinct variables x1, y1, r1, x2, y2, r2.
(x,y,r,X,Y,R)=>Math.hypot(x-X,y-Y)<r+R
Test cases
let f =
(x,y,r,X,Y,R)=>Math.hypot(x-X,y-Y)<r+R
// True
console.log(f(5.86, 3.92, 1.670, 11.8, 2.98, 4.571))
console.log(f(8.26, -2.72, 2.488, 4.59, -2.97, 1.345))
console.log(f(9.32, -7.77, 2.8, 6.21, -8.51, 0.4))
// False
console.log(f(4.59, -2.97, 1.345, 11.8, 2.98, 4.571))
console.log(f(9.32, -7.77, 2.8, 4.59, -2.97, 1.345))
console.log(f(5.86, 3.92, 1.670, 6.21, -8.51, 0.4))
-
\$\begingroup\$ For anyone who hasn't seem Math.hypot before. \$\endgroup\$AncientSwordRage– AncientSwordRage2017年07月27日 07:38:14 +00:00Commented Jul 27, 2017 at 7:38
-
\$\begingroup\$ scala polyglot :) but it does not work for some reason \$\endgroup\$V. Courtois– V. Courtois2017年07月27日 08:54:34 +00:00Commented Jul 27, 2017 at 8:54
-
\$\begingroup\$ @V.Courtois The way you pass the parameters doesn't match the method declaration. It should be
a:Double,x:Double,b:Double,y:Double,r:Double,q:Double. \$\endgroup\$Arnauld– Arnauld2017年07月27日 11:13:49 +00:00Commented Jul 27, 2017 at 11:13 -
1\$\begingroup\$ @Arnauld ooh~ thanks! Should I post it separately? \$\endgroup\$V. Courtois– V. Courtois2017年07月27日 12:05:28 +00:00Commented Jul 27, 2017 at 12:05
-
\$\begingroup\$ @V.Courtois Sure. Go for it! \$\endgroup\$Arnauld– Arnauld2017年07月27日 12:42:55 +00:00Commented Jul 27, 2017 at 12:42
Pyth, 5 bytes
gsE.a
Input format:
[x1, y1], [x2, y2]
r1, r2
How it works
Q autoinitialized to eval(input())
.a L2 norm of vector difference of Q[0] and Q[1]
gsE sum(eval(input()) >= that
MATL, 5 bytes
ZPis<
Input format is:
[x1, y1]
[x2, y2]
[r1, r2]
Try it online! Or verify all test cases.
How it works
ZP % Take two vectors as input. Push their Euclidean distance
i % Input the vector of radii
s % Sum of vector
< % Less than?
-
\$\begingroup\$ Not sure if it is me, but when I use your trial link and press run I get 'Error The server's response could not be decoded' -- Also Not sure if it helps, but did you think about (ab) using complex numbers like in the Jelly answer? \$\endgroup\$Dennis Jaheruddin– Dennis Jaheruddin2017年07月27日 15:31:12 +00:00Commented Jul 27, 2017 at 15:31
-
\$\begingroup\$ @DennisJaheruddin Hey, nice to see you again here! (1) Blame caching, probably. Did you try a hard refresh? (2) I did, but I think it's also
5bytes (-|instead ofZP) \$\endgroup\$Luis Mendo– Luis Mendo2017年07月27日 15:33:01 +00:00Commented Jul 27, 2017 at 15:33 -
\$\begingroup\$ I suppose it is the firewall. Now i'm wondering whether an input format with something like
-r2instead ofr2would help because then you would need three differences, instead of 2 differences and an addition... I'd better run before I get drawn in too deep! \$\endgroup\$Dennis Jaheruddin– Dennis Jaheruddin2017年07月27日 15:43:34 +00:00Commented Jul 27, 2017 at 15:43 -
\$\begingroup\$ I don't think that negating one input is acceptable as input format. If you find any problems with the Try It Online service, would you please report here? \$\endgroup\$Luis Mendo– Luis Mendo2017年07月27日 15:48:44 +00:00Commented Jul 27, 2017 at 15:48
R, 39 bytes
function(k,r)dist(matrix(k,2,2))<sum(r)
takes input k=c(x1,x2,y1,y2) and r=c(r1,r2); returns FALSE for tangent circles.
27 bytes:
function(m,r)dist(m)<sum(r)
Takes input as a matrix with the circle centers given as rows and a vector of radii.
-
\$\begingroup\$ -2 bytes
function(k,r)dist(matrix(k,2))<sum(r)\$\endgroup\$djhurio– djhurio2017年07月27日 05:46:26 +00:00Commented Jul 27, 2017 at 5:46 -
\$\begingroup\$ What about
dist(matrix(scan(),2))<sum(scan())? \$\endgroup\$djhurio– djhurio2017年07月27日 05:49:27 +00:00Commented Jul 27, 2017 at 5:49
Python, 40 bytes
lambda x,y,r,X,Y,R:abs(x-X+(y-Y)*1j)<r+R
Uses Python's complex arithmetic to compute the distance between the two centers. I'm assuming we can't take the input points directly as complex numbers, so the code expresses them like x+y*1j.
-
\$\begingroup\$ Oh 05AB1E does imaginary now? \$\endgroup\$Magic Octopus Urn– Magic Octopus Urn2017年08月09日 17:40:02 +00:00Commented Aug 9, 2017 at 17:40
-
1\$\begingroup\$ @MagicOctopusUrn Apparently /shrug \$\endgroup\$2017年08月09日 17:40:38 +00:00Commented Aug 9, 2017 at 17:40
-
\$\begingroup\$ This code works in python 2 also. \$\endgroup\$micsthepick– micsthepick2017年07月26日 23:50:27 +00:00Commented Jul 26, 2017 at 23:50
-
\$\begingroup\$ @micsthepick Cool, thanks. It's just the way TIO does formatting. \$\endgroup\$2017年07月26日 23:53:02 +00:00Commented Jul 26, 2017 at 23:53
APL (Dyalog), 10 bytes
Prompts for circle centers as list of two complex numbers, then for radii as list of two numbers
(+/⎕)>|-/⎕
(+/⎕) [is] the sum of the radii
> greater than
| the magnitude of
-/⎕ the difference in centers
Mathematica, 16 bytes
Norm[#-#2]<+##3&
Input: [{x1, y1}, {x2, y2}, r1, r2]
Mathematica has a RegionIntersection builtin, but that alone is 18 bytes long...
Built-in version:
RegionIntersection@##==EmptyRegion@2&
Takes 2 Disk objects. [Disk[{x1, y1}, r1], Disk[{x2, y2}, r2]].
Haskell, (削除) 37 (削除ここまで) 36 bytes
(u#v)r x y s=(u-x)^2+(v-y)^2<(r+s)^2
Thanks @AndersKaseorg for -1 byte!
-
3\$\begingroup\$ Shorter as an operator:
(u!v)r x y s. \$\endgroup\$Anders Kaseorg– Anders Kaseorg2017年07月26日 21:03:30 +00:00Commented Jul 26, 2017 at 21:03
-
\$\begingroup\$ Wouldn't creating a new link with
ạ/²on it same bytes? \$\endgroup\$2017年07月26日 21:03:51 +00:00Commented Jul 26, 2017 at 21:03 -
\$\begingroup\$ @cairdcoinheringaahing ? \$\endgroup\$2017年07月26日 21:04:52 +00:00Commented Jul 26, 2017 at 21:04
-
\$\begingroup\$ Never mind, I got 14 bytes by doing this \$\endgroup\$2017年07月26日 21:06:18 +00:00Commented Jul 26, 2017 at 21:06
-
\$\begingroup\$ You can use
Iinstead of reducing by absolute difference. \$\endgroup\$Dennis– Dennis2017年07月26日 21:24:56 +00:00Commented Jul 26, 2017 at 21:24
Java 8, (削除) 41 (削除ここまで) 38 bytes
(x,y,r,X,Y,R)->Math.hypot(x-X,y-Y)<r+R
Apparently, Java also has Math.hypot, which is 3 bytes shorter.
EDIT: Just realized this answer is now exactly the same as @OlivierGrégoire's Java 8 answer, so please upvote him instead of me if you like the 38-byte answer.
Old answer (41 bytes):
(x,y,r,X,Y,R)->(x-=X)*x+(y-=Y)*y<(r+=R)*r
-
1\$\begingroup\$ Oh! So that's why I got 3 upvotes today, but 0 when the challenge was posted? ^^ I was wondering what triggered this weird behavior ;) Since I like my answer, and you posted the same, you get a +1 as well! :p \$\endgroup\$Olivier Grégoire– Olivier Grégoire2017年08月09日 18:03:27 +00:00Commented Aug 9, 2017 at 18:03
Perl 6, 13 bytes
*+*>(*-*).abs
The first two arguments are the radii, in either order. The third and fourth arguments are the coordinates of the centers, as complex numbers, in either order.
Taxi, 1582 bytes
Go to Post Office:w 1 l 1 r 1 l.Pickup a passenger going to The Babelfishery.Pickup a passenger going to Tom's Trims.Pickup a passenger going to Tom's Trims.Go to Tom's Trims:n.[a]Go to Post Office:s.Pickup a passenger going to The Babelfishery.Go to The Babelfishery:s 1 l 1 r.Pickup a passenger going to What's The Difference.Pickup a passenger going to What's The Difference.Go to What's The Difference:n 5 l.Pickup a passenger going to Cyclone.Go to Cyclone:e 1 r.Pickup a passenger going to Multiplication Station.Pickup a passenger going to Multiplication Station.Go to Multiplication Station:s 1 l 2 r 4 l.Pickup a passenger going to Addition Alley.Go to Tom's Trims:s 1 r 3 r.Pickup a passenger going to The Babelfishery.Switch to plan "b" if no one is waiting.Switch to plan "a".[b]Go to Addition Alley:n 1 r 1 l 3 l 1 l.Pickup a passenger going to Magic Eight.Go to Post Office:n 1 r 1 r 3 r 1 l.Pickup a passenger going to The Babelfishery.Go to The Babelfishery:s 1 l 1 r.Pickup a passenger going to Addition Alley.Pickup a passenger going to Addition Alley.Go to Addition Alley:n 5 l 1 l.Pickup a passenger going to Cyclone.Go to Cyclone:n 1 l 1 l.Pickup a passenger going to Multiplication Station.Pickup a passenger going to Multiplication Station.Go to Multiplication Station:s 1 l 2 r 4 l.Pickup a passenger going to Magic Eight.Go to Magic Eight:s 1 r.Switch to plan "c" if no one is waiting.'1' is waiting at Writer's Depot.[c]'0' is waiting at Writer's Depot.Go to Writer's Depot:w 1 l 2 l.Pickup a passenger going to Post Office.Go to Post Office:n 1 r 2 r 1 l.
Outputs 1 for overlapping circles.
Outputs 0 for non-overlapping circles (including tangential circles).
Ungolfed / formatted:
Go to Post Office: west 1st left 1st right 1st left.
Pickup a passenger going to The Babelfishery.
Pickup a passenger going to Tom's Trims.
Pickup a passenger going to Tom's Trims.
Go to Tom's Trims: north.
[a]
Go to Post Office: south.
Pickup a passenger going to The Babelfishery.
Go to The Babelfishery: south 1st left 1st right.
Pickup a passenger going to What's The Difference.
Pickup a passenger going to What's The Difference.
Go to What's The Difference: north 5th left.
Pickup a passenger going to Cyclone.
Go to Cyclone: east 1st right.
Pickup a passenger going to Multiplication Station.
Pickup a passenger going to Multiplication Station.
Go to Multiplication Station: south 1st left 2nd right 4th left.
Pickup a passenger going to Addition Alley.
Go to Tom's Trims: south 1st right 3rd right.
Pickup a passenger going to The Babelfishery.
Switch to plan "b" if no one is waiting.
Switch to plan "a".
[b]
Go to Addition Alley: north 1st right 1st left 3rd left 1st left.
Pickup a passenger going to Magic Eight.
Go to Post Office: north 1st right 1st right 3rd right 1st left.
Pickup a passenger going to The Babelfishery.
Go to The Babelfishery: south 1st left 1st right.
Pickup a passenger going to Addition Alley.
Pickup a passenger going to Addition Alley.
Go to Addition Alley: north 5th left 1st left.
Pickup a passenger going to Cyclone.
Go to Cyclone: north 1st left 1st left.
Pickup a passenger going to Multiplication Station.
Pickup a passenger going to Multiplication Station.
Go to Multiplication Station: south 1st left 2nd right 4th left.
Pickup a passenger going to Magic Eight.
Go to Magic Eight: south 1st right.
Switch to plan "c" if no one is waiting.
'1' is waiting at Writer's Depot.
[c]
'0' is waiting at Writer's Depot.
Go to Writer's Depot: west 1st left 2nd left.
Pickup a passenger going to Post Office.
Go to Post Office: north 1st right 2nd right 1st left.
C#, (削除) 50 (削除ここまで) 41 bytes
(x,y,r,X,Y,R)=>(x-=X)*x+(y-=Y)*y<(r+=R)*r
Saved 9 bytes thanks to @KevinCruijssen.
-
\$\begingroup\$ Can't you save a few bytes there by writing
(r+R)*2instead of(r+R)+(r+R)? \$\endgroup\$Ian H.– Ian H.2017年07月27日 11:21:16 +00:00Commented Jul 27, 2017 at 11:21 -
\$\begingroup\$ @IanH. Yeah don't know how I missed that. \$\endgroup\$TheLethalCoder– TheLethalCoder2017年07月27日 11:27:12 +00:00Commented Jul 27, 2017 at 11:27
-
-
\$\begingroup\$ @IanH. I'd made a typo, the
+on the RHS should have been a*. \$\endgroup\$TheLethalCoder– TheLethalCoder2017年07月27日 11:35:58 +00:00Commented Jul 27, 2017 at 11:35 -
\$\begingroup\$ And my feedback even made that worse. Good job on the solution though! \$\endgroup\$Ian H.– Ian H.2017年07月27日 11:38:15 +00:00Commented Jul 27, 2017 at 11:38
PostgreSQL, 41 characters
prepare f(circle,circle)as select 1ドル&&2ドル;
Prepared statement, takes input as 2 parameters in any circle notation.
Sample run:
Tuples only is on.
Output format is unaligned.
psql (9.6.3, server 9.4.8)
Type "help" for help.
psql=# prepare f(circle,circle)as select 1ドル&&2ドル;
PREPARE
psql=# execute f('5.86, 3.92, 1.670', '11.8, 2.98, 4.571');
t
psql=# execute f('8.26, -2.72, 2.488', '4.59, -2.97, 1.345');
t
psql=# execute f('9.32, -7.77, 2.8', '6.21, -8.51, 0.4');
t
psql=# execute f('4.59, -2.97, 1.345', '11.8, 2.98, 4.571');
f
psql=# execute f('9.32, -7.77, 2.8', '4.59, -2.97, 1.345');
f
psql=# execute f('5.86, 3.92, 1.670', '6.21, -8.51, 0.4');
f
Java, (削除) 50 (削除ここまで) 38 bytes
(x,y,r,X,Y,R)->Math.hypot(x-X,y-Y)<r+R
-
\$\begingroup\$ Using ideas in other answers, this can be shortened to 38 like so:
(x,y,r,X,Y,R)->Math.hypot(x-X,y-Y)<r+R. In fact, just realised this is the exact same as Arnauld's JavaScript answer. \$\endgroup\$laszlok– laszlok2017年07月28日 06:45:23 +00:00Commented Jul 28, 2017 at 6:45 -
\$\begingroup\$ Thanks... This answer was nevee intended to be golfed... i thought it was such a simple challenge there wouldn't be anything that can be golfed... \$\endgroup\$Linnea Gräf– Linnea Gräf2017年07月28日 06:51:18 +00:00Commented Jul 28, 2017 at 6:51
-
\$\begingroup\$ I'm afraid your answer is now exactly the same as the already posted answer by @OlivierGrégoire.. \$\endgroup\$Kevin Cruijssen– Kevin Cruijssen2017年08月09日 07:29:24 +00:00Commented Aug 9, 2017 at 7:29
x86 Machine Code (with SSE2), 36 bytes
; bool CirclesOverlap(double x1, double y1, double r1,
; double x2, double y2, double r2);
F2 0F 5C C3 subsd xmm0, xmm3 ; x1 - x2
F2 0F 5C CC subsd xmm1, xmm4 ; y1 - y2
F2 0F 58 D5 addsd xmm2, xmm5 ; r1 + r2
F2 0F 59 C0 mulsd xmm0, xmm0 ; (x1 - x2)^2
F2 0F 59 C9 mulsd xmm1, xmm1 ; (y1 - y2)^2
F2 0F 59 D2 mulsd xmm2, xmm2 ; (r1 + r2)^2
F2 0F 58 C1 addsd xmm0, xmm1 ; (x1 - x2)^2 + (y1 - y2)^2
66 0F 2F D0 comisd xmm2, xmm0
0F 97 C0 seta al ; ((r1 + r2)^2) > ((x1 - x2)^2 + (y1 - y2)^2)
C3 ret
The above function accepts descriptions of two circles (x- and y-coordinates of center point and a radius), and returns a Boolean value indicating whether or not they intersect.
It uses a vector calling convention, where the parameters are passed in SIMD registers. On x86-32 and 64-bit Windows, this is the __vectorcall calling convention. On 64-bit Unix/Linux/Gnu, this is the standard System V AMD64 calling convention.
The return value is left in the low byte of EAX, as is standard with all x86 calling conventions.
This code works equally well on 32-bit and 64-bit x86 processors, as long as they support the SSE2 instruction set (which would be Intel Pentium 4 and later, or AMD Athlon 64 and later).
AVX version, still 36 bytes
If you were targeting AVX, you would probably want to add a VEX prefix to the instructions. This does not change the byte count; just the actual bytes used to encode the instructions:
; bool CirclesOverlap(double x1, double y1, double r1,
; double x2, double y2, double r2);
C5 FB 5C C3 vsubsd xmm0, xmm0, xmm3 ; x1 - x2
C5 F3 5C CC vsubsd xmm1, xmm1, xmm4 ; y1 - y2
C5 EB 58 D5 vaddsd xmm2, xmm2, xmm5 ; r1 + r2
C5 FB 59 C0 vmulsd xmm0, xmm0, xmm0 ; (x1 - x2)^2
C5 F3 59 C9 vmulsd xmm1, xmm1, xmm1 ; (y1 - y2)^2
C5 EB 59 D2 vmulsd xmm2, xmm2, xmm2 ; (r1 + r2)^2
C5 FB 58 C1 vaddsd xmm0, xmm0, xmm1 ; (x1 - x2)^2 + (y1 - y2)^2
C5 F9 2F D0 vcomisd xmm2, xmm0
0F 97 C0 seta al ; ((r1 + r2)^2) > ((x1 - x2)^2 + (y1 - y2)^2)
C3 ret
AVX instructions have the advantage of taking three operands, allowing you to do non-destructive operations, but that doesn't really help us to compact the code any here. However, mixing instructions with and without VEX prefixes can result in sub-optimal code, so you generally want to stick with all AVX instructions if you're targeting AVX, and in this case, it doesn't even hurt your byte count.
PHP, 66 bytes
<?php $i=$argv;echo hypot($i[1]-$i[4],$i[2]-$i[5])<$i[3]+$i[6]?:0;
Runs from the command line, taking input as 6 command-line parameter arguments, and prints 1 if the circles overlap, else 0.
dc, 22 bytes
9k?+_5R-d*_3R-d*+v-vzp
Input is read from stdin in the format x1 x2 y1 y2 r1 r2. Note that negative numbers are written in dc with an underscore _ instead of a minus sign -.
Output is on stdout: 1 for truthy, 0 for falsey. If the two circles are tangent to one another or if they're identical, they're considered to be overlapping.
This requires a recent version of GNU dc which supports the R operation (rotate).
On versions of dc which don't support R, you can instead use
9k?-d*sY-d*lY+vsD+lD-vzp
(24 bytes long), with input presented on stdin in the order r1 r2 x1 x2 y1 y2. Here's a test suite for the 24-byte program, for older versions of dc
Explanation
9k Set precision to 9 decimal places.
? Read the input and push all 6 numbers on the stack (r2 is at the top of the stack since it's entered last).
+ Add r1 and r2
_5R Rotate the stack so that r1+r2 is now at the bottom.
-d* Compute (y1-y2)^2.
_3R Rotate the stack so that it's now: r1+r2 (y1-y2)^2 x1 x2 (top on the right)
-d* Compute (x1-x2)^2.
+ Compute (x1-x2)^2 + (y1-y2)^2.
v Take the square root to compute the distance between the centers.
- Subtract the distance between the centers from r1-r2.
v Pop one number from the stack. If it's non-negative, then compute its square root and push that back on the stack.
z Push the size of the stack onto the stack. (This is 0 if the difference was negative, and it's 1 if the difference was positive.)
p Print the item at the top of the stack.
Julia 0.6.0 (46 bytes)
a->((a[1]-a[2])^2+(a[3]-a[4])^2<(a[5]+a[6])^2)
Clojure, 68 bytes
#(<(+(*(- %4 %)(- %4 %))(*(- %5 %2)(- %5 %2)))(*(+ %6 %3)(+ %6 %3)))
Takes six arguments: x1, y1, r1, x2, y2, r2. Returns true or false.
Sadly, Clojure does not have a pow function of some sorts. Costs a lot of bytes.
Actually, 8 bytes
-)-(h@+>
Explanation:
-)-(h@+> (implicit input: [y1, y2, x1, x2, r1, r2])
- y2-y1 ([y2-y1, x1, x2, r1, r2])
)- move to bottom, x1-x2 ([x1-x2, r1, r2, y2-y1])
(h move from bottom, Euclidean norm ([sqrt((y2-y1)**2+(x2-x1)**2), r1, r2])
@+ r1+r2 ([r1+r2, norm])
> is r1+r2 greater than norm?
R (+pryr), 31 bytes
pryr::f(sum((x-y)^2)^.5<sum(r))
Which evaluates to the function
function (x, y, z)
sum((x - y)^2)^0.5 < sum(z)
Where x are the coordinates of circle 1, y are the coordinates of circle 2 and z the radii.
Calculates the distance between the two centers using Pythagoras and tests if that distance is smaller than the sum of the radii.
Makes use of R's vectorisation to simultaneously calculate (x1-x2)^2 and (y1-y2)^2. These are then summed and squarely rooted.