optimize ux
This commit is contained in:
BIN
chapter-03/dedekint/__pycache__/dedekint.cpython-313.pyc
Normal file
BIN
chapter-03/dedekint/__pycache__/dedekint.cpython-313.pyc
Normal file
Binary file not shown.
6
chapter-03/dedekint/dedekint.py
Normal file
6
chapter-03/dedekint/dedekint.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from collections.abc import Callable
|
||||
from gmpy2 import mpq
|
||||
|
||||
|
||||
class REAL:
|
||||
def __init__(self, f: Callable[[mpq], bool]): self.smaller=f
|
||||
26
chapter-03/dedekint/main.py
Normal file
26
chapter-03/dedekint/main.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from dedekint import REAL
|
||||
# mpq for rational numbers
|
||||
from gmpy2 import mpq
|
||||
|
||||
|
||||
def sqrt_two(q):
|
||||
if q <= 0 or q * q < 2: return True
|
||||
return False
|
||||
|
||||
|
||||
x = REAL(sqrt_two)
|
||||
|
||||
print("1.41422 is smaller:", x.smaller(mpq(141422, 100000)))
|
||||
print("1.41421 is smaller:", x.smaller(mpq(141421, 100000)))
|
||||
|
||||
k = 0
|
||||
n = 1
|
||||
z = 0
|
||||
|
||||
for k in range(100):
|
||||
if x.smaller(mpq(z, n)):
|
||||
z = z + 1
|
||||
else:
|
||||
print(z, "/", n)
|
||||
z = (z - 1) * 10
|
||||
n = n * 10
|
||||
Reference in New Issue
Block a user