def create_map_from_file(filepath): """Create map from file. Parameters: filepath (str): file path to load the map from Returns: Map: map """ from utilities import FileUtilities file_content = FileUtilities.get_sanitized_content_from_file(filepath) all_nodes = file_content.pop(0) car_node_name = file_content.pop(0) pet_nodes_name = file_content.pop(0).split(" ") house_nodes_names = file_content.pop(0).split(" ") m = MapFactory.create_map_from_node_names(car_node_name, pet_nodes_name, house_nodes_names) while file_content: conn_repr = file_content.pop(0).split(" ") node_source = m.get_node_by_name(conn_repr[0]) node_destination = m.get_node_by_name(conn_repr[1]) distance = int(conn_repr[2]) node_source.add_connection_to(node_destination, distance) node_destination.add_connection_to(node_source, distance) return m
from utilities import FileUtilities def get_frequency(instructions): frequency = 0 while len(instructions) > 0: frequency_change = int(instructions.pop(0)) frequency += frequency_change return frequency if __name__ == "__main__": input_file_path = "puzzle.in" file_content = FileUtilities.get_sanitized_content_from_file( input_file_path) print(get_frequency(file_content))