Skip to content

Instantly share code, notes, and snippets.

@qzchenwl
Created May 30, 2012 08:12
Show Gist options
  • Save qzchenwl/2834494 to your computer and use it in GitHub Desktop.
Save qzchenwl/2834494 to your computer and use it in GitHub Desktop.
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