aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2020-02-10 11:57:13 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2020-02-10 11:57:13 +0000
commit35fbcbb0b0938a38f6d2d6159fe319cdedb5fc59 (patch)
treec94f7b787ed5d0aeca339a32fd8e57198b73689a
parentd5741960b9b2f50c21d2efd4975281380fe69ef7 (diff)
downloadperlweeklychallenge-club-35fbcbb0b0938a38f6d2d6159fe319cdedb5fc59.tar.gz
perlweeklychallenge-club-35fbcbb0b0938a38f6d2d6159fe319cdedb5fc59.tar.bz2
perlweeklychallenge-club-35fbcbb0b0938a38f6d2d6159fe319cdedb5fc59.zip
- Added solutions by Orestis Zekai.
-rw-r--r--challenge-047/orestis-zekai/python/ch-1.py53
-rw-r--r--challenge-047/orestis-zekai/python/ch-2.py13
2 files changed, 66 insertions, 0 deletions
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