Skip to content

Instantly share code, notes, and snippets.

@av-ast
Last active December 24, 2015 16:59
Show Gist options
  • Save av-ast/6832356 to your computer and use it in GitHub Desktop.
Save av-ast/6832356 to your computer and use it in GitHub Desktop.
Function to count sum of squares
module M where
sum_of_squares :: Int -> Int
sum_of_squares n = sum . filter odd . map(^2) $ take n [1..]
sum_of_squares_dotless :: Int -> Int
sum_of_squares_dotless = sum . filter odd . map(^2) . (enumFromTo 1)
main :: IO()
main = do
print (x1, x2, x1 == x2) where
x1 = sum_of_squares n
x2 = sum_of_squares_dotless n
n = 1000
--------------------
1:18 ava@ava:~>runghc M.hs
(166666500,166666500,True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment