SaveText.Ru

Без имени
  1. var s=[
  2. '15',
  3. 'Bendigo 90 46 Shaoyang Sirohi Lima Tocuyito',
  4. 'Budingen 86 36 Shaoyang Pushkar Plymouth Sangzhi',
  5. 'Concord 78 3 Shaoyang Conway Sangzhi',
  6. 'Shaoyang 55 92 Bendigo Concord Conway Budingen Pushkar Plymouth',
  7. 'Tocuyito 26 14 Madras Bendigo',
  8. 'Sangzhi 82 61 Bayswater Sirohi Concord Budingen',
  9. 'Conway 49 20 Lima Madras Concord Shaoyang',
  10. 'Bayswater 52 44 Sangzhi Pushkar Plymouth',
  11. 'Chinhoyi 39 43 Lima Madras',
  12. 'Sirohi 54 65 Bendigo Sangzhi',
  13. 'Lima 83 75 Chinhoyi Conway Bendigo',
  14. 'Madras 97 85 Chinhoyi Pushkar Tocuyito Conway',
  15. 'Sojat 64 79 Plymouth',
  16. 'Pushkar 57 59 Madras Plymouth Bayswater Budingen Shaoyang',
  17. 'Plymouth 24 56 Pushkar Sojat Budingen Bayswater Shaoyang',
  18. 'Sirohi Pushkar',
  19. ]
  20. var graph={}
  21. var rs=(a,b)=>Math.sqrt((graph[a].x-graph[b].x)**2+(graph[a].y-graph[b].y)**2)
  22. var visited = []
  23. var len=+s.shift()
  24. var [start,stop]=s.pop().split(' ')
  25. s.forEach(f=>{
  26. var e=f.split(' ')
  27. graph[e[0]]=
  28. {name:e[0],x:+e[1], y:+e[2], list:e.slice(3)}
  29.  
  30.  
  31. })
  32. console.log(len, start,stop, graph)
  33.  
  34. //while true {
  35. var cc=start
  36. var l=graph[start].list.filter(x=>!visited.includes(x))
  37. var bl=l.sort((a,b)=>rs(cc,a)<rs(cc,b))
  38.  
  39. console.log(l)
  40. console.log(bl)
  41. console.log(rs(start,stop))
  42.  
  43.  
  44.  
  45.  
  46. //}

Share with your friends:

Print