- Fork this gist, then "edit" the gist
- Fill out the questions below
- Click the "Add file" button and add your source code to the gist
- Submit by the due time as instructed in Zoom
Do not publish your code on a public repl.it or repo or other public means.
Write a recursive function that converts an integer into a string such that the number is represented in Roman Numerals in the most efficient way. eg, the number 4 could be written as 'IIII' but it's more efficient to use 'IV' since that's a shorter string Assume no number is greater than 4,000 Here are the Roman Numeral equivalents you'll need to know:
- M=1000
- CM=900
- D=500
- CD=400
- C=100
- XC=90
- L=50
- XL=40
- X=10
- IX=9
- V=5
- IV=4
- I=1
With a function that takes in an integer and return a string of that number in roman numerals
What assumptions will you make about this problem if you cannot ask any more clarifying questions? What are your reasons for making those assumptions?
I will need to do some simple math with conditional statements. If it doesn't hit one of the "milestones" for a new roman numeral character, I need that character with the symbol that represents the amount I will need to subtract.
It seems like I will need a lot of conditionals...but maybe there is a way to condense it
- Searching of Data
- Sorting of Data
- Pattern Recognition
- Build/Navigate a Grid
- Math
- Language API knowledge
- Optimization
Numbers and strings
Write out a few lines of initial pseudocode: (mid-level design, this should be short, and not be real code!)
check if argument is greater or less than a certain amount (check against largest first)
then do the same process with the remainder but skip first conditional
call func until number hits zero
the terminating scenario: when numbers hits zero
function toRoman(num) {
// your code goes here
}
console.log(toRoman(128)); // should return "CXXVIII"
console.log(toRoman(2000)); // should return "MM"
console.log(toRoman(2017)); // should return "MMXVII"
console.log(toRoman(1999)); // should return "MCMXCIX"
def to_roman(num)
# your code goes here
end
puts to_roman(128) # should return "CXXVIII"
puts to_roman(2000) # should return "MM"
puts to_roman(2017) # should return "MMXVII"
puts to_roman(1999) # should return "MCMXCIX"