美文网首页
hailstone 递归实现

hailstone 递归实现

作者: 一行数师 | 来源:发表于2018-11-05 21:04 被阅读18次
image.png
def hailstone(n):
    a = [n]
    if n <= 1:
        return [1]
    elif n % 2 == 0:
        a.extend(hailstone(int(n / 2)))
        return a
    else:
        a.extend(hailstone(3 * n + 1))
        return a
c = hailstone(10)
print(c)

相关文章

网友评论

      本文标题:hailstone 递归实现

      本文链接:https://www.haomeiwen.com/subject/vbsexqtx.html