擅长:python、mysql、java
<p>这是一个有趣的问题。下面是一个没有递归的解决方案:</p>
<pre><code>>>> gears = [6,16,14,20,24,28]
>>> def distance(n, radius):
... return sum(gears[:n] + gears[1:n-1])
>>> distance(1, gears) == 6
True
>>> distance(2, gears) == 6 + 16
True
>>> distance(3, gears) == 6 + 16 + 16 + 14
True
>>> distance(4, gears) == 6 + 16 + 16 + 14 + 14 + 20
True
</code></pre>