import pickle import math import code128 with open("width_arr.pkl", "rb") as f: width_arr = pickle.load(f) patterns = [(5, 5, 7, 4, 3, 2), (5, 4, 3, 4, 8, 2), (2, 5, 7, 4, 5, 3), (5, 5, 7, 5, 2, 2), (5, 5, 2, 3, 7, 4), (5, 2, 7, 5, 2, 5), (5, 4, 8, 4, 3, 2), (7, 5, 2, 2, 5, 5), (2, 5, 7, 5, 4, 3), (5, 5, 2, 2, 3, 9), (5, 5, 7, 2, 2, 5), (7, 2, 3, 4, 5, 5), (2, 5, 7, 5, 5, 2), (5, 4, 7, 5, 2, 3), (5, 4, 3, 2, 7, 5), (3, 4, 7, 5, 5, 2), (5, 4, 7, 5, 3, 2), (2, 5, 7, 2, 5, 5), (5, 2, 7, 5, 3, 4), (7, 2, 2, 5, 5, 5), (7, 5, 3, 2, 5, 4), (5, 5, 2, 5, 7, 2), (4, 5, 7, 5, 2, 3), (4, 5, 3, 2, 7, 5), (7, 2, 5, 2, 7, 3), (4, 5, 7, 3, 2, 5), (5, 5, 2, 2, 7, 5), (4, 3, 7, 5, 2, 5), (7, 3, 2, 5, 5, 4), (5, 4, 7, 3, 2, 5), (2, 5, 7, 3, 4, 5), (4, 3, 7, 4, 3, 5), (3, 5, 7, 4, 5, 2), (7, 4, 3, 2, 5, 5), (3, 4, 8, 4, 5, 2), (4, 5, 2, 3, 7, 5), (7, 3, 4, 3, 7, 2), (8, 2, 2, 5, 5, 4), (4, 5, 2, 5, 7, 3), (5, 4, 3, 5, 7, 2), (7, 2, 5, 3, 7, 2), (5, 4, 3, 4, 7, 3), (7, 3, 5, 2, 7, 2), (7, 2, 3, 5, 4, 5), (7, 2, 5, 2, 8, 2), (8, 4, 3, 2, 5, 4), (3, 5, 7, 2, 5, 4), (7, 5, 2, 3, 4, 5), (4, 5, 7, 2, 3, 5), (7, 3, 2, 5, 4, 5), (2, 2, 7, 3, 4, 8), (5, 2, 7, 2, 3, 7), (3, 9, 3, 4, 5, 2), (2, 10, 2, 5, 5, 2), (3, 2, 5, 9, 3, 4), (3, 9, 3, 2, 5, 4), (2, 10, 2, 3, 4, 5), (2, 10, 2, 2, 5, 5), (3, 2, 5, 9, 2, 5), (2, 9, 3, 2, 5, 5), (3, 9, 2, 5, 5, 2), (2, 10, 2, 5, 4, 3), (5, 4, 3, 2, 2, 10), (5, 5, 2, 3, 2, 9), (5, 4, 3, 2, 3, 9), (2, 9, 3, 5, 4, 3), (2, 9, 3, 4, 5, 3), (4, 5, 2, 3, 2, 10), (4, 5, 3, 2, 2, 10), (2, 3, 2, 5, 9, 5), (3, 2, 2, 5, 10, 4), (3, 9, 2, 3, 4, 5), (2, 2, 5, 10, 2, 5), (5, 2, 7, 3, 2, 7), (2, 3, 9, 5, 2, 5), (3, 2, 10, 4, 3, 4), (2, 2, 10, 5, 2, 5)] special_pattern = (5, 2, 5, 5, 4, 5) def segment_array_loop(data_list, segment_length=6): """Segments a list into sequences of the specified length.""" segments = [] for i in range(0, len(data_list), segment_length): # Slice the list from the current index 'i' up to 'i + segment_length' segment = tuple(data_list[i:i + segment_length]) segments.append(segment) return segments segments = segment_array_loop(width_arr, 6) first = None b_max = 0 b_min = 26 w_max = 0 w_min = 26 last_index_special = 0 b_values = set() w_values = set() for segment in segments: if segment in patterns and segment != first: b = segment[0]+segment[2]+segment[4] w = segment[1]+segment[3]+segment[5] b_values.add(b) w_values.add(w) if b + w != 26: print(segment) break print(f"{segment} : b = {b} : w = {w}") if b < b_min: b_min = b if b > b_max: b_max = b if w < w_min: w_min = w if w > w_max: w_max = w if first is None: first = segment print(f"b_min: {b_min}, b_max: {b_max}") print(f"w_min: {w_min}, w_max: {w_max}") for id, segment in enumerate(segments): if segment == special_pattern: distance = id - last_index_special print(f"Found special at {id} | Distance {distance} | {chr(distance)}") last_index_special = id print(f"bars: {b_values}") print(f"spaces: {w_values}") print(len([pattern for pattern in patterns if 10 not in pattern])) print(len(patterns)) scaled = [tuple(math.ceil(x / 3) for x in t) for t in segments] def tuple_to_str(t: tuple[int, ...]) -> str: return "".join(map(str, t)) strs = [tuple_to_str(s) for s in scaled] import codes keys = codes.CODE_DICT.keys() buf = "" for s in strs: if s in keys: buf += codes.CODE_DICT[s] with open("data.txt", "w") as f: f.write(buf)