tried a really complex semi-recursive solution before I realized I read the problem wrong