finish extra/i-love-lance-janice #26

Merged
seongbeom_park merged 2 commits from extra/i-love-lance-janice into main 2022-05-10 14:10:54 +00:00
4 changed files with 84 additions and 0 deletions

View File

@ -108,3 +108,6 @@ CFcSBwgCCBoHRhkKU1cGAA4AGU5YQR5THBwNFwoGGAxTQQMQVBUSBg4EAAwQRhUQVBUHFAQTGRpT QQM
### skipping-work ### skipping-work
* Completed in: 20 mins, 58 secs. * Completed in: 20 mins, 58 secs.
### i-love-lance-janice
* Completed in: 34 mins, 26 secs.

View File

@ -0,0 +1,21 @@
Java
====
Your code will be compiled using standard Java 8. All tests will be run by calling the solution() method inside the Solution class
Execution time is limited.
Wildcard imports and some specific classes are restricted (e.g. java.lang.ClassLoader). You will receive an error when you verify your solution if you have used a blacklisted class.
Third-party libraries, input/output operations, spawning threads or processes and changes to the execution environment are not allowed.
Your solution must be under 32000 characters in length including new lines and and other non-printing characters.
Python
======
Your code will run inside a Python 2.7.13 sandbox. All tests will be run by calling the solution() function.
Standard libraries are supported except for bz2, crypt, fcntl, mmap, pwd, pyexpat, select, signal, termios, thread, time, unicodedata, zipimport, zlib.
Input/output operations are not allowed.
Your solution must be under 32000 characters in length including new lines and and other non-printing characters.

View File

@ -0,0 +1,43 @@
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 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.

View File

@ -0,0 +1,17 @@
def solution(x):
result = ""
for c in x:
if ord('a') <= ord(c) and ord(c) <= ord('z'):
result += chr(ord('a') + ord('z') - ord(c))
else:
result += c
return result
tests = [
("wrw blf hvv ozhg mrtsg'h vkrhlwv?", "did you see last night's episode?"),
("Yvzs! I xzm'g yvorvev Lzmxv olhg srh qly zg gsv xlolmb!!", "Yeah! I can't believe Lance lost his job at the colony!!"),
]
for i, o in tests:
result = solution(i)
print (i, result == o, result, o)