aboutsummaryrefslogtreecommitdiff
path: root/challenge-227/lubos-kolouch/python
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2023-07-31 15:49:22 +0800
committer冯昶 <fengchang@novel-supertv.com>2023-07-31 15:49:22 +0800
commite7b6313261ef4541d4dcc303c46ef0d886649b70 (patch)
tree8cff819a2036dd8d0172b6343b0a199d7b81721a /challenge-227/lubos-kolouch/python
parent4fda4a4a398e64921020704733556a2ec6dae78a (diff)
parente511966ce2280dbedb2c916d9e6254708800639e (diff)
downloadperlweeklychallenge-club-e7b6313261ef4541d4dcc303c46ef0d886649b70.tar.gz
perlweeklychallenge-club-e7b6313261ef4541d4dcc303c46ef0d886649b70.tar.bz2
perlweeklychallenge-club-e7b6313261ef4541d4dcc303c46ef0d886649b70.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-227/lubos-kolouch/python')
-rw-r--r--challenge-227/lubos-kolouch/python/ch-1.py19
-rw-r--r--challenge-227/lubos-kolouch/python/ch-2.py44
2 files changed, 63 insertions, 0 deletions
diff --git a/challenge-227/lubos-kolouch/python/ch-1.py b/challenge-227/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..1a2e1d0042
--- /dev/null
+++ b/challenge-227/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from datetime import datetime, timedelta
+
+
+def friday_13ths(year):
+ dt = datetime(year, 1, 1)
+ friday_13_count = 0
+
+ while dt.year == year:
+ if dt.weekday() == 4 and dt.day == 13:
+ friday_13_count += 1
+ dt += timedelta(days=1)
+
+ return friday_13_count
+
+
+print(friday_13ths(2023)) # 2
diff --git a/challenge-227/lubos-kolouch/python/ch-2.py b/challenge-227/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..9c2e4a9ee2
--- /dev/null
+++ b/challenge-227/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import roman
+
+
+def roman_maths(expr):
+ # Parse the expression into two Roman numerals and the operation
+ num1, op, num2 = expr.split()
+ num1 = roman.fromRoman(num1.upper())
+ num2 = roman.fromRoman(num2.upper())
+ # Perform the operation
+ if op == '+':
+ result = num1 + num2
+ elif op == '-':
+ result = num1 - num2
+ elif op == '*':
+ result = num1 * num2
+ elif op == '/':
+ if num2 == 0:
+ return "non potest" # they didn't do fractions
+ result = num1 // num2
+ elif op == '**':
+ result = num1 ** num2
+ else:
+ return "Invalid operation"
+ # Check the result
+ if result <= 0:
+ return "nulla" if result == 0 else "non potest" # they didn't do negative numbers
+ elif result > 3999:
+ return "non potest" # they only went up to 3999
+ # Convert the result back into a Roman numeral
+ return roman.toRoman(result)
+
+
+print(roman_maths("IV + V")) # should print IX
+print(roman_maths("M - I")) # should print CMXCIX
+print(roman_maths("X / II")) # should print V
+print(roman_maths("XI * VI")) # should print LXVI
+print(roman_maths("VII ** III")) # should print CCCXLIII
+print(roman_maths("V - V")) # should print nulla
+print(roman_maths("V / II")) # should print non potest
+print(roman_maths("MMM + M")) # should print non potest
+print(roman_maths("V - X")) # should print non potest