A Hugo incarnation of the blog.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TakeMax.hs 588B

123456789101112131415161718192021
  1. takeUntilMax :: [Int] -> Int -> (Int, [Int])
  2. takeUntilMax [] m = (m, [])
  3. takeUntilMax [x] _ = (x, [x])
  4. takeUntilMax (x:xs) m
  5. | x == m = (x, [x])
  6. | otherwise =
  7. let (m', xs') = takeUntilMax xs m
  8. in (max m' x, x:xs')
  9. doTakeUntilMax :: [Int] -> [Int]
  10. doTakeUntilMax l = l'
  11. where (m, l') = takeUntilMax l m
  12. takeUntilMax' :: [Int] -> Int -> (Int, [Int])
  13. takeUntilMax' [] m = (m, [])
  14. takeUntilMax' [x] _ = (x, [x])
  15. takeUntilMax' (x:xs) m
  16. | x == m = (maximum (x:xs), [x])
  17. | otherwise =
  18. let (m', xs') = takeUntilMax' xs m
  19. in (max m' x, x:xs')