Created
February 10, 2012 17:47
-
-
Save rogerbraun/1791212 to your computer and use it in GitHub Desktop.
Revisions
-
rogerbraun revised this gist
Feb 10, 2012 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ def check_number(n) n_f = 1.upto(n).inject(&:*) sum_of_digits = n_f.to_s.each_char.inject(0) do |res, v| res += v.to_i end [n_f, sum_of_digits] end found = false -
rogerbraun created this gist
Feb 10, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ def check_number(n) n_f = 1.upto(n).inject(&:*) quersumme = n_f.to_s.each_char.inject(0) do |res, v| res += v.to_i end [n_f, quersumme] end found = false i = 1 while not found do res = check_number(i) puts "Checking #{i}!, is #{res[0]}, sum of digits #{res[1]}" i += 1 found = true if res[1] == 8001 end 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ require "open-uri" require "nokogiri" url = "http://apply.embed.ly/static/data/2.html" doc = Nokogiri::HTML(open(url)) article = doc.css("article").first def mark_depth(start, n) if start.name == "p" then res = n else res = nil end children = start.children.map do |child| mark_depth(child, n+1) end [res, children].flatten.compact end res = mark_depth(article, 1) mean = res.inject(&:+) / res.count.to_f deviations = res.map{|n| (n - mean) * (n - mean)} deviations_avg = deviations.inject(&:+) / deviations.count.to_f std_dev = Math.sqrt(deviations_avg) puts std_dev 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ require "pry" nums = 1.upto(900) multiplier = nums.inject(&:+) frequencies = nums.each_with_index.map{|n, index| multiplier / (index + 1) } all = frequencies.inject(&:+) half = all / 2 frequencies.each_with_index.inject(0) do |result, (value, index)| result += value if result >= half puts index + 1 break end result end