Created
October 12, 2021 18:27
-
-
Save joe-warren/be54367d3405a1d8f48093aef1277594 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Data.List (minimumBy) | |
| import Data.Function (on) | |
| nearestInc :: Int -> [Int] -> Int | |
| nearestInc n xs = | |
| case span (<n) xs of | |
| ([], h:_) -> h | |
| (ss, []) -> last ss | |
| (ss, l:_) -> minimumBy (compare `on` abs . (`subtract` n)) [last ss, l] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment