Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A little division script for Discrete Math.
a = ARGV[0].to_i
d = ARGV[1].to_i
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}"
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
puts "\nInput: a: #{a}; d: #{d}"
puts "Output: q: #{q}; r: #{r}\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment