simple python version
Fixed problem with double counting. Also added ruby version