Skip to content

Commit 418f0e2

Browse files
JakubDotPygithub-actions[bot]
authored andcommitted
Automated update
1 parent 890be52 commit 418f0e2

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

output/common_directory_path.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""Kata - Common directory path
2+
3+
completed at: 2024-09-05 12:19:57
4+
by: Jakub Červinka
5+
6+
Returns the commom directory path for specified array of full filenames.
7+
```
8+
@param {array} pathes
9+
@return {string}
10+
```
11+
Examples:
12+
```
13+
['/web/images/image1.png', '/web/images/image2.png'] => '/web/images/'
14+
['/web/assets/style.css', '/web/scripts/app.js', 'home/setting.conf'] => ''
15+
['/web/assets/style.css', '/.bin/mocha', '/read.me'] => '/'
16+
['/web/favicon.ico', '/web-scripts/dump', '/webalizer/logs'] => '/'
17+
```
18+
(c)RSS
19+
"""
20+
21+
import os
22+
23+
def get_common_directory_path(paths):
24+
try:
25+
common_path = os.path.commonpath(paths)
26+
common_path_with_sep = common_path + os.sep
27+
28+
# Check if all paths start with the common path + separator
29+
if all(p.startswith(common_path_with_sep) for p in paths):
30+
return common_path_with_sep
31+
32+
return common_path
33+
34+
except ValueError:
35+
return ''

output/k_permutations_of_n.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""Kata - k-permutations of n
2+
3+
completed at: 2024-09-05 16:19:23
4+
by: Jakub Červinka
5+
6+
Implement a function `k_permutations_of_n` that accepts a list of elements `lst` and an integer `k`, and returns all permutations of elements from the list `lst`. Permutations should be a list containing all unique lists of `k` elements from `lst`, in any order.
7+
8+
For example, if `lst == [1,2,3]` and `k == 2` the result should be:
9+
10+
```python
11+
[[1, 2], [1, 3], [2, 1], [2, 3], [3, 1], [3, 2]]
12+
```
13+
14+
* if `k > len(lst)` the function should return an empty list, i.e.`[]`
15+
* if `k == 0`, the function should return `[[]]`, because there is exactly `1` way to arrange `0` elements (remember that `0! == 1`).
16+
17+
You can assume that the input list `lst` contains unique elements.
18+
"""
19+
20+
from itertools import permutations
21+
22+
def k_permutations_of_n(lst : list, k : int) -> list:
23+
return list(map(list, permutations(lst, k)))

output/the_coupon_code.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""Kata - The Coupon Code
2+
3+
completed at: 2024-09-05 15:32:13
4+
by: Jakub Červinka
5+
6+
# Story
7+
8+
Your online store likes to give out coupons for special occasions. Some customers try to cheat the system by entering invalid codes or using expired coupons.
9+
10+
# Task
11+
12+
Your mission:
13+
Write a function called `checkCoupon` which verifies that a coupon code is valid and not expired.
14+
15+
A coupon is no more valid on the day **AFTER** the expiration date. All dates will be passed as strings in this format: `"MONTH DATE, YEAR"`.
16+
17+
## Examples:
18+
19+
```javascript
20+
checkCoupon("123", "123", "July 9, 2015", "July 9, 2015") === true
21+
checkCoupon("123", "123", "July 9, 2015", "July 2, 2015") === false
22+
```
23+
```typescript
24+
checkCoupon("123", "123", "July 9, 2015", "July 9, 2015") === true
25+
checkCoupon("123", "123", "July 9, 2015", "July 2, 2015") === false
26+
```
27+
```csharp
28+
CheckCoupon("123", "123", "July 9, 2015", "July 9, 2015") == true
29+
CheckCoupon("123", "123", "July 9, 2015", "July 2, 2015") == false
30+
```
31+
```python
32+
checkCoupon("123", "123", "July 9, 2015", "July 9, 2015") == True
33+
checkCoupon("123", "123", "July 9, 2015", "July 2, 2015") == False
34+
```
35+
"""
36+
37+
from datetime import datetime
38+
39+
def check_coupon(entered_code, correct_code, current_date, expiration_date):
40+
# check code match
41+
code_match = entered_code is correct_code
42+
43+
# check date validity
44+
current_date = datetime.strptime(current_date, '%B %d, %Y')
45+
expiration_date = datetime.strptime(expiration_date, '%B %d, %Y')
46+
is_fresh = current_date <= expiration_date
47+
48+
return code_match and is_fresh

0 commit comments

Comments
 (0)