Menu
CoddyTech

Integer Arithmetic

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

Lua division produces a numeric quotient, while Ruby divides two integers using floor division. Lua 5.3 and later distinguish integer and floating representations and add an integer-division operator; the examples here use math.floor and remain compatible with Lua 5.1 syntax. Ruby arbitrary-size integers differ from Lua fixed-size or floating numeric representations.

Lua: complete program

print(math.floor(-7 / 3))
print(-7 % 3)
print(7 / 2)

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 Lua Developers

Practice on your own: Online Ruby compiler