My algorithm