Simulations of dynamically triangulated gravity - an algorithm for arbitrary dimension