Training: Math Pyramid (Math, Training)
题目描述
This is the first release of a math challenge.
You have to come up with the shortest solution (9 chars or less) for a geometric function.
And the story goes like:Pharao momo wants a square-based pyramid, where all the eight edges are of the same length ‘a’.
Please support him with a formula to calculate the volume for a given side length.
Your co-workers already drew a sketch how the pyramid looks like from front-view:
Example Formula: a^3/3sqrt(aa)
Notation Hints: sqrt(), a^2, etc.Enjoy!
Thanks go out to momo for the idea, Jinx for testing, paipai for a copy of EvalMath and Miles Kaufmann for writing the EvalMath class.
这是第一个发布的数学挑战。
你必须为一个几何函数想出最短的解(9个字符或更少)。
故事是这样的:
法老莫莫想要一个方形的金字塔,八条边都是相同长度的“a”。
请给他一个公式来计算给定边长下的体积。
你的同事已经画了一幅从正面看金字塔的草图:
pyramid.png
公式:一个^ 3/3 * sqrt (*)
符号提示:sqrt(), a^2,等等。
享受吧!
感谢momo的想法,Jinx的测试,paipai的EvalMath副本和Miles Kaufmann编写的EvalMath类。
解
画一个图就能很快就算出体积了(我想象力不够)
直接百度体积计算公式也行。锥体积公式:
底面是边长a的正方形,底面积是a ^2,做两个直角三角形,
很容易求出高是
体积公式简化为
很容易得出sqrt(2)*a^3/6,但是题目有9字符的限制
简化:
- a^3/3*sqrt(2):13字符
- a^3/3*2^0.5:11字符 (python中就有类似的计算)
- a^3/18^0.5:10字符
- 18^-.5a^3:9字符 (0可以省略)