opti use simple operation
This commit is contained in:
		| @ -23,17 +23,16 @@ def extract_map_data(lines: [str]): | ||||
| 		if (line == ""): | ||||
| 			break | ||||
| 		bozo = line.split() | ||||
| 		destination = int(bozo[0]) | ||||
| 		source_start = int(bozo[1]) | ||||
| 		length = int(bozo[2]) | ||||
| 		destination = int(bozo[0]) - int(bozo[1]) | ||||
| 		source_range = range(int(bozo[1]), int(bozo[1]) + length) | ||||
| 		lst.append({"destination": destination, "source_range": source_range}) | ||||
| 		lst.append([destination - source_start, source_start, source_start + length]) | ||||
| 	return lst | ||||
|  | ||||
| def translation(lst: list[dict], value: int): | ||||
| 	for map in lst: | ||||
| 		if value in map["source_range"]: | ||||
| 			value += map["destination"] | ||||
| 			break | ||||
| def translation(lst: list[[]], value: int): | ||||
| 	for dst, src_start, src_stop in lst: | ||||
| 		if src_start <= value <= src_stop: | ||||
| 			return(value + dst) | ||||
| 	return value | ||||
|  | ||||
| for i, line in enumerate(_lines): | ||||
| @ -48,7 +47,7 @@ def display_duration(interval_between_call, nb_total_values): | ||||
| 	diff = int(((current_time - old_time) / interval_between_call) * nb_total_values) | ||||
| 	print(f"{int(diff / 3600)}h {int(diff % 3600 / 60)}min {int(diff % 60)}s") | ||||
|  | ||||
| def do_all_convertions(lst_convertions: [[dict]], value): | ||||
| def do_all_convertions(lst_convertions: [[[]]], value): | ||||
| 	for i, tab_convertion in enumerate(convertions): | ||||
| 		value = translation(tab_convertion, value) | ||||
| 	return value | ||||
| @ -58,9 +57,8 @@ def get_min_in_range(lst_conversions, start, stop): | ||||
| 	i = start + 1; | ||||
| 	while (i != stop): | ||||
| 		if ((i - start) % 1000000 == 0): | ||||
| 			print(f"{int((i - start)/(stop - start))}% ({i - start}/{stop - start})") | ||||
| 			print(f"{int((i - start) * 100/(stop - start))}% ({i - start}/{stop - start})") | ||||
| 		value = do_all_convertions(lst_conversions, i) | ||||
| 		#print(min_value, value, min(value, min_value)) | ||||
| 		min_value = min(value, min_value) | ||||
| 		i += 1 | ||||
| 	return (min_value) | ||||
| @ -95,6 +93,7 @@ while (threading.active_count() != 1): | ||||
| 	print(values, threading.active_count() - 1) | ||||
| 	time.sleep(10) | ||||
|  | ||||
| print(values) | ||||
| _value = min(values) | ||||
|  | ||||
| print(_value) | ||||
		Reference in New Issue
	
	Block a user