SHARE
TWEET

Untitled

a guest Dec 5th, 2019 116 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sets
  2. import math
  3.  
  4. # results = sets.Set()
  5.  
  6. #def get_my_orbits(k, cur_count, orbit_map):
  7. #   if k in orbit_map:
  8. #       #print k
  9. #       return get_my_orbits(orbit_map[k], cur_count + 1, orbit_map)
  10. #   else:
  11. #       return cur_count
  12.  
  13. def get_orbs(k, orbit_map):
  14.     results = []
  15.     cur = k
  16.     while cur != 'COM':
  17.         results.append(cur)
  18.         cur = orbit_map[cur]
  19.     return results
  20.  
  21.  
  22. f = open('5_1_input.txt')
  23.  
  24. lines = f.readlines()
  25. print len(lines)
  26.  
  27. orbit_map = {}
  28.  
  29. for line in lines:
  30.     orbiting = line.split(')')[0]
  31.     orbiter = line.split(')')[1][:-1]
  32.     if orbiter in orbit_map:
  33.         print 'SHIT'
  34.         break
  35.     orbit_map[orbiter] = orbiting
  36.  
  37. #print len(orbit_map)
  38. #print orbit_map
  39.  
  40. #total = 0
  41. #for k in orbit_map:
  42. #   total += get_my_orbits(k, 0, orbit_map)
  43. #
  44. #print total
  45.  
  46. mine = get_orbs('YOU', orbit_map)
  47. santa = get_orbs('SAN', orbit_map)
  48.  
  49. print mine
  50. print santa
  51.  
  52. for i in range(2, len(mine)):
  53.     if mine[i] in santa:
  54.         print mine[i]
  55.         print i
  56.         print santa.index(mine[i])
  57.         print i + santa.index(mine[i]) - 2
  58.         break
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top