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
#include<stdio.h> | |
#include<openssl/sha.h> | |
#include<time.h> | |
#include<stdlib.h> | |
#include<string.h> | |
static void compute_stream_hash(char *a, char *b, char *c) | |
{ | |
unsigned char sha1[20]; | |
unsigned char hash[(20 * 2) + 1]; |
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
def harmonic_sum n | |
(1..n).each.inject(0) {|sum, i| sum += (1.0 / i)} | |
end | |
total_words = 2520 * harmonic_sum(900) | |
half = total_words / 2 | |
sum = 0 | |
(1..900).each do |i| | |
sum += 1.0 / i |
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
require 'rubygems' | |
require 'hpricot' | |
require 'net/http' | |
def standard_deviation arr | |
mean = arr.each.inject(0) {|sum, i| sum += i; sum} / arr.length.to_f | |
new_arr = arr.each.map{|i| (i - mean) ** 2} | |
(new_arr.each.inject(0) {|sum, i| sum += i; sum} / new_arr.length.to_f) ** 0.5 | |
end |
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
def fact n | |
return 1 if n == 0 | |
n.downto(1).inject(1) {|res, i| res *= i; res} | |
end | |
def sum n | |
n.to_s.each_char.map{|ch| ch.to_i}.inject(0) {|sum, i| sum += i; sum} | |
end | |
(400..1000).each do |i| # fact 400 has 869 digits...close to the 889 required |