def create_accidental_mountains_graph(dir1, dir2): fig, ax = plt.subplots(figsize=(20, 20)) pts1 = get_pts(dir1) pts2 = get_pts(dir2) ax.plot(pts1, color='#013220', linewidth=5) ax.plot(pts2, color='green', linewidth=5) fig.savefig('day3_mountains.png')
def get_shortest_step_ct(dir1, dir2): """returns the shortest step count to intersection point between the paths described by the argument directions Args: dir1: list of directions for first path dir2: list of directions for second path Returns: the minimum number of steps required to get to an intersection point of the two paths """ pts1 = get_pts(dir1) pts2 = get_pts(dir2) intersections = get_intersections(pts1, pts2) return get_fewest_steps(pts1, pts2, intersections)
def create_wire_graph(dir1, dir2): # convert directions to points pts1 = get_pts(dir1) pts2 = get_pts(dir2) # separate x and y for each set x1 = [x[0] for x in pts1] y1 = [x[1] for x in pts1] x2 = [x[0] for x in pts2] y2 = [x[1] for x in pts2] # graph fig, ax = plt.subplots(figsize=(20, 20)) ax.plot(x1, y1, color='red', linewidth=5) ax.plot(x2, y2, color='green', linewidth=5) fig.savefig('day3_image.png')
def test_multidirections(): """Tests get_pts' ability to plot direction sequence """ assert get_pts(['R3', 'U3']) == [(0,0), (1,0), (2,0), (3,0), (3,1), (3,2), (3,3)], \ "Should be [(0,0), (1,0), (2,0), (3,0), (3,1), (3,2), (3,3)]"
def test_up(): """Tests get_pts's ability to plot upward directions """ assert get_pts(['U3']) == [(0,0), (0,1), (0,2), (0,3)], \ "Should be [(0,0), (0,1), (0,2), (0,3)]"
def test_left(): """Tests get_pts's abililty to plot leftward directions """ assert get_pts(['L3']) == [(0,0), (-1,0), (-2,0), (-3,0)], \ "Should be [(0,0), (0,1), (0,2), (0,3)]"
def test_right(): """Tests get_pts's abililty to plot rightward directions """ assert get_pts(['R3']) == [(0,0), (1,0), (2,0), (3,0)], \ "Should be [(0,0), (0,1), (0,2), (0,3)]"
def test_down(): """Tests get_pts's abililty to plot downward directions """ assert get_pts(['D3']) == [(0,0), (0,-1), (0,-2), (0,-3)], \ "Should be [(0,0), (0,1), (0,2), (0,3)]"