From 5c352e3f3425553306cbc7d34a8d735cee29e7a7 Mon Sep 17 00:00:00 2001 From: Kyle Gunter Date: Tue, 25 May 2021 14:02:31 -0500 Subject: [PATCH 1/6] Sarah and Kyle pt1 --- js/romanNumerals.js | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/js/romanNumerals.js b/js/romanNumerals.js index c816e81..955422d 100644 --- a/js/romanNumerals.js +++ b/js/romanNumerals.js @@ -1,3 +1,36 @@ exports.toRoman = function(num) { - + let ansStr = ''; + do { + if(num >= 1000){ + num -= 1000; + ansStr += 'M' + } + else if (num >= 500){ + num -= 500; + ansStr += 'D' + } + else if (num >= 100){ + num -= 100; + ansStr += 'C' + } + else if (num >= 50){ + num -= 50; + ansStr += 'L' + } + else if (num >= 10){ + num -= 10; + ansStr += 'X' + } + else if (num >= 5){ + num -= 5; + ansStr += 'V' + } + else { + num -= 1; + ansStr += 'I' + } + } while (num > 0); + console.log(ansStr) }; + + From 58684c72baba4c301086df56054b90850789c9e3 Mon Sep 17 00:00:00 2001 From: Kyle Gunter Date: Tue, 25 May 2021 14:29:30 -0500 Subject: [PATCH 2/6] Sarah and Kyle pt2 --- js/romanNumerals.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/js/romanNumerals.js b/js/romanNumerals.js index 955422d..0586615 100644 --- a/js/romanNumerals.js +++ b/js/romanNumerals.js @@ -1,3 +1,6 @@ +//pt 1* +//pt 2 + exports.toRoman = function(num) { let ansStr = ''; do { @@ -15,22 +18,32 @@ exports.toRoman = function(num) { } else if (num >= 50){ num -= 50; - ansStr += 'L' + ansStr += 'L'; } else if (num >= 10){ num -= 10; - ansStr += 'X' + ansStr += 'X'; } else if (num >= 5){ num -= 5; - ansStr += 'V' + ansStr += 'V'; + } + else if (num === 4){ + num -= 4; + ansStr += 'IV'; } else { num -= 1; ansStr += 'I' } } while (num > 0); - console.log(ansStr) + return ansStr; }; +/* +if (num >= 900 && num < 1000) { + num -= 900 + ansStr += "CM"} // for times sake -- conditions would reflect this + +/* From a9def6a18f337ef235ef112baf95f0557e33516b Mon Sep 17 00:00:00 2001 From: Kyle Gunter Date: Thu, 27 May 2021 02:52:39 -0500 Subject: [PATCH 3/6] "Kyle Python" --- python/roman_numerals.py | 62 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/python/roman_numerals.py b/python/roman_numerals.py index cbf8571..4d230e1 100644 --- a/python/roman_numerals.py +++ b/python/roman_numerals.py @@ -1,2 +1,62 @@ +# 1. Write a method TO_ROMAN, TO_ROMAN takes in INPUT_NUMBER (an arabic number) +# 2. Create a OUTPUT string, set to '' +# 3. Create a ROMAN_NUMERAL_TO_ARABIC_MAP that includes roman numerals as keys, arabic numbers as values +# 4. Iterate over ROMAN_NUMERAL_TO_ARABIC_MAP, keep track of ROMAN_NUMERAL and ARABIC_NUMBER +# 5. Set EVENLY_DIVISIBLE_TIMES = INPUT_NUMBER / ARABIC_NUMBER: +# 6. If EVENLY_DIVISIBLE_TIMES >= 1 + # 6a. Append ROMAN_NUMERAL to OUTPUT EVENLY_DIVISIBLE_TIMES + # 6b. Subtract ARABIC_NUMBER from INPUT_NUMBER EVENLY_DIVISIBLE_TIMES +# 7. Return OUTPUT + +#python +# I : 1 +# V : 5 +# X -> 10 +# L -> 50 +# C -> 100 +# D -> 500 +# M -> 1000 + +import math + + def to_roman(num): - # write your code here! \ No newline at end of file + + roman_str = '' + + dict_roman_num = { + 'I' : 1, + 'V' : 5, + 'X' : 10, + 'L' : 50, + 'C' : 100, + 'D' : 500, + 'M' : 1000 + } + + #print(type(dict_roman_num[1])) # 1 + + for key in dict_roman_num: + include = dict_roman_num.get(key) + roman_char = dict_roman_num.values() + + result = math.floor(num / include) + + print(key, include, roman_char, result) + + for val in range(result): + val += 1 + roman_str = roman_str + roman_char(val) + + num = num % include + + if num == 0: + break + + #print(include,roman_char) + + + + + + From 0e442ee4372e8f927fd46e31cafefa1c331e8984 Mon Sep 17 00:00:00 2001 From: Kyle Gunter Date: Thu, 27 May 2021 02:55:00 -0500 Subject: [PATCH 4/6] Kyle Python --- python/__pycache__/roman_numerals.cpython-39.pyc | Bin 0 -> 619 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 python/__pycache__/roman_numerals.cpython-39.pyc diff --git a/python/__pycache__/roman_numerals.cpython-39.pyc b/python/__pycache__/roman_numerals.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cc842c74a0eccce6dbf6d9119a79da00707c16d6 GIT binary patch literal 619 zcmYjPO>Yx15S_92!wqdDBt(no4`2@vi3=B0RcbDkN;x1Zv=R!d*d$RlyNT^ZisU^N z^}ui7&>lJQe|+V_-nqbuaRO4tn)f{OJf5-S;^3eMWT&scf4GPNeuQAx7zL-~<^h2O zi6!J9ndF}#M~QDBi#k%^a*TognIH~+MsB_kNNh1w$w z3l3y&&h#SlE;f#$t;>7fh5cJyB8!t=Z50VKif7b&x!93V?Qo_oCV_|D^n$1{&Z zkFRv7%o5Kh%KGF}Q8vo>Xi?Z{9)B$BTKjmZXO;D_E~<&jM9!;bk?-kxQB)&ib>5e= zu^nw=l02WQb)L?uaoI?f_qM`#T4 Date: Thu, 27 May 2021 02:56:10 -0500 Subject: [PATCH 5/6] "kylewgunter" --- js/romanNumerals.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/romanNumerals.js b/js/romanNumerals.js index 0586615..5bfcded 100644 --- a/js/romanNumerals.js +++ b/js/romanNumerals.js @@ -8,7 +8,7 @@ exports.toRoman = function(num) { num -= 1000; ansStr += 'M' } - else if (num >= 500){ + else duh (num >= 500){ num -= 500; ansStr += 'D' } From 8a3f5938ca427fa0522db4d0023162e928265e13 Mon Sep 17 00:00:00 2001 From: Kyle Gunter Date: Fri, 4 Jun 2021 00:33:42 -0500 Subject: [PATCH 6/6] Kyle PY Solution --- python/.gitignore | 1 + .../__pycache__/roman_numerals.cpython-39.pyc | Bin 619 -> 738 bytes python/roman_numerals.py | 77 ++++++++---------- python/roman_numerals_spec.py | 43 +++++++++- 4 files changed, 74 insertions(+), 47 deletions(-) create mode 100644 python/.gitignore diff --git a/python/.gitignore b/python/.gitignore new file mode 100644 index 0000000..bee8a64 --- /dev/null +++ b/python/.gitignore @@ -0,0 +1 @@ +__pycache__ diff --git a/python/__pycache__/roman_numerals.cpython-39.pyc b/python/__pycache__/roman_numerals.cpython-39.pyc index cc842c74a0eccce6dbf6d9119a79da00707c16d6..917f694fa21691bd1501fd9ec8e47f30bfdf1989 100644 GIT binary patch literal 738 zcmZ`%v5wO~5S>}C9VZv(f`o+Nj-C_{2_c|B2q|eI-Ccu-BI{7FGA3u8V<&3|5y`H& z9zNiTq@>^j_?2yGNDUPgv++r!VXb*H^JZuF&B}r2HGtRWZ{OdYI{-gSvcCi;uh_EN z3zmZL?|qd91|^`P`j)ZKl=7% z;DG`2U|Tcc);1swnBhB~##3MPPBr$~^)>cYx15S_92!wqdDBt(no4`2@vi3=B0RcbDkN;x1Zv=R!d*d$RlyNT^ZisU^N z^}ui7&>lJQe|+V_-nqbuaRO4tn)f{OJf5-S;^3eMWT&scf4GPNeuQAx7zL-~<^h2O zi6!J9ndF}#M~QDBi#k%^a*TognIH~+MsB_kNNh1w$w z3l3y&&h#SlE;f#$t;>7fh5cJyB8!t=Z50VKif7b&x!93V?Qo_oCV_|D^n$1{&Z zkFRv7%o5Kh%KGF}Q8vo>Xi?Z{9)B$BTKjmZXO;D_E~<&jM9!;bk?-kxQB)&ib>5e= zu^nw=l02WQb)L?uaoI?f_qM`#T4 10 -# L -> 50 -# C -> 100 -# D -> 500 -# M -> 1000 - import math - - def to_roman(num): - roman_str = '' - dict_roman_num = { - 'I' : 1, - 'V' : 5, - 'X' : 10, - 'L' : 50, - 'C' : 100, + 'M' : 1000, + 'CM': 900, 'D' : 500, - 'M' : 1000 + 'CD': 400, + 'C' : 100, + 'XC': 90, + 'L' : 50, + 'XL': 40, + 'X' : 10, + 'IX': 9, + 'V' : 5, + 'IV': 4, + 'I' : 1 } - - #print(type(dict_roman_num[1])) # 1 - - for key in dict_roman_num: - include = dict_roman_num.get(key) - roman_char = dict_roman_num.values() - - result = math.floor(num / include) - - print(key, include, roman_char, result) - - for val in range(result): - val += 1 - roman_str = roman_str + roman_char(val) - - num = num % include - - if num == 0: - break - - #print(include,roman_char) - - - - + + roman_char_list = [] # target list for appended roman chars from dict + roman_value_list = [] # target list for appended values from dict + + roman_str = '' + + for roman_char, roman_value in dict_roman_num.items(): # + roman_char_list.append(roman_char) + roman_value_list.append(roman_value) + # Create iterable lists from dict items of key, values + + + index = 0 + while num > 0: + for x in range(math.floor(num /roman_value_list[index])): #Iterate through the range of number / index at value list + roman_str += roman_char_list[index] # roman string adds I + # print(roman_str, roman_char_list[index]) + num -= roman_value_list[index] # num param decrements to 0 and breaks out + # print(roman_value_list[index]) + index += 1 # add 1 to index value to iterate through lists + + return roman_str diff --git a/python/roman_numerals_spec.py b/python/roman_numerals_spec.py index 39d195e..abf7019 100644 --- a/python/roman_numerals_spec.py +++ b/python/roman_numerals_spec.py @@ -1,6 +1,41 @@ +import unittest from roman_numerals import to_roman -print(to_roman(1) == 'I') -print(to_roman(3) == 'III') -print(to_roman(4) == 'IV') -# add tests to cover different edge cases +class RomanNumeralsTestCase(unittest.TestCase): + + + # add tests to cover different edge cases + def test_output(self): + self.assertEqual(to_roman(1), 'I') + self.assertEqual(to_roman(3), 'III') + self.assertEqual(to_roman(4), 'IV') + self.assertEqual(to_roman(944), 'CMXLIV') + self.assertEqual(to_roman(150), 'CL') + self.assertEqual(to_roman(2400), 'MMCD') + + + # Output correct roman numerals + + + def test_str(self): + self.assertNotEqual(to_roman(1), str) + + # output returns a string type + + + def test_returns_modern_numerals(self): + self.assertNotEqual(to_roman(4), 'IIII') + + # output not in lazy roman numerals + + # IV -> 4 + # IX -> 9 + # XIV -> 14 + # XLIV -> 44 + # CMXLIV -> 944 + + # to_roman(4) # 'IV' + # to_roman(944) # 'CMXLIV' + # to_roman(150) # CL +if __name__ == '__main__': + unittest.main() \ No newline at end of file