Last active
December 2, 2020 22:18
-
-
Save varokas/521d6b3f9006e399d511254d394d11a4 to your computer and use it in GitHub Desktop.
sum of digit power
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
-- Decompose Int to arrays of digits | |
digits :: Integral a => a -> [a] | |
digits x | |
| x < 10 = [x] | |
| otherwise = digits(x `div` 10) ++ [x `mod` 10] | |
-- x to the 4th | |
power4 x = x^4 | |
-- What is asked | |
[ x | x <- [0..9999], sum(map power4 (digits x)) == x ] | |
=> [0,1,1634,8208,9474] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment