Comp Sci Converting Numbers into Roman numerals

  • Thread starter Thread starter Physics guy
  • Start date Start date
  • Tags Tags
    Numbers
Click For Summary
SUMMARY

The discussion focuses on converting numbers into Roman numerals, a common problem in computer science courses. A suggested method involves generating Roman numeral sequences and identifying patterns, specifically replacing the "IIII" pattern with "IV" and "VIIII" with "IX". The example of converting the number 1980 illustrates the breakdown into components using modulo arithmetic, resulting in the Roman numeral representation "M-CM-LXXX". This approach emphasizes the need for recognizing repetitions and applying efficient transformations.

PREREQUISITES
  • Understanding of Roman numeral conventions
  • Familiarity with basic programming concepts
  • Knowledge of modulo arithmetic
  • Experience with pattern recognition in strings
NEXT STEPS
  • Research algorithms for string manipulation in programming languages
  • Learn about efficient pattern replacement techniques
  • Explore advanced number conversion algorithms
  • Study the history and rules of Roman numerals
USEFUL FOR

Computer science students, software developers, and anyone interested in algorithm design and number conversion techniques.

Physics guy
Messages
23
Reaction score
10
Homework Statement
Write a program in python to convert number entered by a user to roman numerals
Relevant Equations
..
I have tried to solve this question for a while but I am not able to get the logic right.
 
Physics news on Phys.org
Show us what you have and use the code dialog box ( see < / > in the post editor menu next to the smiley face.

This is a common CS problem for introductory classes.

Have you tried the simpler approach of generating the numbers:

I, II, III, IIII, V, VI, VII, VIII, VIIII, X ...

and then looking for the ?IIII pattern and replacing it with the I(?+1) so that IIII is 0IIII which then transforms into IV and VIIII transforms into IX. Actually its a bit more general as you need to find any four repetitions and replace.

As an example, 1980 would be M-DCCCC-LXXX but DCCCC is written as CM and so the answer is M-CM-LXXX.

Using the simpler approach, you can then use modulo arithmetic to break a number down into its 1000*a + 500*b + 100*c + 50*d + 10*e + 5*f + g and then translate that to M*a + D*b + C*c + L*d + X*e + V*f + I*g where a,b,c,... are the number of times to repeat the roman numeral symbol.

I'm sure there are other more efficient approaches that can be found online.
 

Similar threads

  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 19 ·
Replies
19
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 20 ·
Replies
20
Views
4K
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K