Beginner Solution

best case so far: 45 seconds for an array of 12.