Skip to content

Instantly share code, notes, and snippets.

@MiniXC
Created October 22, 2017 16:05
Show Gist options
  • Save MiniXC/190564f24b6682de459eae2f46120d4f to your computer and use it in GitHub Desktop.
Save MiniXC/190564f24b6682de459eae2f46120d4f to your computer and use it in GitHub Desktop.
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