Skip to content

Commit 890be52

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

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

output/exercise_in_summing.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""Kata - Exercise in Summing
2+
3+
completed at: 2024-08-21 17:33:03
4+
by: Jakub Červinka
5+
6+
Your task is to finish two functions, `minimumSum` and `maximumSum`, that take 2 parameters:
7+
8+
- `values`: an array of integers with an arbitrary length; may be positive and negative
9+
- `n`: how many integers should be summed; always 0 or bigger
10+
11+
### Example:
12+
13+
```javascript
14+
var values = [5, 4, 3, 2, 1];
15+
minimumSum(values, 2); // should return 1+2 = 3
16+
maximumSum(values, 3); // should return 3+4+5 = 12
17+
```
18+
19+
```coffeescript
20+
values = [5, 4, 3, 2, 1]
21+
minimumSum values, 2 # should return 1+2 = 3
22+
maximumSum values, 3 # should return 3+4+5 = 12
23+
```
24+
25+
```python
26+
values = [5, 4, 3, 2, 1];
27+
minimum_sum(values, 2) #should return 1 + 2 = 3
28+
maximum_sum(values, 3) #should return 3 + 4 + 5 = 12
29+
```
30+
31+
```haskell
32+
minimumSum [1..5] 2 `shouldBe` 1 + 2
33+
minimumSum [1..5] 3 `shouldBe` 1 + 2 + 3
34+
maximumSum [1..5] 2 `shouldBe` 4 + 5
35+
maximumSum [1..5] 3 `shouldBe` 3 + 4 + 5
36+
```
37+
38+
All values given to the functions will be integers. Also take care of the following special cases:
39+
40+
- if `values` is empty, both functions should return 0
41+
- if `n` is 0, both functions should also return 0
42+
- if `n` is larger than `values`'s length, use the length instead.
43+
"""
44+
45+
def minimum_sum(values, n):
46+
return sum(sorted(values)[:n])
47+
48+
def maximum_sum(values, n):
49+
if n == 0: return 0
50+
return sum(sorted(values)[-n:])

output/telephone_words.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""Kata - telephone words
2+
3+
completed at: 2024-08-21 18:44:14
4+
by: Jakub Červinka
5+
6+
Businesses use keypad letters in creative ways to spell out a phone number and make it more memorable.
7+
Example:
8+
http://en.wikipedia.org/wiki/File:Telephone-keypad2.svg
9+
10+
Create a mapping for your dialer as given in the above link.
11+
Constraints:
12+
1. letters are all uppercase
13+
2. digits 0, 1 are mapped to 0, 1 respectively
14+
15+
Write a function that takes four digits of a phone number, and returns a list of all of the words that can be written with that number. (You should return all permutations, not only English words.)
16+
17+
"""
18+
19+
from itertools import product
20+
21+
def telephone_words(digit_string):
22+
mapping = {
23+
'0': '0',
24+
'1': '1',
25+
'2': 'ABC',
26+
'3': 'DEF',
27+
'4': 'GHI',
28+
'5': 'JKL',
29+
'6': 'MNO',
30+
'7': 'PQRS',
31+
'8': 'TUV',
32+
'9': 'WXYZ'
33+
}
34+
options = (
35+
mapping[letter]
36+
for letter in digit_string
37+
)
38+
return list(''.join(tup) for tup in product(*options))
39+

0 commit comments

Comments
 (0)