我正在尝试创建一个函数,该函数将在给定列表的情况下查找 3 个相同和相邻的数字,用于我正在尝试实现的求解器。然后,如果有3个相同和相邻的数字,它将第1个和第3个相同的数字标记为'0',并将中间值设置为负数。
我想知道为什么这给了我一个错误。:
change xs = chnge xs []
where
chnge xs acc
| length xs <= 2 = [acc]
| (head xs == xs !! 1) && (head xs == xs !! 2) = [0, (xs !! 1)*(-1), 0] ++ tail xs
| otherwise = chnge (tail xs) (acc ++ head xs)