Skip to content

Instantly share code, notes, and snippets.

@varokas
Last active December 2, 2020 22:18
Show Gist options
  • Save varokas/521d6b3f9006e399d511254d394d11a4 to your computer and use it in GitHub Desktop.
Save varokas/521d6b3f9006e399d511254d394d11a4 to your computer and use it in GitHub Desktop.
sum of digit power
-- 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