Skip to content

Instantly share code, notes, and snippets.

@tathagata
Created February 10, 2012 23:21
Show Gist options
  • Save tathagata/1793945 to your computer and use it in GitHub Desktop.
Save tathagata/1793945 to your computer and use it in GitHub Desktop.
embed.ly contest
import math
def sum_digits(value):
sum =0
while value !=0:
sum +=value%10
value /=10
return sum
def fact(value):
mul =1
for i in range(value,0,-1):
mul *=i
return mul
if __name__ == "__main__":
num = 0
i = 786 #0
while num!=8001:
num = list(map(sum_digits, list (map(fact, range(0,i+1)))))[-1]
print num, i
i+=1
print i-1
from __future__ import division
import math
def sum(vals):
for i in vals: sum +=i
import urllib, urllib2, urlparse, re
url = 'http://apply.embed.ly/static/data/2.html'
depth =1
do = re.compile(r'<div>')
dc = re.compile(r'</div>')
po = re.compile(r'<p>.*</p>')
vals = []
for i in urllib2.urlopen(url).readlines():
r=do.search(i)
if r:
print ' '*depth, 'div -', depth
depth +=1
r=dc.search(i)
if r:
print ' '*depth, 'div -', depth
depth -=1
r=po.search(i)
if r:
print ' '*depth, 'p -', depth
vals.append(depth)
sum=0
for i in vals:sum += i
mean = sum/len(vals)
sum=0
for i in vals:sum +=math.pow((mean-i),2)
print math.sqrt(sum/len(vals))
from __future__ import division
sum = 0
for i in range(1,900): sum+=1/i
new_sum =0
for i in range(1,450):
new_sum += 1/i
print i, sum, sum/2, sum/2-new_sum
if (sum/2-new_sum)<0.0000:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment