wikipedia gray code
easy, be careful for the index change