|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
开发的算法(
- def PascalTriangle(limit:int) -> list:
- """
- limit
- 限制生成的层数
- 提示:如果你想无限生成杨辉三家的话,可使用下面这个
- """
- Result = [1]
- for times in range(int(limit)):
- yield Result
- _Product = [1]
- for i in range(0, len(Result)):
- if i + 1 > len(Result) - 1: #判断是否完成
- _Product.append(Result[0])
- break
- else:
- _Product.append(Result[i] + Result[i+1])
- Result = _Product
- def PascalTriangle_Loop() -> list:
- Result = [1]
- while True:
- yield Result
- _Product = [1]
- for i in range(0, len(Result)):
- if i + 1 > len(Result) - 1: #判断是否完成
- _Product.append(Result[0])
- break
- else:
- _Product.append(Result[i] + Result[i+1])
- Result = _Product
复制代码 |
|