Skip to content

Instantly share code, notes, and snippets.

@tiegz
Last active August 29, 2015 14:04
Show Gist options
  • Save tiegz/fd8a79a3b3f2122284a7 to your computer and use it in GitHub Desktop.
Save tiegz/fd8a79a3b3f2122284a7 to your computer and use it in GitHub Desktop.
Growth rate of Expendables cast movie one-liner in Ruby
> ((((Nokogiri::HTML(open("http://en.wikipedia.org/wiki/The_Expendables_(film_series)#Cast_and_characters").read) / "#Cast_and_characters").first.parent.next_element) / "tr")[1..-1].map { |tr| (tr / "td").map { |td| td['colspan'].to_i > 0 ? ([td.text] * td['colspan'].to_i) : td.text } }).map(&:flatten).tap { |a| (0..2).map { |i| a.map { |row| row[i].blank? ? 0 : 1 }.sum }.tap { |a| puts "1->2: #{(a[1] - a[0]) / a[0].to_f}%"; pus "2->3: #{(a[2] - a[1]) / a[1].to_f}%" } } nil
1->2: 0.0
2->3: 0.26666666666666666
@CarBen
Copy link

CarBen commented Aug 4, 2014

👍

@selftext
Copy link

selftext commented Aug 4, 2014

💯

@kastner
Copy link

kastner commented Aug 6, 2014

❤️

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