A Hugo incarnation of the blog.
https://danilafe.com
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.
21 lines
588 B
21 lines
588 B
takeUntilMax :: [Int] -> Int -> (Int, [Int]) |
|
takeUntilMax [] m = (m, []) |
|
takeUntilMax [x] _ = (x, [x]) |
|
takeUntilMax (x:xs) m |
|
| x == m = (x, [x]) |
|
| otherwise = |
|
let (m', xs') = takeUntilMax xs m |
|
in (max m' x, x:xs') |
|
|
|
doTakeUntilMax :: [Int] -> [Int] |
|
doTakeUntilMax l = l' |
|
where (m, l') = takeUntilMax l m |
|
|
|
takeUntilMax' :: [Int] -> Int -> (Int, [Int]) |
|
takeUntilMax' [] m = (m, []) |
|
takeUntilMax' [x] _ = (x, [x]) |
|
takeUntilMax' (x:xs) m |
|
| x == m = (maximum (x:xs), [x]) |
|
| otherwise = |
|
let (m', xs') = takeUntilMax' xs m |
|
in (max m' x, x:xs')
|
|
|