From d2aa2ab951a00427037aaf214b0e20e0d41a8b28 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Wed, 26 Jul 2023 00:42:23 +0100 Subject: - Added solutions by Robert DiCicco. - Added solutions by Mark Anderson. - Added solutions by Andrew Shitov. - Added solutions by Simon Proctor. - Added solutions by Luca Ferrari. - Added solutions by David Ferrone. - Added solutions by Thomas Kohler. - Added solutions by Robbie Hatley. - Added solutions by Ali Moradi. - Added solutions by W. Luis Mochan. - Added solutions by E. Choroba. - Added solutions by Roger Bell_West. - Added solutions by Peter Campbell Smith. --- challenge-227/eric-cheung/python/ch-1.py | 13 ++++++++ challenge-227/eric-cheung/python/ch-2.py | 53 ++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100755 challenge-227/eric-cheung/python/ch-1.py create mode 100755 challenge-227/eric-cheung/python/ch-2.py (limited to 'challenge-227/eric-cheung/python') diff --git a/challenge-227/eric-cheung/python/ch-1.py b/challenge-227/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..1286f37671 --- /dev/null +++ b/challenge-227/eric-cheung/python/ch-1.py @@ -0,0 +1,13 @@ + +from datetime import datetime + +nYearGiven = 2023 ## Example + +nFri_13th_Count = len([nMonthLoop + 1 for nMonthLoop in range(12) if int(datetime(nYearGiven, nMonthLoop + 1, 13).strftime("%w")) == 5]) + +## for nMonthLoop in range(12): + ## strWeekDay = datetime(nYearGiven, nMonthLoop + 1, 13).strftime("%w") + ## if int(strWeekDay) == 5: + ## nFri_13th_Count = nFri_13th_Count + 1 + +print (nFri_13th_Count) diff --git a/challenge-227/eric-cheung/python/ch-2.py b/challenge-227/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..ce59ffaa51 --- /dev/null +++ b/challenge-227/eric-cheung/python/ch-2.py @@ -0,0 +1,53 @@ + +import roman + +nMaxLimit = 3999 + +def GetRomanArithOper (strInput): + + global nMaxLimit + + arrElem = strInput.split() + nInt_01 = roman.fromRoman(arrElem[0]) + strOperator = arrElem[1] + nInt_02 = roman.fromRoman(arrElem[2]) + + if strOperator == "+": + if nInt_01 + nInt_02 > nMaxLimit: + return "non potest" + return roman.toRoman(nInt_01 + nInt_02) + + if strOperator == "-": + if nInt_01 > nInt_02: + return roman.toRoman(nInt_01 - nInt_02) + if nInt_01 == nInt_02: + return "nulla" + return "non potest" + + if strOperator == "/": + if nInt_01 % nInt_02 == 0: + return roman.toRoman(int(nInt_01 / nInt_02)) + return "non potest" + + if strOperator == "*": + if nInt_01 * nInt_02 > nMaxLimit: + return "non potest" + return roman.toRoman(nInt_01 * nInt_02) + + if strOperator == "**": + if nInt_01 ** nInt_02 > nMaxLimit: + return "non potest" + return roman.toRoman(nInt_01 ** nInt_02) + + +## strGivenExpr = "IV + V" +## strGivenExpr = "M - I" +## strGivenExpr = "X / II" +## strGivenExpr = "XI * VI" +## strGivenExpr = "VII ** III" +## strGivenExpr = "V - V" +## strGivenExpr = "V / II" +## strGivenExpr = "MMM + M" +strGivenExpr = "V - X" + +print (GetRomanArithOper(strGivenExpr)) -- cgit