-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathta1.py
executable file
·36 lines (31 loc) · 993 Bytes
/
ta1.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
#!/usr/bin/env python
from mpmath import mp
import random
from irradix import irradix, derradix, set_precision
set_precision(1000)
val = mp.mpf(10)
for i in range(1000):
basePhi = irradix(val)
regular = derradix(basePhi)
if regular != int(val):
print(f"Divergence at {i+2}-digit random value.")
vs = str(int(val))
rs = str(int(regular))
track = []
diff_places = []
for j in range(min(len(vs), len(rs))):
if vs[j] != rs[j]:
diff_places.append(j+1)
track.append('^')
else:
track.append(' ')
print(f"Original: {vs}")
print(f"Recovered: {rs}")
print(f" {''.join(track)}")
print(f"Values differ at places: {diff_places}")
input("Press Enter to continue...") # Pause for user input
else:
print(f"{i+2}-digit values match: {regular}")
digit = random.randint(0, 9)
val *= 10
val += digit