06/12/2025

Week 6 and 7 Assignments

1. Stammer Bob: 

Bob stammers when facing long words.  He speaks all words with less than or equal to 5 letters fluently, but for each word with more than 5 letters, each extra letter causes him to repeat the word once more.  For example, when you say ‘Good Morning Bob’, he will have to reply ‘Good Morning Morning Morning George George’.  

Input a sentence, output how Bob actually pronounces it.

2. Looping

Input an integer N and an integer M (0 < NM < 20), output a N by M parallelogram.  Example, N = 5, M = 4, output is

 
   *****
  *****
 *****
*****

 

Extension 1: 

Output both the original parallelogram and its mirror image.


Extension 2: 

Use ‘*’ and ‘+’ for alternating rows.


3. Preprocessing:

You work for a big data company.  They take vast number of texts from the media and perform data analysis.  Your job is to preprocess the text by attaching data points to the words so that they can be processed by the data scientists.  The rule is simple: for each input line, separate them into words (delimited by spaces), prefix each word with the sequence number of it in the line, and suffix it with the length of the word.  For example, for the input ‘giant leap for mankind’, you produce an output ‘0giant5 1leap4 2for3 3mankind7’.

3. the Code


Criminals are threatening to blow up the city, you have only 24 hours to stop them.

The only thing you know is that they use the Bible as a code book.  We know that different words appear with difference frequencies in the Bible, apparently that's the hint to crack their code.  

You are given an extract from the bible.  Please break it into words, then sort them in the order of frequence appearing in the extract.  Give that result (a list of words sorted in the descending order of frequencies) to forensic scientist who will take it from there.

The clock is ticking.  Act NOW!

No comments: