Skip to content

Instantly share code, notes, and snippets.

@nvanderw
Created June 21, 2012 02:18
Show Gist options
  • Save nvanderw/2963459 to your computer and use it in GitHub Desktop.
Save nvanderw/2963459 to your computer and use it in GitHub Desktop.
Exercise Set 7.1
import System.Environment
sumSquares :: (Integral a) => a -> a
sumSquares n = n*(n+1)*(2*n+1) `div` 6
sumCubes :: (Integral a) => a -> a
sumCubes n = ((n^2 + n) `div` 2)^2
main = do
args <- getArgs
let limit = read (head args) :: Int
putStrLn $ "The sum of squares is " ++ (show $ sumSquares limit)
putStrLn $ "The sum of cubes is " ++ (show $ sumCubes limit)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment