Skip to content

Instantly share code, notes, and snippets.

@rodrigosetti
Created April 19, 2012 23:27
Show Gist options
  • Save rodrigosetti/2424838 to your computer and use it in GitHub Desktop.
Save rodrigosetti/2424838 to your computer and use it in GitHub Desktop.
Full script for the Google Developer Day Quiz (http://developerquiz.appspot.com) in 23 lines
#! /usr/bin/env python
from string import maketrans, lowercase, split
G_FOO = 'pgjck' # Googlon special letters
G_PREP_C = 'j' # Preposition character
G_PREP = 3 # Preposition size
G_VERB = 8 # Verb size
G_ORDER = 'kgpvbmzfhtxqcrlnjsdw' # Letter ordering
G_NUM_MOD = 5 # Pretty number divisor
G_NUM_MIN = 716810 # Pretty number minimum
G_PREP_END_IN_FOO = False # End of prepositon must be in Foo?
G_CHAR_IN_PREP = False # Preposition char must be in preposition?
G_VERB_END_IN_FOO = False # End of verb must be in Foo?
G_FIRST_PERSON_START_IN_FOO = True # First person verb must start in Foo?
words = split(raw_input()) # Reads text from standard input and split words
print "Prepositions: ", sum(1 for w in words if len(w) == G_PREP and G_PREP_END_IN_FOO == (w[2] in G_FOO) and G_CHAR_IN_PREP == (G_PREP_C in w))
print "Verbs:", sum(1 for w in words if len(w) >= G_VERB and G_VERB_END_IN_FOO == (w[-1] in G_FOO))
print "First person:", sum(1 for w in words if len(w) >= G_VERB and G_VERB_END_IN_FOO == (w[-1] in G_FOO) and G_FIRST_PERSON_START_IN_FOO == (w[0] in G_FOO))
print "Vocabulary:", ' '.join(sorted(set(words), key=lambda x: x.translate(maketrans(G_ORDER, lowercase[:len(G_ORDER)]))))
print "Pretty Numbers:", sum(1 for v in (sum(20**n * G_ORDER.index(c) for n,c in enumerate(w)) for w in set(words)) if v >= G_NUM_MIN and v % G_NUM_MOD == 0)
@rodrigosetti
Copy link
Author

A response to the Gaigala's challenge Gist ( https://gist.github.com/1132654 ). This version adds four other parameters to configure sets pertinence.

@rodrigosetti
Copy link
Author

Eu acho que esse é o limite para Python. Se não colapsar as 11 linhas de parâmetros e 5 linhas de output, só sobrou a linha de leitura da entrada e import para remover.

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