Nov-09-2019, 08:34 PM
(Nov-09-2019, 07:59 PM)Gribouillis Wrote: I see something! At the end of the script you forgot to close the file. UseHi!fhand.close()
instead offhand.close
. It may perhaps change something.
I was running the program and having the same result as mnh001, and when I changed the code as you suggested, the last lines of the txt file are then:
Output:3864, [-1575, -1296, 2880, 3600, -1215, -405, 189, 1026, -999, 0]
3865, [-1584, 0]
3866, [-1495, 1235, -429, 585, 162, 189, 1026, -999, 0]
3867, [-1440, 225, 81, 63, 27, -45, -9]
3868, [-1575, -1296, 2880, 3600, -1215, -405, 189, 1026, -999, 0]
3869, [-2080, 3600, -1215, -405, 189, 1026, -999, 0]
(Nov-09-2019, 08:09 PM)mnh001 Wrote: Ah, that did it. I totally forgot the parenthesis. Thanks.
I was having the same result as you on the txt file, but to have the same results in both the txt file and on screen, I had to do the change suggested by Gribouillis, but I also had to interchange the order of lines 44 and 45 (I don't know why or how, though):
import numpy as np # def mat(num_in, side): rows = [] A = [] for y in range(0, side): for x in range(0, side): rows.append(int(num_in[x])) A.append(rows) rows = [] rgt = num_in[side - 1:] temp = rgt for z in range(0, side - 1): temp = temp + num_in[z] num_in = str(temp) return A side = 4; side1 = side num_in = str(10**(side1 - 1)) hold = int(num_in) fhand = open("cd4.txt", "w") s = 0 chain = [] while int(hold) < 10**side1: while s == 0: A = mat(num_in, side) det = int(round(np.linalg.det(A))) if (det in chain or abs(det) in chain) or (det < 10 and det > -10): chain.append(det) break else: chain.append(det) num_in = str(abs(det)) side = len(num_in) hold += 1 num_in = str(hold) side = len(num_in) print(f'{hold - 1}, {chain}') fhand.write(f'{hold - 1}, {chain}\n') chain = [] fhand.close()With that last modification both the text file and the output on the screen are the same.
All the best,
newbieAuggie2019
"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs