working code to generalize to multiple dimensions, along with a comparison
clean and organize code into a function; close #12