import Data.Maybe cartesianProduct :: [a] -> [b] -> [(a,b)] cartesianProduct lista listb = concat $ map (\y -> (map (\x -> (y, x)) listb)) lista baseNListP :: Integer -> [Integer] baseNListP n = map (\(a,b) -> (a * n + b)*(n^2+1)) $ [(x,y) | (x,y) <- cartesianProduct [1..(n-1)] [0..(n-1)], x /= y] matrixCNE :: [[Integer]] -> Integer -> Integer matrixCNE matrix cut = minimum $ filter (>cut) $ map last $ filter (/= []) $ takeWhileI2 (\x -> length x /= 1) $ map (takeWhileI (<= cut)) matrix mtrP :: [[Integer]] mtrP = map baseNListP [2..] fullListP :: [Integer] fullListP = (baseNListP 2 !! 0) : map (matrixCNE mtrP) fullListP takeWhileI :: (a -> Bool) -> [a] -> [a] takeWhileI _ [] = [] takeWhileI p (x:xs) = x : if p x then takeWhileI p xs else [] takeWhileI2 :: (a -> Bool) -> [a] -> [a] takeWhileI2 _ [] = [] takeWhileI2 _ [x] = [x] takeWhileI2 p (x:xs) = x : if p x then takeWhileI2 p xs else takeWhileI p xs