Created
December 14, 2019 20:25
-
-
Save bcalmac/fc183c244ab053c273c70c708f3da904 to your computer and use it in GitHub Desktop.
Determine the list of remainders of powers of a divided by b
This file contains 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
-- a^0 mod b is 1. Once we find the next power with a remainder of 1, the remainders will repeat. | |
-- Take from a list until the first element repeats | |
takeUntilFirstRepeats (x:xs) = x : takeWhile (/= x) xs | |
remaindersOfPowers a b = takeUntilFirstRepeats [a^i `mod` b | i <- [0..]] | |
-- Example | |
remaindersOfPowers 9 7 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment