我非常接近这个,但我仍然陷入困境:/
txt :: String
txt = "[1] and [2] both feature characters who will do whatever it takes to " ++
"get to their goal, and in the end the thing they want the most ends " ++
"up destroying them. In case of [3] this is a whale..."
references :: String -> Int
split :: String -> [String]
split str = words str
find :: [String] -> [String]
find xs = [ x | x <- xs, x == "["++"1"++"]" ]
references x = length (find (split x ))
我需要找到时间段[n]
出现在n
为数字0
的字符串中。
在上面的例子中n = 3
。
我似乎无法编写谓词来捕获括号"[1]"
或"[3]"
括起来的所有数字。
(我在这里的代码中硬编码1)