def get_next(board) hbest <- initialval best <- [] temp <- [] copy "board" into temp and best arrays for each column in "board" for each row in "board" if the row value is not currently at the column in "board" - store this row value in the column in "temp" array - find the score of this "temp" array - if this score is the best so far (or is the initial new board) - update the current best score - save this temp array as the current best after checking each row in this column, reset the temp column value to the original board. Check next column in "board" if best is [] return hbest and the original board array else return hbest and the new best array end get_next def sideways(board) Using a similar process as get_next(board) find another array with the same score as board, but is different from board Return this new array (or the original board if no new array is found) end sideways def main board <- [] generate random board and score this random board hbest, best <- get_next(board) while count < MAXVALUE and hbest > 0 hbest, best <- get_next(best) bestboards <- [] incr count if count >= 5 and hbest > 0 "Stuck, trying sideways move... " temp = [] newbest = [] copy best into temp array if bestboards.include?(best) put temp array into bestboards array hbest, newbest <- sideways(temp, best) if this newbest array is not in bestboards array, add to bestboards increment sidewayscount end if sidewayscount >= SOME VALUE STUCK, use some other process to mix up the board, for example swap consecutive board positions end end main