forked from kyclark/biofx_python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution1_list_closure.py
executable file
·60 lines (41 loc) · 1.5 KB
/
solution1_list_closure.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
""" Calculate Fibonacci """
import argparse
from typing import NamedTuple
class Args(NamedTuple):
""" Command-line arguments """
generations: int
litter: int
# --------------------------------------------------
def get_args() -> Args:
""" Get command-line arguments """
parser = argparse.ArgumentParser(
description='Calculate Fibonacci',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('gen',
metavar='generations',
type=int,
help='Number of generations')
parser.add_argument('litter',
metavar='litter',
type=int,
help='Size of litter per generation')
args = parser.parse_args()
if not 1 <= args.gen <= 40:
parser.error(f'generations "{args.gen}" must be between 1 and 40')
if not 1 <= args.litter <= 5:
parser.error(f'litter "{args.litter}" must be between 1 and 5')
return Args(generations=args.gen, litter=args.litter)
# --------------------------------------------------
def main() -> None:
""" Make a jazz noise here """
args = get_args()
def fib(n: int) -> int:
nums = [0, 1]
for _ in range(n - 1):
nums.append((nums[-2] * args.litter) + nums[-1])
return nums[-1]
print(fib(args.generations))
# --------------------------------------------------
if __name__ == '__main__':
main()