Skip to content

Instantly share code, notes, and snippets.

@mindscratch
Created September 19, 2011 01:22
Show Gist options
  • Select an option

  • Save mindscratch/1225808 to your computer and use it in GitHub Desktop.

Select an option

Save mindscratch/1225808 to your computer and use it in GitHub Desktop.
80th percentile
values = [1, 9, 3, 12, 29, 30, 33, 17, 5, 0, 23, 7, 19, 18, 32, 56, 34]
sorted = values.sort
percentile = 0.80
num_vals = (percentile * sorted.count).ceil
puts "Values within the #{(percentile * 100).to_i}th percentile: #{sorted[0, num_vals]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment