Write the solutions for the following quizzes by using functional programming:
Let's write a module (a pool of functions) that given a quite large text (over than 2000 words) counts how frequent each word occurs in the text. In particular the module should provide the function freqs that given a filename and a number would return a list of words (with their frequencies) that occur more than the given number; the list is sorted by frequency with the higher first.
The text is read from a file and it is a real text with punctuation (i.e., commas, semicolons, ...) that shouldn't be counted.
Note that words that differ only for the case should be considered the same.
sin(x) can be approximate by the Taylor's series:
Let's write a library to implement sin(x, n) by using the Taylor's series (where n is the level of approximation, i.e., 1 only one item, 2 two items, 3 three items and so on).
Let's compare your function with the one implemented in the math module at the growing of the approximation level.
Hint. Use a generator for the factorial and a comprehension for the series.
Consider the number 6. The divisors of 6 are: 1, 2, 3 and 6.
Every number from 1 up to and including 6 can be written as a sum of distinct divisors of 6: 1=1, 2=2, 3=1+2, 4=1+3, 5=2+3, 6=6.
A number n is called a practical number if every number from 1 up to and including n can be expressed as a sum of distinct divisors of n.
A pair of consecutive prime numbers with a difference of six is called a sexy pair (since "sex" is the Latin word for "six"). The first sexy pair is (23, 29).
We may occasionally find a triple-pair, which means three consecutive sexy prime pairs, such that the second member of each pair is the first member of the next pair.
We shall call a number n such that:
an engineers' paradise.
Find the sum of the first four engineers' paradises.