Remove elements by index in haskell

后端 未结 8 852

I\'m new in haskell and I\'m looking for some standard functions to work with lists by indexes.

My exact problem is that i want to remove 3 elements after every 5. If i

8条回答
  •  无人共我
    2021-02-07 23:49

    Here is my solution:

    remElements step num=rem' step num
        where rem' _ _ []=[]
              rem' s n (x:xs)
                  |s>0 = x:rem' (s-1) num xs
                  |n==0 = x:rem' (step-1) num xs
                  |otherwise= rem' 0 (n-1) xs
    

    example:

    *Main> remElements 5 3 [1..20]
    [1,2,3,4,5,9,10,11,12,13,17,18,19,20]
    

提交回复
热议问题