~kameliya/tolcalc

cee04378332c4e1993efada30fd00560a59f18a6 — Ashe Connor 1 year, 4 months ago
init
1 files changed, 28 insertions(+), 0 deletions(-)

A tolcalc
A  => tolcalc +28 -0
@@ 1,28 @@
#!/usr/bin/env ruby

def usage
  STDERR.puts "#{File.basename $0} last [desired] days"
  STDERR.puts "#{File.basename $0} last days"
  exit
end

usage if ARGV.length < 2 || ARGV.length > 3

last = ARGV[0].to_i
if ARGV.length == 2
  desired = nil
  days = ARGV[1].to_i
else
  desired = ARGV[1].to_i
  days = ARGV[2].to_i
end

usage if last == 0 || desired == 0 || days == 0

d = 280.0595565 * (days.to_f ** (-0.41256)) * last.to_f / 100.0 - last.to_f

puts "diff:          #{d.to_i}"
if desired != nil
  puts "to hit target: #{(desired + d).to_i}"
  puts "effective:     #{(desired - d).to_i}"
end