-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
91 lines (76 loc) · 1.88 KB
/
test.py
File metadata and controls
91 lines (76 loc) · 1.88 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# num = 10000
# total = 300000
# print(num * 100 / total)
# num = [1, 5, 6, 3, 6, 8]
# print("Count 1 000 000: Number = %s" % (''.join(map(str, num))))
# print(1/7)
# arr = [1, 5, 10, 15, 20]
#
# for a in arr:
# print(arr)
# print(arr)
# arr[arr.index(a)] = a + 1
# print(a)
# arr[-1] = 0
#
# print(arr)
# a = "asdasds"
# b = list(a)
# print(a)
# print(b)
# print(''.join(b))
def is_pandigital(n):
n = str(n)
for i in range(1, len(n) + 1):
if str(i) not in n:
return False
return True
# print(is_pandigital(999999999))
from Scripts import is_prime
import time
def is_cyclic(n): # n must be str
n = str(n)
m = len(n)
init = n = list(n)
while n[0] == "0":
del n[0]
n = int(''.join(n))
# print("init(n) == %s" % init)
cyc = True
for i in range(2, m):
x = n * i
init_temp = list(str(x))
# print("init_temp) == %s" % init_temp)
y = init_temp
y.append(y.pop(0))
a = False
for i in range(1, len(y)):
if y == init:
a = True
# print(y)
break
y.append(y.pop(0))
if not a:
cyc = False
# print(y)
return cyc
# limit = 100000000
# pt = 0
# ct = 0
# for i in range(1, limit):
# if i % 100000 == 0:
# print("i = %s" % i)
# a = time.time()
# is_prime(i)
# b = time.time()
# prime = b - a
# print("is_prime(%s): %s seconds" % (i, prime))
# is_cyclic(i)
# c = time.time()
# cycle = c - b
# print("is_cyclic(%s): %s seconds" % (i, cycle))
# print("Fastest: %s" % ("cycle" if prime > cycle else "prime"))
# pt += 1 if cycle > prime else 0
# ct += 1 if cycle < prime else 0
# print("pt, ct = %s, %s" % (pt, ct))
# Gotta get better exceptions, maybe prime iirc. In test.py i tried it and primes are faster than cyclics 80% of time