7 kyu
[Code Golf] One Line Task: Pyramid of Spheres
114 of 125polluxCast0r
Description:
You are given 4 spheres, one of them lies on 3 others; all the spheres are in contact - see the image below:

(The front sphere was made transparent for clear view)
All spheres have the same radius r
Task
Your task is to write a function that accepts a radius r
, and returns the distance between the bottom of the upper sphere and the plane on which they are all located (vertical dashed line at the image below). The answer should be rounded to 4 decimal places. If the function recieves invalid float for radius (r < 0), then it should return 0.0
as an answer.

Code limit
The maximum code length: 58
Examples
10 --> 16.3299
9 --> 14.6969
1.224744871391589 --> 2.0
-10 --> 0.0
Mathematics
Geometry
Restricted
Fundamentals
Similar Kata:
Stats:
Created | Aug 15, 2018 |
Published | Aug 15, 2018 |
Warriors Trained | 293 |
Total Skips | 3 |
Total Code Submissions | 1404 |
Total Times Completed | 125 |
Python Completions | 114 |
Ruby Completions | 19 |
Total Stars | 6 |
% of votes with a positive feedback rating | 81% of 52 |
Total "Very Satisfied" Votes | 36 |
Total "Somewhat Satisfied" Votes | 12 |
Total "Not Satisfied" Votes | 4 |
Total Rank Assessments | 24 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 8 kyu |