Rewrite k-means by using builtins only.