Skip to content

Instantly share code, notes, and snippets.

Created February 10, 2012 22:28
Show Gist options
  • Save anonymous/1793584 to your computer and use it in GitHub Desktop.
Save anonymous/1793584 to your computer and use it in GitHub Desktop.
import math
import sys
def fact( num):
if num == 0 or num == 1:
return 1
else:
return num * fact(num-1)
for i in xrange(100000):
sum=0
for dig in str(fact(i)):
sum = sum + int(dig)
if sum == 8001:
print i
sys.exit(0)
import urllib
f = urllib.urlopen("http://apply.embed.ly/static/data/2.html")
s = f.read()
f.close()
import re
###DISCLAIMER, I ripped the code to do this calculation from
###http://www.physics.rutgers.edu/~masud/computing/WPark_recipes_in_python.html
def meanstdv(x):
from math import sqrt
n, mean, std = len(x), 0, 0
for a in x:
mean = mean + a
mean = mean / float(n)
for a in x:
std = std + (a - mean)**2
std = sqrt(std / float(n-1))
return mean, std
#s=" <article>\
# <p>Sign Up Today</p>\
# <div>\
# <p>Content</p>\
# <div>\
# <img />\
# <p>Img Caption</p></div>\
# <p>Content</p> </div></article>"
print s
stack = []
values = []
for match in re.findall(r'(\<.*?\>)', s):
if (match.rfind("</") != -1):
stack.pop()
elif (match.rfind("/>") != -1):
print "skip"
else:
print match,",",len(stack)
values.append(len(stack))
stack.append(match)
mean,stdev = meanstdv(values)
print "mean ", mean
print "std ", stdev
import sys
import math
most_frequent = 2520
totalWords = 0
wordSum = 0
for x in xrange(1,901):
totalWords = totalWords + math.floor(most_frequent/x)
print totalWords
for x in xrange(1,901):
wordSum = wordSum + most_frequent/x
if wordSum >= math.floor(totalWords/2):
print "ans ", x+1
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment