roughly write principle algorithm