algorithm implementation in golang