Realized I could optimize solution1() slightly by summing as I go.