Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
wikipedia solution in Clear category for Humpty Dumpty Form by Alf_
import math
sqrt = math.sqrt
sqr = lambda a:a*a
cubed = lambda a:a*a*a
arcsin = math.asin
pi = math.pi
atanh = math.atanh
#from http://en.wikipedia.org/wiki/Sphere
def sphere_volume(r):
return 4*pi*cubed(r)/3
def sphere_area(r):
return 4*pi*sqr(r)
#from http://en.wikipedia.org/wiki/Spheroid
def prolate_spheroid_area(c, a):
e = sqrt(1-sqr(a)/sqr(c))
return 2*math.pi*sqr(a)*(1+(c*arcsin(e))/(a*e))
def prolate_spheroid_volume(c, a):
return 4*pi/3 * sqr(a) * c
def oblate_spheroid_area(c,a):
e = sqrt(1-sqr(c)/sqr(a))
return 2*math.pi*sqr(a)*(1+(1-sqr(e))/e*atanh(e))
oblate_spheroid_volume = prolate_spheroid_volume
def checkio(height, width):
if height == width:
r = height/2
return [sphere_volume(r), sphere_area(r)]
c = height/2
a = width/2
if height > width:
return [prolate_spheroid_volume(c, a), prolate_spheroid_area(c,a)]
else:
return [oblate_spheroid_volume(c, a), oblate_spheroid_area(c,a)]
Feb. 11, 2014
Comments: