Skip to content

Instantly share code, notes, and snippets.

@rahmlad-aramide
Forked from dhaninugraha/run.py
Created October 18, 2022 01:14
Show Gist options
  • Save rahmlad-aramide/bae5db3e969081e5edd81257c820e759 to your computer and use it in GitHub Desktop.
Save rahmlad-aramide/bae5db3e969081e5edd81257c820e759 to your computer and use it in GitHub Desktop.
Google foobar - I Love Lance and Janice
# foobar:~/i_love_lance_janice guest$ cat constraints.txt
# Java
# ====
# Your code will be compiled using standard Java 7. It must implement the answer() method in the solution stub.
# Execution time is limited. Some classes are restricted (e.g. java.lang.ClassLoader). You will see a notice if you use a restricted class when you verify your solution.
# Third-party libraries, input/output operations, spawning threads or processes and changes to the execution environment are not allowed.
# Python
# ======
# Your code will run inside a Python 2.7.6 sandbox.
# Standard libraries are supported except for bz2, crypt, fcntl, mmap, pwd, pyexpat, select, signal, termios, thread, time, unicodedata, zipimport, zlib
# 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 answer(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
# ==========
# Inputs:
# (string) s = "wrw blf hvv ozhg mrtsg'h vkrhlwv?"
# Output:
# (string) "did you see last night's episode?"
# Inputs:
# (string) s = "Yvzs! I xzm'g yvorvev Lzmxv olhg srh qly zg gsv xlolmb!!"
# Output:
# (string) "Yeah! I can't believe Lance lost his job at the colony!!"
# 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 answer(s):
lc_norm = [i for i in range(97, 123)]
lc_rev = [j for j in range(122, 96, -1)]
dict_lc = {lc_norm[n]: lc_rev[n] for n in range(len(lc_norm))}
decrypted_s = []
for c in s:
if dict_lc.has_key(ord(c)):
decrypted_s.append(chr(dict_lc[ord(c)]))
else:
decrypted_s.append(c)
return ''.join(decrypted_s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment