Created
February 13, 2012 15:21
-
-
Save gijoehosaphat/1817565 to your computer and use it in GitHub Desktop.
Embed.ly Challenge
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
//1 (Groovy) | |
BigInteger n(BigInteger number) { | |
return number > 1 ? number.multiply(n(--number)) : number | |
} | |
BigInteger r(BigInteger number) { | |
BigInteger nn = n(number) | |
BigInteger result = 0 | |
nn.toString().each { character -> | |
result += Integer.parseInt(character, 10) | |
} | |
return result | |
} | |
def num = 0 | |
while(r(num) != 8001) { | |
++num | |
} | |
num | |
//2 (JavaScript) | |
var depths = []; | |
var total = 0; | |
var crawl = function(nodeParent, depth) { | |
++depth; | |
for(var i in nodeParent.childNodes) { | |
var node = nodeParent.childNodes[i]; | |
if (node.nodeName === "P") { | |
depths.push(depth); | |
total += depth; | |
} | |
crawl(node, depth); | |
} | |
}; | |
crawl(document.getElementsByTagName("article")[0], 0); //Assuming the first article element on the page. | |
var stdDev = function(depth) { | |
return (depth - (total / depths.length)) * (depth - (total / depths.length)); | |
} | |
var stdDevTotal = 0; | |
for (var i in depths) { | |
stdDevTotal += stdDev(depths[i]); | |
} | |
console.log(Math.sqrt(stdDevTotal/depths.length)); | |
//3 (Groovy) | |
def total = 0 | |
def wordCounts = [] | |
for(def i = 900; i > 0; --i) { | |
total += (900 / i) | |
wordCounts.push((900 / i)) | |
} | |
def half = 0 | |
def i = wordCounts.size() - 1 | |
while(half < (total / 2)) { | |
half += wordCounts[i] | |
--i | |
} | |
(900 - i) - 1 // [0] Offset |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment