在用户输入字符串然后将输入的一部分与第二个输入进行比较时,我将如何编写代码。例如;两个数字共享相同的1-4数字,因此123456和123467的输出相同,但是123456和134567的输出却不同。
答案 0 :(得分:-1)
看看Data.List。有很多有用的功能。您的特定功能可能如下所示:
import Data.List
shares4 :: String -> String -> Bool
shares4 s1 s2 =
any (\s -> isSubsequenceOf s s2) -- we check if any of subsequences of first string are in the second
$ filter (\s -> length s == 4) -- we take only those that are 4 chars long
$ subsequences s2 -- returns all possible subsequences of a string