SHARE
TWEET

liney thing

Spiritreader Dec 11th, 2019 (edited) 137 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. uniqueVec :: Integer -> [(Integer, Integer, Bool)]
  2. uniqueVec limit = map (isUnique 0) candidates
  3.     where
  4.         candidates = [(x,y) | x <- [1..limit], y <- [1..limit], x /= y, y <= x]
  5.         isUnique :: Integer -> (Integer, Integer) -> (Integer, Integer, Bool)
  6.         isUnique 0 (x,y)  = isUnique (min x y) (x,y)
  7.         isUnique 1 (x,y) = (x,y,True)
  8.         isUnique current (x,y)  = if (x > 1 && y > 1) && (mod x current == 0 && mod y current == 0)
  9.                                  then (x,y,False)
  10.                                  else isUnique (current - 1) (x,y)
  11.  
  12. countVec :: Integer -> Int
  13. countVec limit = (+ 1) $ length $ foldr (\(x,y,z) xs -> if z then ((x,y):xs) else xs) [] $ uniqueVec limit
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top