First unoptimized version of problem 23