Created
February 11, 2012 16:29
-
-
Save ramkalari/1801816 to your computer and use it in GitHub Desktop.
Embedly Challenge
This file contains hidden or 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
| def factorial(n): | |
| result = 1 | |
| for i in range(1, n+1): | |
| result = result * i | |
| return result | |
| def sum_digits(n): | |
| digits = [int(x) for x in str(n)] | |
| return sum(digits) | |
| def lowest_number(): | |
| result = 0 | |
| n = 1 | |
| while result != 8001: | |
| result = sum_digits(factorial(n)) | |
| n = n + 1 | |
| return n - 1 | |
| print lowest_number() |
This file contains hidden or 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
| <script> | |
| mean = function(numbers){ | |
| var n = numbers.length; | |
| var sum = 0; | |
| var i = 0; | |
| while( i < n ){ | |
| sum += numbers[i]; | |
| i++; | |
| } | |
| return sum / n ; | |
| }; | |
| variance = function(numbers){ | |
| var mu = mean(numbers); | |
| var n = numbers.length; | |
| var result = 0; | |
| var i = 0; | |
| while( i < n ){ | |
| result+= Math.pow( (numbers[ i ] - mu), 2 ); | |
| i++; | |
| } | |
| return result/n; | |
| }; | |
| stdev = function(numbers){ | |
| var result = Math.sqrt(variance(numbers)); | |
| return result; | |
| }; | |
| $(document).ready(function(){ | |
| var depth = []; | |
| var sum = 0; | |
| var paras = $("article p") | |
| var n = paras.length; | |
| paras.each(function(i){ | |
| depth[i] = $(this).parents().length; | |
| }); | |
| var stddev = stdev(depth); // returns 1.4 | |
| }); | |
| </script> |
This file contains hidden or 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
| $start_frequency = 2520 | |
| $total_uniques = 900 | |
| def get_total_words() | |
| total = 0 | |
| (1..900).each do |i| | |
| total = total + $start_frequency / i | |
| end | |
| return total | |
| end | |
| def number_unique_words() | |
| total_words = get_total_words() | |
| uniques_covered = 1 | |
| words_covered = 0 | |
| while uniques_covered <= $total_uniques | |
| words_covered += $start_frequency / uniques_covered | |
| uniques_covered+=1 | |
| if(words_covered >= total_words / 2) | |
| return uniques_covered | |
| end | |
| end | |
| end | |
| puts number_unique_words() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment