Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. def move(old_pos, throw):
  2.     pos = old_pos + int(throw)
  3.     ladder = False
  4.     l = {3:17, 8:10, 15:44, 22:5, 39:56, 49:75, 62:45, 64:19, 65:73, 80:12, 87:79}
  5.     if pos in l:
  6.         pos = l.get(pos)
  7.         ladder = True
  8.     elif pos > 90:
  9.         pos = old_pos
  10.     return [pos, ladder]
  11.  
  12.  
  13. if __name__ == "__main__":
  14.     ppos = [1] * 1337
  15.     player = 0
  16.     ladders = 0
  17.     cur_pos = [0, False]
  18.     with open('input8_knowit.txt') as file:
  19.         for line in file:
  20.             cur_pos = move(ppos[player], line)
  21.             ppos[player] = cur_pos[0]
  22.             if ppos[player] == 90:
  23.                 print("player:", player+1, "ladders:", ladders, (player+1)*ladders)
  24.             ladders += cur_pos[1]
  25.             player = (player+1) % 1337
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement