my algorithm work in python