Instantly share code, notes, and snippets.
Does not work... because of "xrange" is not defined, my notebook said.
@Kay1223: It should work fine with Python 2.7
To make this work in Python 3, replace all xrange with range (3 replacements) and also replace length/2 with length//2. Then it works fine in Python 3.8.