Skip to content

Instantly share code, notes, and snippets.

Created February 11, 2012 04:23
Show Gist options
  • Save anonymous/1796145 to your computer and use it in GitHub Desktop.
Save anonymous/1796145 to your computer and use it in GitHub Desktop.
Embedly Problems
from math import factorial
from itertools import count
from urllib import urlopen
from xml.dom.minidom import parse
"""
Problem #1
"""
def R(x):
fsum = 0
fact = factorial(x)
for i in map(int,str(fact)):
fsum += i
return fsum
def problem_1():
for i in count(1): #Alot of trust here... haha 8001 better be here!
if R(i) == 8001:
print i
break
"""
Problem #2
Used C# HTML Agility Pack, it makes parsing pretty nice
(i'm sure mini dom would work here as well
public void StartParse()
{
HtmlDocument doc = new HtmlDocument();
doc.Load("file.htm");
PNodes(doc.DocumentNode.FirstChild.FirstChild, 1);
}
public void PNodes(HtmlNode node, int depth)
{
if (node.HasChildNodes)
{
//Process Children First
PNodes(node.FirstChild, depth + 1);
}
if (node.Name == "p")
{
Console.WriteLine(depth);
//Console.WriteLine("Found <p> at Depth = {0}", depth);
}
if (node.NextSibling != null)
PNodes(node.NextSibling, depth);
}
"""
"""
Problem #3
"""
def problem_3(mf, tu):
zipfreq = [mf]
for i in range(2,tu):
zipfreq.append(zipfreq[0] / i)
halfway = sum(zipfreq) / 2
hsum = 0.0
for r in range(0,tu -1):
hsum += zipfreq[r]
if hsum > halfway:
print r + 1
return
problem_3(2520.0,900)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment