Menu
CoddyTech

Integer Arithmetic

Lesson 4 of 48 in Coddy's Ruby for Dart Developers course.

Dart ~/ truncates division toward zero, while % is a nonnegative modulo for a positive divisor. Ruby integer / floors and % follows the divisor’s sign, so the paired negative-input results differ. Dart native and web numeric representations differ, with BigInt available separately; Ruby Integer grows automatically. Preserve the intended arithmetic contract.

Dart: complete program


void main() {
print("${-7 ~/ 3}:${-7 % 3}");
}

Ruby: complete program

puts(-7 / 3)
puts(-7 % 3)
puts(7.0 / 2)
challenge icon

Challenge

Easy

Input is nonnegative minutes up to 100000. Return hours and remaining minutes separated by a colon, without zero padding.

Return text from solve(input) without printing. The locked driver prints the returned text with one final newline and checks required public APIs independently.

Your code goes in exercise.rb. main.rb holds the supplied input/output code and cannot be edited.

Try it yourself

require_relative 'exercise'
def check(value)
  raise 'Public API check failed' unless value
end

puts solve(STDIN.read)
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Ruby for Dart Developers

Practice on your own: Online Ruby compiler