Skip to content

Instantly share code, notes, and snippets.

@deevis
Last active March 31, 2020 15:29
Show Gist options
  • Select an option

  • Save deevis/0655993eb75b18115936592e0ec0ca0c to your computer and use it in GitHub Desktop.

Select an option

Save deevis/0655993eb75b18115936592e0ec0ca0c to your computer and use it in GitHub Desktop.
Program to display a frequency histogram of rational values determined by month divided by day values over the course of the next year
# Program to display a frequency histogram of rational values
# determined by month divided by day values over the course of the next year
# For example, March 30 is 3/30 = 0.1
require 'active_support/all'
vals = (0...365).map{|x| d = x.days.from_now; [d.strftime("%m/%d"), d.strftime("%m").to_f / d.strftime("%d").to_f]}
# print the results
# vals.each{|v| puts "#{v[0]} #{v[1]}"};nil
counts = Hash.new(0); vals.each{|v| counts[v[1]] += 1}
counts.sort{|a,b| b[1] <=> a[1]}.each{|val, count| puts "#{count} ==> #{val}"};nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment