This problem is part of our Ada Lovelace Day celebration.
It is for practice only and will NOT count towards your grade!
(just have fun and use it to improve your skills: there is no submission deadline!)
In this problem you should submit a function as described. Inside the function do not print anything that was not asked!
The name of the .py source file you submit to Mooshak should NOT start with a digit (you will get an error if you submit it like that).
Hedy Lamarr was both a Hollywood actress and an inventive thinker!
During World War II, she worked
with composer George Antheil on a communication system that used
frequency hopping
to make radio signals harder to jam. Their system was intended to help guide torpedoes without enemies disrupting their radio signals.
The idea can be imagined like this: a transmitter and a receiver change radio
channels together, following the same pattern.
If someone tries to interfere
with one channel, the signal will soon hop to another one.
Although their invention was not used during the war, their pioneering work helped lay the groundwork for modern wireless technologies!
Recreate Hedy's hopping messages by implementing the function hopping_message(message, corrupted_channels).
The function receives a string message and a list of corrupted channels and returns a new string containing only the message that was successfully sent:
You should consider the following transmission rules:
The following limits are guaranteed in all the test cases that will be given to your program:
| 1 ≤ message ≤ 1000 | characters in message | |
| 0 ≤ |corrupted_channels| ≤ 5 | number of corrupted channels | |
| corrupted_channels ∈ {1, 2, 3, 4, 5} | possible corrupted channels |
| Example Function Calls 1 | Example Output 1 |
print(hopping_message("HELLOWORLD", [2, 4]))
print(hopping_message("SIGNAL", [3]))
print(hopping_message("ABCDE", [2, 4]))
|
"HLOWRD" "SINAL" "ACE" |
Explanation of the example function calls 1: in the first call, channels 2 and 4 are corrupted, so the letters sent through those channels are lost.
Letters: H E L L O W O R L D Channels: 1 2 3 4 5 1 2 3 4 5 Received: H L O W R D
The gaps show lost letters only for illustration. The returned string contains
no gaps.
Note also that the sixth letter uses channel 1, regardless of the
letters that were lost before it.
| Example Function Calls 2 | Example Output 2 |
print(hopping_message("RADIO", []))
print(hopping_message("HEDY", [1, 2, 3, 4, 5]))
print(hopping_message("PYTHON", [1]))
print(hopping_message("WIRELESS", [1, 3]))
|
"RADIO" "" "YTHO" "IELS" |
Explanation of the example function calls 2: