tail recursive version of contiguous sum without using any vars