exercise algorithm