test

mail@pastecode.io avatar
unknown
python
7 months ago
1.9 kB
3
Indexable
Never
class Point:
    
    
    def __init__(self, x, y):
        self.x = x
        self.y = y
        
    def __str__(self) -> str:
        return f"{self.x},{self.y}"
        
    def confina(self, other_point):
        if isinstance(other_point, Point):
            if self.x-other_point.x == 1 or self.y-other_point.y == 1:
                print(f"point {self} share border with point {other_point}")
                return True
            else:
                print(f"{self}-{other_point} don't share border")
                return False
        else:
            raise TypeError("Wrong Object")
        
    def count_neighboring(self, points_list):
        count = 0
        for point in points_list:
            if self.confina(point):
                count += 1
        print(f"{self} has {count} neighboring point")
        return count
        
        
    def idoneo(self, points_list):
        conta_conf = self.count_neighboring(points_list)
        return True if conta_conf==1 else False

def main():
    marked_points = []
    steps = 4
    count = 0
    p = Point(0,0)
    marked_points.append(p)
    x, y = -1, -1
    for i in range(steps):
        for x in range(-i,i+2):
            for y in range(-i, i+2):
                if x != y:
                    p = Point(x,y)
                    print(p)
                    if p not in marked_points:
                        if p.idoneo(marked_points):
                            count+=1
                            marked_points.append(p)
                        # else:
                        #     print(f"punto {p} non idoneo")
                    else:
                        print(f"Point {p} already marked")
    for p in marked_points:
        print(f"Marked point: {p} ")
    print(f"Total marked point: {len(marked_points)}")
Leave a Comment