Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8331017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:17:44+00:00 2026-06-09T02:17:44+00:00

I am working on the coding kata Roman Numerals defined here . While I

  • 0

I am working on the coding kata Roman Numerals defined here. While I have finished it and am not stuck I do have a question that I need help answering.

Here is where my question sits:

class Fixnum
  NUMERALS = [
    ['V', 5], ['IV', 4], ['I', 1]
  ]
  def to_roman
    roman = ""
    number = self
    for key, value in NUMERALS
      count, number = number.divmod(value)
      roman << (key * count)
    end
    roman
  end
end

When I execute divmod on say the number 5, like so

5.to_roman

It returns V. And that makes sense because

5.divmod(5) => 1, 0

But how does this code above not do the same with

5.divmod(1) => 5, 0

So how is it returning V and not IIIII, since it’s just appending the key (I) times count (5). Somehow it’s obviously correctly returning V instead of IIIII but i’m not sure where that logic is. Any help would be greatly appreciated. Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T02:17:45+00:00Added an answer on June 9, 2026 at 2:17 am

    Your code never executes 5.divmod(1). The first time it executes the loop, key is ‘V’ and value is 5. It then executes 5.divmod(5) and afterwards, number == 0. So in the next iteration of the loop, when key is ‘IV’ and value is 4, it executes 0.divmod(4), resulting in count == 0 and nothing being added to the string.

    But this code is weird, because 9.to_roman returns ‘VIV’.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Latelly I've been working with multi-thread coding, after a while writing I realized that
Here is the coding in which hover is working inf firefox but not in
I'm not currently working on a coding project that is trying to implement this,
I tried working with this coding posted on Nara's question , but I'm not
I am working on some form coding in PHP, and I have everything working
I have a problem in my coding which was working fine with an older
I'm currently working at home, but it's not always an ideal environment for coding.
I am working on a coding problem and I need to check whether a
I have been coding a design I had been working on for a week
I've recently been coding a lot in both Objective C while also working on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.