Created
December 11, 2020 06:54
-
-
Save Iainmon/f49e3524f751ecafb242925418db9fcb 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
| data List a = Cons a (List a) | Nil | |
| listA = Cons 0 (Cons 2 (Cons 4 Nil)) | |
| listB = Cons 1 (Cons 0 (Cons 1 Nil)) | |
| tentothe :: Double -> Double | |
| tentothe m = 10 ** m | |
| reduce :: List Double -> Double -> Double | |
| reduce (Cons n Nil) m = n * (tentothe m) | |
| reduce (Cons n l) m = (reduce l (m + 1)) + (n * (tentothe m)) | |
| construct :: Double -> Double -> List Double | |
| construct n m = Cons (extract n m) (if swallowed n (m + 1) then Nil else construct n (m + 1)) | |
| extract :: Double -> Double -> Double | |
| extract n m = dfloor (n/tentothe m) - (dfloor (n/tentothe (m+1)) * 10) | |
| dfloor :: Double -> Double | |
| dfloor = fromIntegral . floor | |
| -- extract' :: Double -> Double -> Double | |
| -- extract' n m = dfloor (n/tentothe m) - (dfloor (n/tentothe (m+1)) * 10) | |
| swallowed :: Double -> Double -> Bool | |
| swallowed n m = (n / tentothe m) < 1 | |
| sumLists a b = construct ((reduce a 0) + (reduce b 0)) 0 | |
| listToArray :: List a -> [a] | |
| listToArray (Cons e Nil) = [e] | |
| listToArray (Cons e l) = e : (listToArray l) | |
| main :: IO () | |
| -- main = print $ extract 1234 0 | |
| main = print $ listToArray $ sumLists listA listB |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment