public
Last active

A little division script for Discrete Math.

  • Download Gist
division.rb
Ruby
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
a = ARGV[0].to_i
d = ARGV[1].to_i
 
begin
raise '`a` (first argument) must be a non-negative integer' unless a >= 0
raise '`d` (second argument) must be a positive integer' unless d > 0
rescue Exception => e
puts "Error: #{e.message}"
Process.exit
end
 
r = a
q = 0
counter = 0
 
puts "\n"
loop do
puts "Counter: #{counter}; r: #{r}; q: #{q}"
break if r < d
r -= d
q += 1
counter += 1
end
 
puts "\nInput: a: #{a}; d: #{d}"
puts "Output: q: #{q}; r: #{r}\n\n"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.