@SnoopJeDi/

SugaryAlertListeners

Python

No description

fork
loading
Files
  • main.py

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.8287382652164406","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"IiIiCkEgc2ltcGxlIGNsYXNzIGZvciB0aGUgdHJhdmVsaW5nIHNhbGVzbWFuIHByb2JsZW0sIGJhc2VkIG9uIGEgcXVlc3Rpb24KaW4gI3B5dGhvbiBvbiBmcmVlbm9kZSBvbiBPY3QgMzEsIDIwMTguCiIiIgoKaW1wb3J0IGl0ZXJ0b29scwoKY2xhc3MgQ2l0eToKICAgICIiIiBSZXByZXNlbnRzIGEgY2l0eSBhdCB0aGUgcG9zaXRpb24gYCh4LCB5KWAgIiIiCiAgICBkZWYgX19pbml0X18oc2VsZiwgeCwgeSwgbmFtZSk6CiAgICAgICAgc2VsZi54ID0geAogICAgICAgIHNlbGYueSA9IHkKICAgICAgICBzZWxmLm5hbWUgPSBuYW1lCgogICAgZGVmIF9fc3RyX18oc2VsZik6CiAgICAgICAgcmV0dXJuIHNlbGYubmFtZQogICAgICAKICAgIGRlZiBfX3N1Yl9fKHNlbGYsIG90aGVyKToKICAgICAgICAiIiIgQ2FsY3VsYXRlIHRoZSBFdWNsaWRlYW4gZGlzdGFuY2UgYmV0d2VlbiB0d28gQ2l0eSBvYmplY3RzICIiIgogICAgICAgIHJldHVybiAoKHNlbGYueCAtIG90aGVyLngpKioyICsgKHNlbGYueSAtIG90aGVyLnkpKioyKSoqMC41CgpjaXRpZXMgPSBbCiAgQ2l0eSgxLCAyLCAnQScpLAogIENpdHkoMywgNCwgJ0InKSwKICBDaXR5KDUsIDYsICdDJyksCl0KCmZvciBjMSwgYzIgaW4gaXRlcnRvb2xzLmNvbWJpbmF0aW9ucyhjaXRpZXMsIDIpOgogIHByaW50KGYnRGlzdGFuY2UgYmV0d2VlbiB7YzF9IGFuZCB7YzJ9IGlzIHtjMS1jMjouMmZ9Jyk="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
A simple class for the traveling salesman problem, based on a question
in #python on freenode on Oct 31, 2018.
"""

import itertools

class City:
    """ Represents a city at the position `(x, y)` """
    def __init__(self, x, y, name):
        self.x = x
        self.y = y
        self.name = name

    def __str__(self):
        return self.name
      
    def __sub__(self, other):
        """ Calculate the Euclidean distance between two City objects """
        return ((self.x - other.x)**2 + (self.y - other.y)**2)**0.5

cities = [
  City(1, 2, 'A'),
  City(3, 4, 'B'),
  City(5, 6, 'C'),
]

for c1, c2 in itertools.combinations(cities, 2):
  print(f'Distance between {c1} and {c2} is {c1-c2:.2f}')