If anyone has any tips on how to improve it feel free to share. The source is available at https://github.com/zcr1/hn-markov