Created
June 19, 2015 07:52
-
-
Save yassu/4c7b3b52d83bd1f6681a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
-- n is a square number or not | |
isSquare:: Int -> Bool | |
isSquare n = t*t == n | |
where t = round(sqrt (fromIntegral(n))) | |
-- "n = c*c + (n-c*c)" is square split or not | |
isSquareSplit:: Int -> Int -> Bool | |
isSquareSplit n c = isSquare (n - c*c) | |
-- return whether n is splittable as two square number or not | |
splittableAsSquare:: Int -> Bool | |
splittableAsSquare n = True `elem` map (\c -> isSquareSplit (fromIntegral n) c) [1 .. t] | |
where t = round(sqrt (fromIntegral(n))) | |
cntSplitAndNot:: Int -> Int | |
cntSplitAndNot n | |
|(splittableAsSquare(n) == False) = 0 | |
|(otherwise) = 1 + (length (takeWhile (\c -> not(splittableAsSquare(c))) [n+1 ..])) | |
moreThanCntSplitAndNotFrom:: Int -> Int -> Int | |
moreThanCntSplitAndNotFrom s k = head(filter (\n -> cntSplitAndNot n >= k) [s ..]) | |
moreThanCntSplitAndNot:: Int -> Int | |
moreThanCntSplitAndNot k = moreThanCntSplitAndNotFrom 1 k |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment