Last active
December 24, 2015 04:59
-
-
Save jacksonrayhamilton/6747186 to your computer and use it in GitHub Desktop.
A little division script for Discrete Math.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment