Skip to content

Instantly share code, notes, and snippets.

@dnene
Created April 15, 2012 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnene/2394980 to your computer and use it in GitHub Desktop.
Save dnene/2394980 to your computer and use it in GitHub Desktop.
Solution to Google Code Jam Problem - Problem A. Speaking in Tongues
3
ejp mysljylc kd kxveddknmc re jsicpdrysi
rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd
de kr kd eoya kw aej tysr re ujdr lkgc jv
# python3
# Problem description at : http://code.google.com/codejam/contest/1460488/dashboard
# Suggested Java solution at : http://www.harshadura.net/2012/04/googlecodejam-my-answer-algorithm-for.html
# Post on suggested clojure solution at : http://bestinclass.dk/index.clj/2012/04/google-code-jam-1.html
from functools import reduce
g = ["ejp mysljylc kd kxveddknmc re jsicpdrysi",
"rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd",
"de kr kd eoya kw aej tysr re ujdr lkgc jv"]
e = ["our language is impossible to understand",
"there are twenty six factorial possibilities",
"so it is okay if you want to just give up"]
def m(d, p) : return d if (p[0] in d) else ( d.update({p[0]:p[1]}) or d)
d = reduce(m,zip("".join(g),"".join(e)),{})
lines=input()
for i in range(int(lines)):
j=input()
print("Case #%s: %s"%(i+1,"".join("".join(d[c] for c in l) for l in j)))
@swanandp
Copy link

Just to make this complete, you might want to add the missing translations to g and e:

# a zoo -> y qee (from translation provided in problem description)
# q -> z (inferred from the one-to-one mapping rule)
g.append("a zoo q")
e.append("y qee z")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment