Skip to content

Instantly share code, notes, and snippets.

@connrs
Created November 16, 2016 09:35
Show Gist options
  • Save connrs/82d246675b173e90a72fe025155b9ea5 to your computer and use it in GitHub Desktop.
Save connrs/82d246675b173e90a72fe025155b9ea5 to your computer and use it in GitHub Desktop.
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