Created
November 8, 2016 16:17
-
-
Save lovasoa/0e52bcbc937f3d26224f303669ca2b0f to your computer and use it in GitHub Desktop.
Modular multiplicative inverse in Haskell
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
-- Inverses a modulo b | |
inverse b a = | |
let | |
next a b = zipWith (-) a $ map (*(head $ zipWith div a b)) b | |
l = [a,0] : [b,1] : zipWith next l (tail l) | |
in | |
head $ tail $ head $ filter ((==1).head) l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment