Created
April 30, 2013 22:19
-
-
Save teamdandelion/5492378 to your computer and use it in GitHub Desktop.
Prints lists of numbers which are the sum of two powers of a given base
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
isPowerSum :: Int -> Int -> Bool | |
isPowerSum p x= any (==x) [a + b | a <- shortPows, b <- shortPows] where | |
shortPows = takeWhile (<x) . map (p^) $ [0..] | |
powerSequence :: Int -> [Int] | |
powerSequence p = filter (isPowerSum p) [1..] | |
sq1 = take 20 . powerSequence $ 2 | |
sq2 = take 20 . powerSequence $ 3 | |
sq3 = take 20 . powerSequence $ 5 | |
sq4 = take 20 . powerSequence $ 7 | |
main :: IO() | |
main = do | |
print sq1 | |
print sq2 | |
print sq3 | |
print sq4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment