Implementation of Dawkin's "Weasel" algorithm