Let me know if you want some help understanding the code, there are quite a few different algorithms for this sketch.