One algorithm immediately comes to mind, although optimization can be done if the time problem is complex.
2x2 ( , ), 8 , (, -, , , , -, , -).
( pass by value, "current_string" ):
find(position, direction, current_string){
new_letter = m[0, position + direction];
if(!current_string.Contains(new_letter)){
current_string += new_letter;
find(position, (0, 1), current_string);
find(position, (1, 1), current_string);
find(position, (1, 0), current_string);
find(position, (1, -1), current_string);
find(position, (0, -1), current_string);
find(position, (-1, -1), current_string);
find(position, (-1, 0), current_string);
find(position, (-1, 1), current_string);
} else {
print current_string;
}
}
, " + , , current_string ".
, , , ( , Snake).
( if(!current_string.Contains(new_letter)){), O (1) , . n , cn n, c - .