我无法理解 DART 中生成的斐波那契代码的工作原理。
void main() async {
List<BigInt> lista = [];
final start = DateTime.now();
finobacciPOC(lista, BigInt.from(15000), BigInt.zero, BigInt.one);
print('lista');
final time_exec = start.difference(DateTime.now());
print("Calculate in time ${time_exec}");
}
void finobacciPOC(
List<BigInt> listResult, BigInt total, BigInt start, BigInt end) async {
BigInt sum = start + end;
await Future.delayed(Duration(microseconds: 1));
listResult.add(sum);
total = total - BigInt.one;
if (total == BigInt.zero) {
print(listResult);
return;
}
finobacciPOC(listResult, total, end, sum);
}
Run Code Online (Sandbox Code Playgroud)
仅当您保留延迟例程时(如果您想生成 15000 个序列),该代码才有效。如果删除延迟,将显示溢出错误。
我想了解这个场景是如何运作的。
dart ×1