It always adds up to the number of sides!
That's fascinating. I don't think I have the time to prove it right now, though. That being said, I think my algorithm is working because it was discovering this pattern :)
I also don't know how you go about decomposing
into the individual length components.