Created
November 16, 2016 09:35
-
-
Save connrs/82d246675b173e90a72fe025155b9ea5 to your computer and use it in GitHub Desktop.
This file contains 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
module SqTr where | |
-- Make a square number | |
squareNumber :: Integer -> Integer | |
squareNumber = (^2) | |
-- Make a triangle numnber | |
triNumber :: Integer -> Integer | |
triNumber x = fromIntegral (round (x' * (x' + 1) * 0.5)) :: Integer | |
where x' = fromInteger x | |
stMatch x = squareNumber x == triNumber x | |
squares = [(x, x^2) | x <- [1..]] :: [(Int,Int)] | |
triangles = [(round x :: Int, round (x * (x + 1) * 0.5) :: Int) | x <- [1..]] | |
matches sqrs tris = [(x, y, s) | (x, s) <- sqrs, (y, t) <- tris, s == t] | |
squareTriangleNumbers = [(x,y) | x <- [1..], y <- [1..], stn x y == 0] | |
where stn x y = (2 * x^2) - (y^2) - y | |
-- | |
-- n^2 = m (m+1) | |
-- ------- | |
-- 2 | |
-- | |
-- | |
-- | |
-- 2n^2 = m^2 + m | |
-- | |
-- | |
-- 0 = 2n^2 - m^2 - m |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment