My original code--written in C--was about 6 lines long.