-
Notifications
You must be signed in to change notification settings - Fork 0
/
level1.py
64 lines (51 loc) · 2.82 KB
/
level1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# I Love Lance & Janice
# =====================
# You've caught two of your fellow minions passing coded notes back and forth - while they're on duty, no less! Worse, you're pretty sure it's not job-related - they're both huge fans of the space soap opera ""Lance & Janice"". You know how much Commander Lambda hates waste, so if you can prove that these minions are wasting her time passing non-job-related notes, it'll put you that much closer to a promotion.
# Fortunately for you, the minions aren't exactly advanced cryptographers. In their code, every lowercase letter [a..z] is replaced with the corresponding one in [z..a], while every other character (including uppercase letters and punctuation) is left untouched. That is, 'a' becomes 'z', 'b' becomes 'y', 'c' becomes 'x', etc. For instance, the word ""vmxibkgrlm"", when decoded, would become ""encryption"".
# Write a function called solution(s) which takes in a string and returns the deciphered string so you can show the commander proof that these minions are talking about ""Lance & Janice"" instead of doing their jobs.
# Languages
# =========
# To provide a Python solution, edit solution.py
# To provide a Java solution, edit Solution.java
# Test cases
# ==========
# Your code should pass the following test cases.
# Note that it may also be run against hidden test cases not shown here.
# -- Python cases --
# Input:
# solution.solution("wrw blf hvv ozhg mrtsg'h vkrhlwv?")
# Output:
# did you see last night's episode?
# Input:
# solution.solution("Yvzs! I xzm'g yvorvev Lzmxv olhg srh qly zg gsv xlolmb!!")
# Output:
# Yeah! I can't believe Lance lost his job at the colony!!
# -- Java cases --
# Input:
# Solution.solution("Yvzs! I xzm'g yvorvev Lzmxv olhg srh qly zg gsv xlolmb!!")
# Output:
# Yeah! I can't believe Lance lost his job at the colony!!
# Input:
# Solution.solution("wrw blf hvv ozhg mrtsg'h vkrhlwv?")
# Output:
# did you see last night's episode?
# Use verify [file] to test your solution and see how it does. When you are finished editing your code, use submit [file] to submit your answer. If your solution passes the test cases, it will be removed from your home folder.
def solution(x):
# Your code here
# Dictionary to map the encoded values
values = "abcdefghijklmnopqrstuvwxyz"
reverse_values = "zyxwvutsrqponmlkjihgfedcba"
coded_values = {}
for i in range(len(values)):
coded_values[values[i]] = reverse_values[i]
# Convert each character in X to the decoded ones
decoded_x = ""
for each in x:
if each in values:
decoded_x = decoded_x + coded_values[each]
else:
decoded_x = decoded_x + each
return decoded_x
print solution("vmxibkgrlm")
print solution("wrw blf hvv ozhg mrtsg'h vkrhlwv?")
print solution("Yvzs! I xzm'g yvorvev Lzmxv olhg srh qly zg gsv xlolmb!!")