Created
May 30, 2012 08:12
-
-
Save qzchenwl/2834494 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
module Main where | |
import Data.Char (digitToInt) | |
sort :: (Ord a) => [a] -> [a] | |
sort [] = [] | |
sort (x:xs) = sort smaller ++ [x] ++ sort greater | |
where | |
smaller = filter (not.(> x)) xs | |
greater = filter (> x) xs | |
sortBy :: (a -> a -> Ordering) -> [a] -> [a] | |
sortBy _ [] = [] | |
sortBy cmp (x:xs) = sortBy cmp smaller ++ [x] ++ sortBy cmp greater | |
where | |
smaller = filter ((/= GT).(`cmp` x)) xs | |
greater = filter ((== GT).(`cmp` x)) xs | |
toNumber :: String -> Double | |
toNumber = read . filter (`elem` '.':['0'..'9']) | |
gap2 :: Int -> [Int] | |
gap2 x = x : (gap2 (x+2)) | |
gap4 :: Int -> [Int] | |
gap4 x = x : (gap4 (x+4)) | |
gap7 :: Int -> Int -> [Int] | |
gap7 x y = undefined | |
half = (/2) | |
newline = (++"\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment