half x = x/2 isBig x = x>100 listify x y = [x,y] myAnd False _ = False myAnd True a = a len [] = 0 len (x:xs) = 1 + len xs sign1 x | x>0 = 1 | x<0 = -1 | otherwise = 0 word n = case n of 1 -> "one" 2 -> "two" 3 -> "three" _ -> "???" sign2 x = if x<0 then -1 else if x>0 then 1 else 0 evensDown n = [i | i<-[n,(n-2)..0]] qsort [] = [] qsort (x:xs) = small ++ [x] ++ large where small = qsort [a | a<-xs, a<=x] large = qsort [a | a<-xs, a>x] qsort' [] = [] qsort' (x:xs) = let small = qsort' [a | a<-xs, a<=x] large = qsort' [a | a<-xs, a>x] in small ++ [x] ++ large someValues x = [x, sq x, sq (sq x)] where sq i = i*i myPower _ 0 = 1 myPower x y = x * myPower x (y-1) myPower' x y | y==0 = 1 | even y = half * half | otherwise = half * half * x where half = myPower' x (div y 2) stupidAdder x 0 = x stupidAdder x y = stupidAdder (x+1) (y-1) stupidAdder' x 0 = x stupidAdder' x y = 1 + stupidAdder' x (y-1) -- myPower'' m x y returns m * x^y myPower'' m _ 0 = m myPower'' m x y = myPower'' (m*x) x (y-1) factorial' n = factTail 1 n where factTail a 0 = a factTail a n = factTail (a*n) (n-1) (+++) a b = b ++ a ++ b divisors1 n = [i | i <- [2..(n `div` 2)], divides n i] where divides a b = a `mod` b == 0 divisors2 n = filter (divides n) [2..(n `div` 2)] where divides a b = a `mod` b == 0 mySum' xs = foldl (+) 0 xs myLength xs = foldl oneMore 0 xs where oneMore n _ = n+1 reverse' xs = foldl postfix [] xs where postfix xs x = x:xs --reverse'' xs = foldr operation [] xs -- where operation ??? --something :: Int -> Int -> Int something :: (Num a) => a -> a -> a something x y = x + x*y something2 x y z = (x>y, z+1) join _ [] = "" join _ (w:[]) = w join sep (w:ws) = w ++ sep ++ join sep w commajoin = join ","