Advertisement
Guest User

Untitled

a guest
Jan 25th, 2015
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. def pajek(moves):
  2.     pos_x, pos_y = 0, 1
  3.     ver_axis = 1
  4.     hor_axis = 1
  5.  
  6.     cross_count = 0
  7.  
  8.     for x, y in moves:
  9.         pos_x += x
  10.         pos_y += y
  11.  
  12.     if pos_x < 0:
  13.         new_ver_axis = -1
  14.     else:
  15.         new_ver_axis = 1
  16.  
  17.     if pos_y < 0:
  18.         new_hor_axis = -1
  19.     else:
  20.         new_hor_axis = 1
  21.  
  22.     if ver_axis != new_ver_axis:
  23.         cross_count += 1
  24.         ver_axis = new_ver_axis
  25.  
  26.     if hor_axis != new_hor_axis:
  27.         cross_count += 1
  28.         hor_axis = new_hor_axis
  29.  
  30.     return cross_count
  31. print(pajek(([(2, 0), (-1, -2), (1, -1), (-5, 5)])))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement