-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_triple_mols_existence.py
64 lines (57 loc) · 1.64 KB
/
check_triple_mols_existence.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
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
# Created on: 4 Oct 2024
# Author: Oleg Zaikin
# E-mail: [email protected]
#
# Given a file with Latin squares, check if a triple of MOLS can be formed
# based on them.
#=============================================================================
import sys
script = "check_triple_mols_existence.py"
version = "0.0.1"
def count_orthogonal_cells(ls1 : list, ls2 : list):
ordered_pairs_set = set()
for i in range(len(ls1)):
for j in range(len(ls1[i])):
ordered_pairs_set.add(ls1[i][j] + ls2[i][j])
#print(ordered_pairs_set)
return len(ordered_pairs_set)
### Main function:
print(script + ' of version ' + version + ' is running')
if len(sys.argv) == 2 and sys.argv[1] == '-v':
exit(1)
if len(sys.argv) < 2:
print('Usage : ' + script + ' ls-file')
exit(1)
fname = sys.argv[1]
latin_squares = []
with open(fname, 'r') as f:
lines = f.read().splitlines()
for line in lines:
line = line.rstrip()
#print(line)
assert(len(line) == 100)
ls = []
for i in range(10):
row = []
for j in range(10):
row.append(line[i*10 + j])
#print(row)
ls.append(row)
latin_squares.append(ls)
#print('')
print(str(len(latin_squares)) + ' Latin squares')
ls_num = len(latin_squares)
orth_pairs_num = 0
max_orth_num = -1
for i in range(ls_num - 1):
if i > 0 and i % 100 == 0:
print(str(i) + ' squares processed')
for j in range(i+1, ls_num):
orth_num = count_orthogonal_cells(latin_squares[i], latin_squares[j])
if orth_num > max_orth_num:
max_orth_num = orth_num
print('max_orth_num : ' + str(max_orth_num))
if orth_num == 100:
orth_pairs_num += 1
print(str(orth_pairs_num) + ' orthogonal pairs so far.')
#print(str(orth_num))