Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def pajek(moves):
- pos_x, pos_y = 0, 1
- ver_axis = 1
- hor_axis = 1
- cross_count = 0
- for x, y in moves:
- pos_x += x
- pos_y += y
- if pos_x < 0:
- new_ver_axis = -1
- else:
- new_ver_axis = 1
- if pos_y < 0:
- new_hor_axis = -1
- else:
- new_hor_axis = 1
- if ver_axis != new_ver_axis:
- cross_count += 1
- ver_axis = new_ver_axis
- if hor_axis != new_hor_axis:
- cross_count += 1
- hor_axis = new_hor_axis
- return cross_count
- print(pajek(([(2, 0), (-1, -2), (1, -1), (-5, 5)])))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement