The algorithm implementation in Golang