Exercises

Below are some exercises to help you practice and reinforce your understanding of the concepts discussed in the previous sections. Remember to use the template reference if you need help. Do them at your own pace and whenever you feel like it.

Duplicates in a List

  1. You are given a list of numbers having some repeated digits. Write a CC which will eliminate duplicate entries and return the cleaned list. The list is as follows: 42 1 2 81 3 5 42 19 2 42 19 81 46.

  2. Have the CC take a list of numbers as an argument instead and then return the cleaned list.

Stars

Write a CC that will take a number as an argument and then print a pattern of stars as follows:

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

ROT13 Substitution

ROT13 (“rotate by 13 places”, sometimes hyphenated ROT-13) is a simple letter substitution cipher that replaces a letter with the 13th letter after it, in the alphabet. Because there are 26 letters (2×13) in the basic Latin alphabet, ROT13 is its own inverse; that is, to undo ROT13, the same algorithm is applied, so the same action can be used for encoding and decoding. The algorithm provides virtually no cryptographic security, and is often cited as a canonical example of weak encryption.

  1. Write a CC that takes any string and returns the ROT13 version of the string; you may assume that the character set is ASCII and let “space” character be counted as well. Discard numbers.

  2. Decode lntcqo vf n pbby obg naq qhpxf ner onq.

Arithmetic Progression

A sequence of numbers such that the difference between each term remains constant is called an Arithmetic Progression.

We start with a term mathematical expression or equation and add the common difference mathematical expression or equation . We do this for mathematical expression or equation times. To find the sum of any such progression, we use the following formula.

mathematical expression or equation

Write a custom command for finding the sum of mathematical expression or equation terms of an arithmetic progression, parameterized to mathematical expression or equation , and verify it with above formula in the same command (use the right-hand side of the equation).