Facebook runs a robot that takes email attachments and runs them to solve a puzzle that is posted
at http://www.facebook.com/careers/puzzles.php#!/careers/puzzles.php .
This is what I did to submit the hoppity puzle
shell$ echo 15 > file.txt
shell$ python hoppity.py file.txt
Hoppity
Hohpop
Hoppity
Hoppity
Hohpop
Hoppity
Hop
shell$ cat hoppity.py
#!/usr/bin/env python
import sys
if len(sys.argv) != 2:
print 'run it as ', __file__, 'file.txt # file.txt should contain one unsigned int'
sys.exit(1)
_file=sys.argv[1]
try:
f = open(_file, 'r')
except IOError, ioe:
print "file %s does not exist " % _file
except:
print "can not open file %s" % _file
no = f.read() # assume ONE uint in _file
max = int(no.strip()) + 1
for i in xrange(1,max):
if i % 3 == 0 and i % 5 == 0 :
print 'Hop'
elif i % 3 == 0: print 'Hoppity'
elif i % 5 == 0: print 'Hophop'
try:
f.close()
except:
pass
to actually submit the program - archive it as
mv hoppity.py hoppity && tar cvfz hoppity.tar.gz hoppity.py # the bot doesn't take the extension so you have to cut it offand send an email with the archive attached to 1051962371@fb.com
0 comments:
Post a Comment