List manipulation



  • Help me write a program that changes the elements of the list by the formula first.

    a[i]=a[i]+a[i-1] для i>0
    

    then removes all uneven elements that are less than the arithmetic mean.

    Didn't find how to index the list to the maximum that it was possible to add or remove anything from the element or add or remove a specific element:

    func (xs) = [ x+xs!!0 | x <- xs]
    


  • &quot; Indicating on the list &quot; is, in principle, possible, but I understand it is a very &quot; unfunctional path &quot; .


    Changes the elements of the list by the formula a[i]=a[i]+a[i-1] for igrad

    If the numbering begins at zero, for example:

    f [] = []
    f (x:xs) = x:(f1 x xs) where
      f1 _ [] = []
      f1 n (x:xs) = n+x : f1 (n+x) xs
    

    Verification:

    > f [1,2,3,4]
    [1,3,6,10]
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2