Skip to content

Instantly share code, notes, and snippets.

@Aramgutang
Created May 4, 2011 20:51
Show Gist options
  • Save Aramgutang/956010 to your computer and use it in GitHub Desktop.
Save Aramgutang/956010 to your computer and use it in GitHub Desktop.
Google Nexus S Challenge Puzzle #6
"""
My answer was: "1 vowel; 3-5 digits; letters in ascending order, but sequence
can restart after first 2 if rest of letters are unique. #googlenexus #pattern"
Though it may seem a bit iffy, this is the most specific pattern I could find
that would validate all strings marked as "yes" and invalidate all strings
marked as "no". After 5 hours, I'm not prepared to explore this puzzle any
further.
The following code verifies that my solution holds true.
"""
from string import ascii_lowercase, digits
yes = """
adgjl24680
ABBBB12345
adgjl24680
asd12nx123
ASDFG24680
acdfg13579
acdfg35719
bcdef13579
13579acdfg
ghijk57913
defgh88129
ABDFG24680
13bcd579ef
a1b3c5d7f9
abxyz24688
abcdz13579
rstuv12345
mnopq24688
13acd579fg
a1b2b3b4b5
abbb1b3579
BBBBE54321
aglmn24688
ablmn24688
abbbbbb123
acccccc120
effffff120
affffff135
abcdgh2345
ABBBBB1234
abbbbb1223
"""
no = """
b873ahfj11
QWANG16235
AHTPG60342
omgwtf1234
e11111cccc
asd2ds1234
a2c3n5g8g9
shryo167ly
BBBBA54321
oblmn24688
eblmn24688
abbbbbbb20
29dknkfpqa
ab12345678
ABC0123456
abbb112358
ablm246888
samp012345
BBBA123456
a1p357975p
a111111111
googl63987
n3xu5n3xu5
12345abcde
a2c4e6g8i0
Abcde13579
acdhi13579
cdfgh02468
GHJMK18576
jklmn39751
CCCCC12345
a1b2c3d4e5
ZY8X7W6V5S
v1llainrom
hdjs63yh5d
qsxt293xpm
googlegogo
57d3hjs351
sbnn295pwd
gnannwxyzh
gmflcokvn4
AAAAAAAAAA
nexuss235i
a1b2c3d4e5
dfg2jklrd5
ayawanapat
bbbbbbbbbb
n3xvsr0cks
1abcdefgha
fdmmm619vb
sdbbn769wm
cddbtn538p
abcde11379
cgwmt70vv3
eghkljmnbh
gtttn234tg
ABC0123456
abbb112358
dffffff120
bcccccc120
almnu76498
b359gjmpwz
hw30lrll0d
2468824688
c1c2c3c4c5
icecream71
msnvm90231
w4ntn3x0ss
1BBBBC2345
"""
yes = yes.lower().strip().split('\n')
no = no.lower().strip().split('\n')
def evaluate(s):
# Check if only one vowel
if len([c for c in s if c in 'aeiou']) != 1:
return False
# Check if between 3 and 5 digits
if len([c for c in s if c in digits]) not in range(3,6):
return False
# Extract the character codes of the Latin letters in the string
letters = [ord(c) for c in s if c in ascii_lowercase]
# Get the differences in position in the alphabet for each sequential
# pair of letters
diffs = []
for i in range(len(letters) - 1):
diffs.append(letters[i+1] - letters[i])
# First check if all letters sequential
if all(diff >= 0 for diff in diffs):
return True
# If not, check if the first 2 are sequential, and no duplicates occur
# in the subsequent letters
else:
return (diffs[0] >= 0 and diffs[1] < 0 and all(diff > 0 for diff in diffs[2:]))
assert all(map(evaluate, yes)), 'FAIL: All "yes" strings must evaluate to True!'
assert not any(map(evaluate, no)), 'FAIL: All "no" strings must evaluate to False!'
print 'SUCCESS: Evaluate function is correct for the data set!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment