Single letter swaps
Write a function that takes a sequence of strings and a target string. For each string in the sequence, determine if it is equal to the target string after exactly one letter swap. Return the sequence of letter pairs that are swapped, or nil if it doesn't exist.
Example
(letter-swaps ["bacd" "abdc" "abcde" "abcc" "abcd"] "abcd")
;=> [#{\a \b} #{\c \d} nil nil nil]
Swapping a and b in "bacd" gives you the target string. Swapping c and d in "abdc" gives you the target string. But there is no way to swap to get an extra e. And trading a d for a c is not possible. Finally, the last string has no swaps, and exactly one is required.
Thanks to this site for the problem idea, where it is rated Very Hard in PHP. The problem has been modified.
Please submit your solutions as comments on this gist.
To subscribe: https://purelyfunctional.tv/newsletter/
Solution in haskell-
A little change to use T.Text instead-