solution to circular-buffer exercise