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:

figure

(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.

distance

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

More By Author:

Check out these other kata created by polluxCast0r

Stats:

CreatedAug 15, 2018
PublishedAug 15, 2018
Warriors Trained293
Total Skips3
Total Code Submissions1404
Total Times Completed125
Python Completions114
Ruby Completions19
Total Stars6
% of votes with a positive feedback rating81% of 52
Total "Very Satisfied" Votes36
Total "Somewhat Satisfied" Votes12
Total "Not Satisfied" Votes4
Total Rank Assessments24
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • polluxCast0r Avatar
  • anter69 Avatar
  • FArekkusu Avatar
  • dfhwze Avatar
  • Fuzzi Avatar
Ad