# Applied programming 2014 week six

### Lectures

At both lectures we will talk about how to break up a large problem into a set of smaller and problems that are more easily solved.

### Computer exercises

The computer exercise for this week was once an exam set. So if you think it is difficult at this point, do not despair. It is about finding open reading frames in bacteria sequences. There is a link to the exercise in the outline table on the course page.

### Reading material

None for this week. Spend the extra time going through each separate topic we have been through to make sure you understand each part well enough. Otherwise it will become too confusing when we start to put all the things together.

### Weekly assignment

For the assignment you must write four functions. Most of them can be implemented with list comprehensions if you have the guts.

Write a function `square(L)`

that takes a list of numbers and returns the list of those

numbers squared.

Example usage:

print square([2, 5, 3, 6])

should print:

`[4, 25, 9, 36]`

Write a function `even(L)`

that takes a list of numbers and returns a list of only those

numbers that are even. Remember that you can test if a number is even using `n % 2 == 0`

.

Example usage:

print even([2, 5, 3, 6])

should print:

`[2, 6]`

Write a function, `differences(xs,ys)`

that takes two lists of equal length, `xs`

and `ys`

, and

returns a list of the pairwise differences. One way to solve it is similar to the way you

did the `pairwiseDifferences`

function in last weeks exercise. An other way is to use the

built in function `zip(xs,ys)`

to get a list of all the matching pairs of xs and ys to

iterate through (look at the documentation yourself).

Example usage:

print differences([2, 5, 3, 6], [1, 5, 6, 3])

should print:

`[1, 0, -3, 3]`

Write a function `squaredDifferences(xs, ys)`

that takes two lists of equal length, `xs`

and

`ys`

, and returns a list of the pairwise differences squared. You can use the

`differences(xs,ys)`

function to make it easier to write this function.

Example usage:

print squaredDifferences([2, 5, 3, 6], [1, 5, 6, 3])

should print:

`[1, 0, 9, 9]`