function k_means(points, k):

   centers = choose_k_starting_centers(points, k)
   repeat until assignments stop changing:
      for point in points:
        assign point to its nearest center
      for center in centers:
        move center to the average of its assigned points

   return centers
