Irw*_*wan 2 algorithm indexing haskell
我现在开始学习 haskell,但我遇到了一个案例,我找不到解决方案来解决它
案件:
list = [4, 9, 2, 4, 2]
想成为:
list = [4, 18, 2, 8, 2]
这就像只在奇数索引上乘以 2,我们可以在 Haskell 中做到这一点吗?
id您可以创建一个与 和(2*)交错的无限列表cycle [id, (2*)],然后我们使用以下方法将这些函数应用于元素zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]:
zipWith ($) (cycle [id, (2*)]) [4, 9, 2, 4, 2]Run Code Online (Sandbox Code Playgroud)