Skip to content

Instantly share code, notes, and snippets.

@RSully
Created February 10, 2012 23:07
Show Gist options
  • Save RSully/1793860 to your computer and use it in GitHub Desktop.
Save RSully/1793860 to your computer and use it in GitHub Desktop.
Challenged from apply.embed.ly
def nBang(n):
mul = 1
for i in xrange(1,n+1):
mul *= i
return mul
def R(n):
bang = str(nBang(n))
sum = 0
for i in xrange(0, len(bang)):
sum += int(bang[i])
return sum
n = 0
while R(n) != 8001:
n += 1
print "Found value %d which returns 8001" % (n)
print "Testing... %d" % (R(n))

This challenge didn't require code. It did however require me to re-type this entire message because TextMate decided CMD+R should refresh this page, after CMD+SHIFT+R wouldn't bring up my PHP cmd for the next file below.

Anyways, I opened up http://apply.embed.ly/static/data/2.html with Safari, grabbed the source and threw it into TextMate and removed any lines without <article> or <p>.

I then made a table of the index of each <p> and the amount I counted (I just eyeballed it):

Index 1: 19
Index 2: 8
Index 3: 3
Index 4: 5
Index 5: 4

Then I switched it into a string: ...

1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,5,5,5,5,5,4,4,4,4

And inputted it to this website: http://easycalculation.com/statistics/standard-deviation.php

I did notice you didn't round up to 1.5, and that threw me off at first. Oh wells.

<?php
$first = 2520;
$words = 900;
$wordCounts = array();
for ($i = 0; $i < $words; $i++) {
$wordCounts[$i] = $first / ($i + 1);
}
$totalWordAmount = 0;
for ($i = 0; $i < count($wordCounts); $i++) {
$totalWordAmount += $wordCounts[$i];
}
printf("Word amount: %d\n", $totalWordAmount);
$halfText = $totalWordAmount / 2;
printf("Half-text: %d\n", $halfText);
$plsZero = $halfText;
for ($i = 0; $i < count($wordCounts); $i++) {
$plsZero -= $wordCounts[$i];
if ($plsZero <= 0) { $i++; break; }
}
printf("At \$i = %d, plsZero = %f\n", $i, $plsZero);
?>
@RSully
Copy link
Author

RSully commented Feb 11, 2012

As far as challenge 2, I found someone else telling me the answer was 1.41 (or something that didn't round up to 1.5) Maybe the site I used is incorrect, or maybe I have one index wrong? (Or maybe the other person was wrong)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment