During this activity, students should be able to:
This activity helps the student develop the following skills, values and attitudes: ability to analyze and synthesize, capacity for identifying and solving problems, and efficient use of computer systems.
Individually or in pairs, solve the following programming exercises using Erlang and the plists:mapreduce
function in order to effectively take advantage of any level of parallelism available on the execution environment. Place your functions in a module called mapred
.
Write the function primes
that takes two integer parameters, S and E (0 ≤ S ≤ E). It starts by calling the MapReduce operation with a list of all integer numbers between S and E inclusively. The mapping function receives a number N and emits the tuple {true, N}
if N is a prime number, otherwise it emits the tuple {false, N}
. After the reduction, it returns a list with all the prime numbers found between S and E, or an empty list if none were found. Examples (note that the order of the resulting elements is nondeterministic):
> mapred:primes(0, 20). [2,3,5,7,11,13,17,19] > mapred:primes(320, 330). [] > mapred:primes(9999500, 9999900). [9999511,9999533,9999601,9999883,9999593,9999889,9999637, 9999653,9999659,9999761,9999863,9999713,9999823,9999677, 9999739,9999667,9999749,9999877]
A number of the form 2n that contains the consecutive digits 666 (i.e., the beast number) is called an Apocalyptic Number.
The number 2157 is an apocalyptic number, because
2157 = 182687704666362864775460604089535377456991567872
which contains the beast number starting at the digit in position 10 (starting from the left).
Write the function apocalyptic
that takes two integer parameters, S and E (0 ≤ S ≤ E). It starts by calling the MapReduce operation with a list of all integer numbers between S and E inclusively. The mapping function receives a number N and determines if 2N is or isn't an apocalyptic number. If it is, it emits the tuple {true, N}
, otherwise it emits the tuple {false, N}
. After the reduction, it returns a list with all the apocalyptic numbers found between S and E, or an empty list if none were found. Examples:
> mapred:apocalyptic(100, 200). [157,192] > mapred:apocalyptic(100, 150). [] > mapred:apocalyptic(800, 850). [800,807,819,820,822,823,824,826,828,836,838,840,841,842, 844,846,848,850]
A sexy prime triplet is a tuple (p, p+6, p+12) of prime numbers that differ by six. The term "sexy prime" stems from the Latin word for six: sex. For example, the first sexy prime triplet is: (5, 11, 17).
Write the function called sexy
that takes two integer parameters S and E (0 ≤ S ≤ E). This function returns a list with a all the sexy prime triplets (p, p+6, p+12), where S ≤ p ≤ E. Examples:
> mapred:sexy(1, 100). [{5,11,17}, {7,13,19}, {11,17,23}, {17,23,29}, {31,37,43}, {41,47,53}, {47,53,59}, {61,67,73}, {67,73,79}, {97,103,109}] > mapred:sexy(1500, 1600). [] > mapred:sexy(50000, 51000). [{50147,50153,50159}, {50411,50417,50423}, {50581,50587,50593}, {50587,50593,50599}] > mapred:sexy(100000, 101000). [{100511,100517,100523},{100931,100937,100943}]
Let φ(X) be the sum of all the digits of 2X. For example, to compute φ(15), first you compute 215, which equals to 32,768, and then you add up all its digits: 3 + 2 + 7 + 6 + 8. The result is 26.
Write the function called phi13
that takes two integer parameters S and E (0 ≤ S ≤ E). This function returns a list with all the values of K, where S ≤ K ≤ E, such that φ(K) is exactly divisible by 13. Examples:
> mapred:phi13(0, 100). [8,15,21,49,74,77] > mapred:phi13(350, 400). [] > mapred:phi13(1000, 1100). [1002,1008,1032,1033,1034,1049,1067,1097] > mapred:phi13(10000, 10100). [10016,10019,10037,10052,10088,10090,10100]
Using the Online
Assignment Delivery System (SETA), deliver the file called
mapred.erl
. No assignments will be accepted through
e-mail or any other means.
IMPORTANT: The program source file must include at the top the author's personal information (name and student id) within comments. For example:
%% ITESM CEM, October 10, 2012. %% Erlang Source File %% Activity: MapReduce with Erlang %% Authors: 1166611 Pepper Pots %% 1160611 Anthony Stark . . (The rest of the program goes here) .
Due date: Wednesday, October 10.
This activity will be evaluated using the following criteria:
-10 | The program doesn't contain within comments the author's personal information. |
---|---|
10 | The program contains syntax errors. |
DA | The program was plagiarized. |
10-100 | Depending on the amount of exercises that were solved correctly. |