-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumber_matrix.py
More file actions
52 lines (51 loc) · 4.69 KB
/
number_matrix.py
File metadata and controls
52 lines (51 loc) · 4.69 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
'''
Lot of print statements to debug. Number Matrix was a file given to me. It was a big matrix filled with numbers.
'''
inFile = open('number_matrix', 'r')
#list of products for me to maxamize
list_of_products = []
column = [] #column's list for products
number_of_iterations = 0
for line in inFile: #iterate throught file line by line
mystring = line #convertingline into string
mylist = mystring.split() #splitting the string into individual list indexes
#print (len(mylist))
#print (x)
row_counter = 0 #value of indexing
while row_counter < 17: #to index and not over index and to loop through the values over and over again
#find all possible products
product_of_numbers = int(mylist[row_counter])*int(mylist[row_counter+1])*int(mylist[row_counter+2])*int(mylist[row_counter+3])
list_of_products.append( (product_of_numbers,"row",int(mylist[row_counter]),int(mylist[row_counter+1]),int(mylist[row_counter+2]),int(mylist[row_counter+3])))
#increase index to allow for all products and so that we don't have a infinite loop
row_counter = row_counter + 1
number_of_iterations += 1
#print (max(list_of_products))
inFile.seek(0) #bring cursor back to the first line
column_counter = 0
#indexing for columns
for number in range(0,number_of_iterations):
#print (number)
for line in inFile: #iterate through the file line by line
newstring = line #convert line to string
#print (newstring)
newlist = newstring.split() #convert string to list
#print(newlist[int(number)])
#print ()
column.append(newlist[int(number)]) #add first index to the column list to find all possible products
#print (len(column))
#print (y) #debug
#print (len(column)) #debug
#print (column)
column_counter = 0
while column_counter < 17: #to index and not over index and to loop through the values over and over again
#find all possible products
#print (column_counter)
product_of_numbers = int(column[column_counter])*int(column[column_counter+1])*int(column[column_counter+2])*int(column[column_counter+3])
list_of_products.append((product_of_numbers, "col", int(column[column_counter]), int(column[column_counter+1]), int(column[column_counter+2]), int(column[column_counter+3]) ))
#increment by one to keep a finite loop
column_counter = column_counter + 1
column = []
inFile.seek(0)
#print ((column)) #debug
print (list_of_products)
print (max(list_of_products)) #max product