Skip to content

Instantly share code, notes, and snippets.

View freemo's full-sized avatar

Jeffrey Phillips Freeman freemo

View GitHub Profile
@freemo
freemo / PrimeCheck.hs
Last active September 20, 2019 17:00
Primality Algoritm, Multiple languages
prime :: Int -> Bool
prime x
| x == 1 = False
| x == 2 = True
| x == 3 = True
| x `mod` 2 == 0 = False
| x `mod` 3 == 0 = False
| otherwise = all (\y -> x `mod` y /= 0) $ dividends x
where
dividends z =
@freemo
freemo / MergeSort.hs
Last active September 20, 2019 17:00
Merge sort, Multiple languages
mergeSort :: (Ord a) => [a] -> [a]
mergeSort x
| len <= 1 = x
| otherwise = combine (mergeSort upper) (mergeSort lower)
where len = length x
middle = quot len 2
upper = take middle x
lower = drop middle x
combine x [] = x
combine [] x = x