medium ai diff algorithm