optimize ux
This commit is contained in:
11
chapter-03/binseq/binseq.py
Normal file
11
chapter-03/binseq/binseq.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from collections.abc import Callable
|
||||
|
||||
class REAL:
|
||||
def __init__(self, f: Callable[[int], str]) -> None:
|
||||
self.binseq = f
|
||||
|
||||
def as_string(self, w: int) -> str:
|
||||
s = ""
|
||||
for n in range(w):
|
||||
s += self.binseq(n)
|
||||
return s
|
20
chapter-03/binseq/main.py
Normal file
20
chapter-03/binseq/main.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from binseq import REAL
|
||||
from math import isqrt # integer sqrt
|
||||
|
||||
|
||||
def one_third(n):
|
||||
if n == 1: return "."
|
||||
if n % 2 == 0: return "0"
|
||||
return "1"
|
||||
|
||||
|
||||
def irrational(n):
|
||||
if n == 1: return "."
|
||||
if n != isqrt(n) * isqrt(n): return "1"
|
||||
return "0"
|
||||
|
||||
|
||||
x = REAL(one_third)
|
||||
y = REAL(irrational)
|
||||
|
||||
print("x: " + x.as_string(50) + "\ny: " + y.as_string(50))
|
Reference in New Issue
Block a user