Sha256: 9675d5e2fb4d190ba6aa7e14b21f9eb9bf0a336eaf44bbba836772d017c1b22c

Contents?: true

Size: 603 Bytes

Versions: 2

Compression:

Stored size: 603 Bytes

Contents

#!/usr/bin/ruby

require 'pp'
require 'lib/benford'

class Float
  def perc
    "%.1f%" % (self * 100)
  end
end

beginning = Time.now

file = File.open(ARGV[0], "rb")
b = Benford.new
data = file.read.gsub(',', '').scan(/\w+/) # remove , for correct parsing of '123,456,78'
b.load! data

puts ["digit", "count", "sample", "benford", "deviation"].join("\t\t")

(1..9).each do |d|
  d = d.to_s # the digits are string
  puts [d, b.counts[d], b.distribution[d].perc , b.law[d].perc, b.deviation[d].perc ].join("\t\t")
end

puts "-> Analysis of #{b.numbers.count} samples in #{Time.now - beginning} seconds"

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
benford-0.0.1 bin/benford
benford-0.0.0 bin/benford