From 35fbcbb0b0938a38f6d2d6159fe319cdedb5fc59 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Mon, 10 Feb 2020 11:57:13 +0000 Subject: - Added solutions by Orestis Zekai. --- challenge-047/orestis-zekai/python/ch-1.py | 53 ++++++++++++++++++++++++++++++ challenge-047/orestis-zekai/python/ch-2.py | 13 ++++++++ 2 files changed, 66 insertions(+) create mode 100644 challenge-047/orestis-zekai/python/ch-1.py create mode 100644 challenge-047/orestis-zekai/python/ch-2.py (limited to 'challenge-047') diff --git a/challenge-047/orestis-zekai/python/ch-1.py b/challenge-047/orestis-zekai/python/ch-1.py new file mode 100644 index 0000000000..014cc3b293 --- /dev/null +++ b/challenge-047/orestis-zekai/python/ch-1.py @@ -0,0 +1,53 @@ +# For sake of simplicity, we will consider that MMMCMXCIX is the largest number we can get +# This maps to 3999 + +# Helper dicitonairies +roman_dict = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} + +def romanToArab(number): + arabNumber = 0 + + for i in range(0, len(number)): + letter = str(number[i]) + value = roman_dict[letter] + + if (i < len(number) - 1): + if (value < roman_dict[str(number[i+1])]): + arabNumber -= value + else: + arabNumber += value + else: + arabNumber += value + + return arabNumber + + +def arabToRoman(number): + conv = [[1000, 'M'], [900, 'CM'], [500, 'D'], [400, 'CD'], [100, 'C'], [90, 'XC'], [50, 'L'], [40, 'XL'], [10, 'X'], [9, 'IX'], [5, 'V'], [4, 'IV'], [1, 'I']] + + result = '' + for denom, roman_digit in conv: + result += roman_digit*int((number/denom)) + number %= denom + + return result + +# Main +roman_input1 = 'MDCCCXCVII' +roman_input2 = 'IC' + +arabInput1 = romanToArab(roman_input1) +arabInput2 = romanToArab(roman_input2) + + +print('The roman number ' + roman_input1 + ' converts to ' + str(arabInput1)) +print('The roman number ' + roman_input2 + ' converts to ' + str(arabInput2)) + +arabSum = arabInput1 + arabInput2 +print('\nThe sum of the two numbers in arab is ' + str(arabSum) + '\n') + +if (arabSum > 3999): + print('The sum is greater than 3,999 so it will not be converted') +else: + romanSum = arabToRoman(arabSum) + print('The sum of the two numbers in roman is ' + romanSum) \ No newline at end of file diff --git a/challenge-047/orestis-zekai/python/ch-2.py b/challenge-047/orestis-zekai/python/ch-2.py new file mode 100644 index 0000000000..b2e745ac96 --- /dev/null +++ b/challenge-047/orestis-zekai/python/ch-2.py @@ -0,0 +1,13 @@ +gapfulNumbers = 0 +currentNum = 100 +numbers = [] + +while (gapfulNumbers < 20): + divisor = int(str(currentNum)[0] + str(currentNum)[-1]) + if (currentNum % divisor == 0): + gapfulNumbers += 1 + numbers.append(currentNum) + + currentNum += 1 + +print(numbers) \ No newline at end of file -- cgit