add implementation using permutations