implement the stupid gnome algorithm