mirror of
https://github.com/cedricbonhomme/Stegano.git
synced 2025-06-28 19:26:14 +02:00
Ackermann is now encapsulated in a generator.
This commit is contained in:
parent
1704aec690
commit
5694e5c806
2 changed files with 21 additions and 2 deletions
|
@ -118,14 +118,14 @@ def ackermann_naive(m: int, n: int) -> int:
|
|||
return ackermann(m - 1, ackermann(m, n - 1))
|
||||
|
||||
|
||||
def ackermann(m: int, n: int) -> int:
|
||||
def ackermann_fast(m: int, n: int) -> int:
|
||||
"""Ackermann number.
|
||||
"""
|
||||
while m >= 4:
|
||||
if n == 0:
|
||||
n = 1
|
||||
else:
|
||||
n = ackermann(m, n - 1)
|
||||
n = ackermann_fast(m, n - 1)
|
||||
m -= 1
|
||||
if m == 3:
|
||||
return (1 << n + 3) - 3
|
||||
|
@ -136,6 +136,13 @@ def ackermann(m: int, n: int) -> int:
|
|||
else:
|
||||
return n + 1
|
||||
|
||||
def ackermann(m: int) -> Iterator[int]:
|
||||
"""Ackermann written as a generator.
|
||||
"""
|
||||
n = 0
|
||||
while True:
|
||||
yield ackermann_fast(m, n)
|
||||
n += 1
|
||||
|
||||
def fibonacci() -> Iterator[int]:
|
||||
"""Generate the sequence of Fibonacci.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue