# CMU 15-112 - 200605 ###### tags: `Tutor` `CS` `Tiffany` - Date: 2020.06.05 ## Learning Intention Using the summer time to get an idea of Big Data ^^ ## Topics for today - Finish HW2. - Learning how to debug. ## Homework ### CMU 15-112 #### patternedMessage(message, pattern) >- [Reference link](https://www.cs.cmu.edu/~112/notes/hw3.html) >- [Solution](https://github.com/kuangkaocompassion/CMU-15-112-Summer-2020-Fundamentals-of-Programming/tree/master/hw3_Kuang) Write the function patternedMessage(message, pattern) that takes two strings, a message and a pattern, and returns a string produced by replacing the non-whitespace characters in the pattern with the non-whitespace characters in the message (where any leading or trailing newlines in the pattern are first removed). As a first example: ![](https://i.imgur.com/zh9mlYH.png) Here, the message is "Go Pirates!!!" and the pattern is a block of asterisks with a few missing in the middle. Notice how the whitespace in the pattern is preserved, but the whitespace in the message is removed. Again, note that any leading or trailing newlines in the pattern are removed. Here is another example: ![](https://i.imgur.com/Pe10R72.png) :fire:Hint: While you may solve this how you wish, our sample solution did not use replace in any way. Instead, we started with the empty string, and built up the result character by character. How did we determine the next character? Using both the message and the pattern in some way... **Pseudocode** ![](https://i.imgur.com/Kgo17FQ.jpg)