snake logic