|
5 | 5 | # import re
|
6 | 6 | import copy
|
7 | 7 |
|
8 |
| -filename = "data3_short.txt" |
| 8 | +filename = "data3.txt" |
9 | 9 |
|
10 | 10 | file = open(filename)
|
11 | 11 | filestr = file.read()
|
|
31 | 31 |
|
32 | 32 | maxcols = len(a_list[0])
|
33 | 33 |
|
34 |
| -ogen = c02 = None |
| 34 | +ogen = None |
35 | 35 | current_list = copy.deepcopy(a_list)
|
36 | 36 | for col in range(maxcols):
|
37 | 37 | zero_bits = one_bits = 0
|
38 |
| - #col = 0 |
39 | 38 | for row in current_list:
|
40 | 39 | if row[col] == "0":
|
41 | 40 | zero_bits += 1
|
42 | 41 | elif row[col] == "1":
|
43 | 42 | one_bits += 1
|
44 | 43 | if one_bits >= zero_bits:
|
45 |
| - most_common = 1 |
| 44 | + common = 1 |
46 | 45 | else:
|
47 |
| - most_common = 0 |
48 |
| - #col = 0 |
| 46 | + common = 0 |
49 | 47 | new_list = []
|
50 | 48 | for row in current_list:
|
51 |
| - if row[col] == str(most_common): |
| 49 | + if row[col] == str(common): |
52 | 50 | new_list.append(row)
|
53 |
| - print(f"new_list(col={col}):\n{new_list}") |
| 51 | + #print(f"new_list(col={col}):\n{new_list}") |
54 | 52 | if len(new_list) == 1:
|
55 | 53 | print(f"found entry, {new_list}")
|
56 | 54 | #found_ogen = new_list[0]
|
|
59 | 57 | current_list = copy.deepcopy(new_list)
|
60 | 58 | print(f"ogen = {ogen}")
|
61 | 59 |
|
| 60 | +co2 = None |
| 61 | +current_list = copy.deepcopy(a_list) |
| 62 | +for col in range(maxcols): |
| 63 | + zero_bits = one_bits = 0 |
| 64 | + for row in current_list: |
| 65 | + if row[col] == "0": |
| 66 | + zero_bits += 1 |
| 67 | + elif row[col] == "1": |
| 68 | + one_bits += 1 |
| 69 | + if one_bits < zero_bits: #### TODO: only diff, refactor into one function |
| 70 | + common = 1 # least common.... |
| 71 | + else: |
| 72 | + common = 0 |
| 73 | + new_list = [] |
| 74 | + for row in current_list: |
| 75 | + if row[col] == str(common): |
| 76 | + new_list.append(row) |
| 77 | + #print(f"new_list(col={col}):\n{new_list}") |
| 78 | + if len(new_list) == 1: |
| 79 | + print(f"found entry, {new_list}") |
| 80 | + #found_co2 = new_list[0] |
| 81 | + co2 = int(new_list[0],2) |
| 82 | + break |
| 83 | + current_list = copy.deepcopy(new_list) |
| 84 | +print(f"co2 = {co2}") |
| 85 | + |
| 86 | +print(f"mul = {ogen*co2}") |
| 87 | + |
| 88 | + |
| 89 | + |
62 | 90 | # print(f"gamma={gamma}, epsilon={epsilon}")
|
63 | 91 | # g1 = arraytostr(gamma)
|
64 | 92 | # e1 = arraytostr(epsilon)
|
|
0 commit comments