Created
October 22, 2017 16:05
-
-
Save MiniXC/190564f24b6682de459eae2f46120d4f 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
import Data.Char | |
import Test.QuickCheck | |
-- count str = length [c | c <- str, isUpper c || isDigit c] | |
count = length . filter c | |
where c x = isUpper x || isDigit x | |
countRec [] = 0 | |
countRec (c:str) = (if isUpper c || isDigit c then 1 else 0) + countRec str | |
prop_count :: String -> Bool | |
prop_count str = count str == countRec str | |
isNext :: Int -> Int -> Bool | |
isNext n1 n2 | even n1 = div n1 2 == n2 | |
| otherwise = (n1 * 3 + 1) == n2 | |
--collatz xs = all(==True) [isNext x (xs!!i) | (x,i) <- zip xs [1..], i < length xs] | |
collatz :: [Int] -> Bool | |
collatz xs = and (zipWith isNext xs (tail xs)) | |
collatzRec :: [Int] -> Bool | |
collatzRec [] = True | |
collectRec [x] = True | |
collatzRec (y:x:xs) = isNext x y && collatzRec (y : xs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment