finished problem 23, might want to optimize.... takes a while