-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflip_order.py
More file actions
107 lines (102 loc) · 3.14 KB
/
Copy pathflip_order.py
File metadata and controls
107 lines (102 loc) · 3.14 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#from sage.all import next_prime, previous_prime
import csv
import pandas as pd
flip_num = pd.read_csv('prime_elliptic_order.csv', header=None, names=['a', 'b', 'prime', 'order'])
flip_array = []
def three_binary(a, b, order, arr):
#Getting minimum and maximum indices of array elements with same order
min_val = -1
change = False
max_val = len(arr) + 1
frozen_index = -1
min_index = 0
max_index = len(arr)
test_index = len(arr)//2
while(max_index - min_index != 1):
if(order < arr.iat[test_index, 2]):
max_index = test_index
frozen_index = max_index
elif(order == arr.iat[test_index, 2]):
max_index = test_index
if(not change):
test_index = (test_index + max_index)//2
change = True
else:
min_index = test_index
test_index = (max_index + min_index)//2
if(test_index == len(arr) - 1):
return -1
if(arr.iat[test_index, 2] != order):
test_index += 1
min_val = test_index
max_index = frozen_index
min_index = test_index
while(max_index - min_index != 1):
if(order < arr.iat[test_index, 2]):
max_index = test_index
else:
min_index = test_index
test_index = (max_index + min_index)//2
if(not(test_index + 1 == len(arr) or arr.iat[test_index + 1, 2] != order)):
test_index += 1
max_val = test_index
#Getting minimum and maximum indices of array elements with same a
frozen_index = max_index
change = False
min_val_2 = -1
max_val_2 = len(arr) + 1
min_index = min_val
max_index = max_val + 1
test_index = (min_index + max_index)//2
while(max_index - min_index != 1):
if(a < arr.iat[test_index, 0]):
max_index = test_index
frozen_index = max_index
elif(a == arr.iat[test_index, 0]):
max_index = test_index
if(not change):
frozen_index = max_index
change = True
else:
min_index = test_index
test_index = (max_index + min_index)//2
if(arr.iat[test_index, 0] != a):
test_index += 1
min_val_2 = test_index
max_index = frozen_index
min_index = test_index
while(max_index - min_index != 1):
if(a < arr.iat[test_index, 0]):
max_index = test_index
else:
min_index = test_index
test_index = (max_index + min_index)//2
if(not(test_index + 1 > max_val or arr.iat[test_index + 1, 0] != a)):
test_index += 1
max_val_2 = test_index
#Comparing b values are correct
true_index = -1
for ind in range(min_val_2, max_val_2+1):
if(arr.iat[ind, 1] == b):
true_index = ind
if(true_index != -1):
return arr.iloc[true_index]
else:
return true_index
def find_point(a, b, order, arr):
for i in range(0, len(arr)):
if(a == arr.iat[i, 0] and b == arr.iat[i, 1] and order == arr.iat[i, 2]):
return arr.iat[i, 3]
return -1
for i in range(0, len(flip_num)):
a = flip_num.iat[i, 0]
b = flip_num.iat[i, 1]
prime = flip_num.iat[i, 2]
order = flip_num.iat[i, 3]
if(prime >= order):
if(find_point(a, b, order, flip_num) == prime):
flip_array.append([a, b, prime, order])
print(a, b, prime, order)
with open('flip_order.csv', 'a', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerows(flip_array)