Created
January 23, 2019 09:53
-
-
Save gaxiiiiiiiiiiii/00c6a9f7096e033a2ebbf007955ec96b 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
| findRoot :: Float -> Float -> Float | |
| findRoot digit n = find n candidate | |
| where scale = 10 ** digit | |
| candidate = map (/ scale) [1..(n * scale)] | |
| find :: Float -> [Float] -> Float | |
| find _ [x] = x | |
| find n xs | (target ** 2) >= n = find n smaller | |
| | otherwise = find n bigger | |
| where mid = (length xs) `div` 2 | |
| (smaller,bigger) = splitAt mid xs | |
| target = last smaller |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment