Soluytion 1
Vectorized version with Numpy
Merge pull request #1 from jeudyx/master

Solution 1,
good to be merged