I know it's a code review, but since you're chasing efficiency, here's how to calculate in O(1). Try it first in Excel... INT() is traditional TRUNC()/FLOOR() for positive integers Integer MOD(a,b) gives remainder after dividing a by b N is season number, h the height (at the end of that season) h = (2^(INT(N/2)+1)-1)*(1+INT(MOD(N,2))) Output N h 0 1 1 2 2 3 3 6 4 7 5 14 6 15 7 30