# Lambda Functions Lambda functions are sometimes called anonymous functions. Quite simply, they are a function without a name. It's often more convenient to not bother naming a function when you're only going to use it once. Lambda is a Greek letter that looks like this: λ Haskell uses a \\ as it looks a little like a lambda. Here's an example of a lambda function that doubles a number ```haskell *Main> (\x -> x*2) 3 6 ``` Here's another lambda function that multiplies two numbers ```haskell *Main> (\x y -> x*y) 3 4 12 ``` The above example is an anonymous version of the areaRectangle function mentioned earlier. Here's how to use a lambda function to find the numbers that divide by 3 ```haskell *Main> filter (\x -> x `mod` 3 == 0) [1..20] [3,6,9,12,15,18] ``` # Perfect Numbers Here's a Haskelly way of solving a problem, using some of the things learned so far. A perfect number is a number that is the sum of its factors. 6 is a perfect number as its factors are 1, 2 and 3 and 1 + 2 + 3 = 6. Find all the perfect numbers < 10000 We know from earlier that we can find the factors of a number using the following function ```haskell factors n = [x | x <- [1..n], n `mod` x == 0] ``` Here's an example ```haskell *Main> factors 6 [1,2,3,6] ``` Remember that a number is perfect if it's the sum of its factors, not including the number itself, so we add an extra predicate to eliminate that. ```haskell factors n = [x | x <- [1..n], n `mod` x == 0, x/=n] ``` Check this ```haskell *Main> factors 6 [1,2,3] ``` So a number is perfect if sum (factors x) == x. Lets run a list comprehension to find the perfect numbers <1000. ```haskell *Main> [x | x <- [1..1000], sum (factors x) == x] [6,28,496] ``` Or use a filter… ```haskell *Main> filter (\x -> sum(factors x) == x) [1..1000] [6,28,496] ``` Try running that on \[1..10000\] to see how long it takes Haskell to figure out the next perfect number!