Skip to content

Instantly share code, notes, and snippets.

@varokas
Last active December 2, 2020 22:18
Show Gist options
  • Select an option

  • Save varokas/521d6b3f9006e399d511254d394d11a4 to your computer and use it in GitHub Desktop.

Select an option

Save varokas/521d6b3f9006e399d511254d394d11a4 to your computer and use it in GitHub Desktop.

Revisions

  1. varokas revised this gist Dec 2, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions sum.hs
    Original file line number Diff line number Diff line change
    @@ -4,8 +4,10 @@ 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]
  2. varokas revised this gist Dec 2, 2020. No changes.
  3. varokas created this gist Dec 2, 2020.
    11 changes: 11 additions & 0 deletions sum.hs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    -- Decompose Int to arrays of digits
    digits :: Integral a => a -> [a]
    digits x
    | x < 10 = [x]
    | otherwise = digits(x `div` 10) ++ [x `mod` 10]

    power4 x = x^4

    [ x | x <- [0..9999], sum(map power4 (digits x)) == x ]

    => [0,1,1634,8208,9474]