-
-
Save tathagata/1793945 to your computer and use it in GitHub Desktop.
embed.ly contest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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