~kameliya/tolcalc

ref: 7342c91d0f3a4728fd1455aed4cedf085a64ae0f tolcalc/tolcalc -rwxr-xr-x 610 bytes
7342c91dAshe Connor clean 1 year, 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env ruby
#
# Formula per http://tolerancecalculator.paperplane.io/.

def usage
  STDERR.puts "#{File.basename $0} last [desired] 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