0 Replies - 1106 Views - Last Post: 18 November 2009 - 05:46 PM

#1 Raynes  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 614
  • View blog
  • Posts: 2,815
  • Joined: 05-January 09

Finding the middle of a list in Haskell

Posted 18 November 2009 - 05:46 PM

Description: Just copy and paste.This snippet returns the center of a list, which is 2 elements for an even length list, or 1 element for an odd length list.
middleList [email protected](_:_:_:_) = take (if odd n then 1 else 2) $ drop en xs
    where n = length xs
          en = if n < 5 then 1 else 2 * (n `div` 4)
middleList xs = xs

Is This A Good Question/Topic? 0
  • +

Page 1 of 1