33 lines
1.1 KiB
Haskell

doubleMe x = x + x
doubleUs x y = doubleMe x + doubleMe y
doubleSmallNumber x = if x > 100
then x
else x*2
doubleSmallNumber' x = (if x > 100 then x else x*2) + 1
-- boom bangs, ya heard???
boomBangs xs = [ if x< 10 then "BOOM!" else "BANG!" | x <- xs, odd x]
-- remember, [function | set, predicate] 'fucking stupid predicate'
schtankyList x = [ x*y | x <- [2,5,10], y <- [8,10,11]]
-- Now Writing our own custom list function
length' xs = sum [1 | _ <- xs]
-- use dummy variable _, draw an element from a list and replace it with 1. Sum all of those.
--- Strings are lists! We can use list comprehensions on them.
removeNonUppercase st = [ c | c <- st, c `elem` ['A'..'Z']]
--------------Pythogoraus Problem----------------------
--triangles with integer sides
triangles x = [(a,b,c) | c <- [1..10], b <- [1..10], a <- [1..10]]
--right triangles
rightTriangles x = [(a,b,c) | c <- [1..10], b <- [1..10], a <- [1..10], a^2 + b^2 == c^2]
-- Now only triangles with perimiter equal to 24
rightTriangles' x = [(a,b,c) | c <- [1..10], b <- [1..10], a <- [1..10], a^2 + b^2 == c^2, a+b+c == 24]