Advertisement
banovski

Ninety-Nine Haskell Problems: #2

Feb 19th, 2024 (edited)
2,082
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haskell 0.35 KB | Source Code | 0 0
  1. one xs = xs !! (length xs - 2)
  2.  
  3. two xs = reverse xs !! 1
  4.  
  5. three = aux
  6.   where
  7.     aux [x,y] = x
  8.     aux (x:xs) = aux xs
  9.  
  10. four xs = aux xs (length xs)
  11.   where
  12.     aux xs 2 = head xs
  13.     aux (x:xs) l = aux xs (l - 1)
  14.  
  15. five xs = snd . head . filter (\(x, _) -> x == 1) $ zip (reverse xs) [0 ..]
  16.  
  17. six = head . tail . reverse
  18.  
  19. seven = last . init
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement