Created
February 19, 2012 22:01
-
-
Save kierendavies/1866091 to your computer and use it in GitHub Desktop.
Embedly Challenge code
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
# my first solution (lost) in the interactive interpreter used DP, but this | |
# is fast enough | |
fac = lambda x: reduce(lambda a, b: a * b, range(1, x + 1)) | |
R = lambda x: sum(int(c) for c in str(fac(x))) | |
x = 1 | |
while R(x) != 8001: | |
x += 1 | |
print(x) |
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
# the problem statement had a few ambiguities | |
maxfreq = 2520.0 | |
freqs = [maxfreq / d for d in xrange(1, 901)] # (rounding, for example) | |
sums = [sum(freqs[:i]) for i in xrange(900)] | |
i = 0 | |
while sums[i] < sums[-1] / 2: # (and do I take the result that's just less | |
i += 1 # or just more?) | |
print i | |
# well, it seems I was lucky in my guesses |
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
# Ruby for easy regex | |
html = <<STRING | |
<html> | |
<head> | |
<title>Embedly Apply Document</title> | |
</head> | |
<body> | |
<article> | |
<p>ncetta. Velit ribeye shoulder, et ball tip venison incididunt ut pork chop exercitation spare ribs f</p> | |
<div> | |
<span>lit ribeye shoulder,</span> | |
<p>owl, turducken flank ball tip adipisicing short ribs ham hock anim. Pastrami elit jowl, esse ground </p> | |
<span>aola ground round ba</span> | |
<span>ccaecat. Adipisicing</span> | |
</div> | |
<span> aliqua occaecat. Ad</span> | |
<div> | |
<span>aboris jerky ham sin</span> | |
<span>nt laborum id pork l</span> | |
</div> | |
<span>boris jerky ham sint</span> | |
<span>ound round ball tip</span> | |
<p> mollit laboris jerky ham sint nisi turkey aliqua. Pig non velit pork jowl, turducken flank ball tip</p> | |
<span>t jowl, esse ground</span> | |
<span>e tongue short ribs </span> | |
<p> t-bone excepteur magna ullamco sausage drumstick pancetta. Velit ribeye shoulder, et ball tip venis</p> | |
<p>ncetta incididunt nulla. Quis in t-bone excepteur magna ullamco sausage drumstick pancetta. Velit ri</p> | |
<p>is jerky ham sint nisi turkey aliqua. Pig non velit pork jowl, turducken flank ball tip adipisicing </p> | |
<p>adipisicing, hamburger ad fugiat pork loin venison aute bresaola ground round ball tip prosciutto t-</p> | |
<p>Ribeye ut pig aliqua occaecat. Adipisicing voluptate fatback, mollit laboris jerky ham sint nisi </p> | |
<p>am sint nisi turkey aliqua. Pig non velit pork jowl, turducken flank ball tip adipisicing short ribs</p> | |
<div> | |
<p>ken consequat meatloaf brisket pancetta incididunt nulla. Quis in t-bone excepteur magna ullamco sau</p> | |
<p>incididunt upork chop exercitation spare ribs fatback. Voluptate officia adipisicing, hamburger ad</p> | |
<p>llamco sausage drumstick pancetta. Velit ribeye shoulder, et ball tip venison incididunt ut pork cho</p> | |
<div> | |
<span> ground round deseru</span> | |
<p>ne. Swine consequat ex reprehenderit. Leberkase eu laborum et, irure tongue short ribs ham hock labo</p> | |
<p> adipisicing, hamburger ad fugiat pork loin venison aute bresaola ground round ball tip prosciutto t</p> | |
<p>iat pork loin venison aute bresaola ground round ball tip prosciutto t-bone. Swine consequat ex repr</p> | |
<div> | |
<p>is jerky ham sint nisi turkey aliqua. Pig non velit pork jowl, turducken flank ball tip adipisicing </p> | |
<p><span>non velit pork jowl,</span>t. Leberkase eu laborum et,irure tongue short ribs ham hest esse.R</p> | |
<p>giat pork loin venison aute bresaola ground round ball tip prosciutto t-bone. Swine consequat ex rep</p> | |
<p> prosciutto est esse. Ribeye ut pig aliqua occaecat. Adipisicing voluptate fatback, mollit laboris</p> | |
<p>llamco drumstick pancetta. Velit ribeye shoulder, et ball tip venison incididunt ut pork cho</p> | |
<div> | |
<p>oluptate fatback, mollit laboris jerky ham sint nisi turkey aliqua. Pig non velit pork jowl, turduck</p> | |
<p> velit pork jowl, turducken flank ball tip adipisicing short ribs ham hock anim. Pastrami elit jowl,</p> | |
<p>ipisicing short ribs ham hock anim. Pastrami elit jowl, esse ground</p> | |
<p>elit pork jowl, turducken flank ball tip adipisicing short ribs ham hock anim. Pastrami elit jowl, e</p> | |
</div> | |
</div> | |
</div> | |
</div> | |
<span>af brisket pancetta </span> | |
<p>isicing voluptate fatback, mollit laboris jerky ham sint nisi turkey aliqua. Pig non velit pork jowl</p> | |
<p>pancetta incididunt nulla. Quis in t-bone excepteur magna ullamco sausage drumstick pancetta. Velit</p> | |
<p>nisi turkey aliqua. Pig non velit pork jowl, turducken flan ball tip adipisicing short ribs ham hoc</p> | |
<span>cing short ribs ham </span> | |
<p>ciutto est esse. Ribeye ut pig aliqua occaecat. Adipisicing voluptate fatback, mollit laboris jerky</p> | |
<p>rehenderit. Leberkase eu laborum et, irure tongue short ribs ham hock labore capicola prosciutto est</p> | |
<div> | |
<span>atback. Voluptate of</span> | |
<p>nsequat ex reprehenderit. Leberkase eu laborum et, irure tongue short ribs ham hock labore capicola </p> | |
<span>lder, et ball tip ve</span> | |
</div> | |
<span>wine consequat ex re</span> | |
<p> et, irure tongue short ribs ham hock labore capicola prosciutto est esse. Ribeye ut pig aliqua occ </p> | |
<p>pork jowl, turducken flank ball tip adipisicing short ribs ham hock anim. Pastrami elit jowl, esse g</p> | |
<span>k loin venison aute </span> | |
<p>at ex reprehenderit. Leberkase eu laborum et, irure tongue short ribs ham hock labore capicola prosc</p> | |
<p>t pancetta incididunt nulla. Quis in t-bone excepteur magna ullamco sausage drumstick pancetta. Veli</p> | |
<div> | |
<p>ound round ball tip prosciutto t-bone. Swine consequat ex reprehenderit. Leberkase eu laborum et, ir</p> | |
</div> | |
<span>ure tongue short rib</span> | |
<div> | |
<span>ut pork chop exercit</span> | |
<p> ham, cow consectetur chicken consequat meatloaf brisket pancetta nulla. Quis in t-bone e</p> | |
</div> | |
<p>nison incididunt ut pork chop exercitation spare ribs fatback. Voluptate officia adipisicing, hambur</p> | |
<div> | |
<div> | |
<span>equat ex reprehender</span> | |
<p>a ullamco sausage | |
drumstick pancetta. Velit ribeye shoulder, et ball tip venison incididunt ut | |
pork </p> | |
<span>urducken flank ball </span> | |
</div> | |
</div> | |
<p>ll tip venison incididunt ut pork chop exercitation spare ribs fatback. Voluptate officia adipisicin</p> | |
</article> | |
</body> | |
</html> | |
STRING | |
level = 0 | |
plevels = [] | |
html.scan(/<.*?>/) do |tag| | |
if tag =~ /<\/.*>/ | |
level -= 1 | |
else | |
level += 1 | |
if tag == "<p>" | |
plevels << level | |
end | |
end | |
end | |
mean = plevels.reduce(:+).to_f / plevels.length | |
var = plevels.reduce(0) { |memo, x| memo + (x - mean)**2 } / plevels.length | |
stdev = Math.sqrt(var) | |
puts stdev |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment