Skip to content

Commit e9ca1be

Browse files
committed
Add Final tasks for week 1
1 parent 50444a2 commit e9ca1be

File tree

5 files changed

+171
-0
lines changed

5 files changed

+171
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Are two words anagrams?
2+
3+
For anagrams, check here - https://en.wikipedia.org/wiki/Anagram
4+
5+
For example, `listen` and `silent` are anagrams.
6+
7+
The program should read two words from the standard input and output:
8+
9+
* `ANAGRAMS` if the words are anagrams of each other
10+
* `NOT ANAGRAMS` if the two words are not anagrams of each other
11+
12+
**Consider lowering the case of the two words since the case does not matter. `SILENT` and `listen` are also anagrams.**
13+
14+
## Examples
15+
---
16+
17+
Input:
18+
19+
```
20+
TOP_CODER COTO_PRODE
21+
```
22+
23+
Output:
24+
25+
```
26+
NOT ANAGRAMS
27+
```
28+
29+
---
30+
31+
Input:
32+
33+
```
34+
kilata cvetelina_yaneva
35+
```
36+
37+
Output:
38+
39+
```
40+
NOT ANAGRAMS
41+
```
42+
43+
Also, should not make songs together.
44+
45+
---
46+
47+
Input:
48+
49+
```
50+
BRADE BEARD
51+
```
52+
53+
Output:
54+
55+
```
56+
ANAGRAMS
57+
```
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Credit card validation
2+
3+
Implement a function, called `is_credit_card_valid(number)`, which returns True/False based on the following algorithm:
4+
5+
* Each credit card number must contain odd count of digits.
6+
* We transform the number with the following steps (based on the fact that we start from index 0)
7+
- All digits, read from right to left, at even positions (index), **remain the same.**
8+
- Every digit, read from right to left, at odd position is replaced by the result, that is obtained from doubling the given digit.
9+
* After the transformation, we find the sum of all digits in the transformed number.
10+
* The number is valid, if the sum is divisible by 10.
11+
12+
For example: `79927398713` is valid, bacause:
13+
14+
* When we double and replace all digits at odd position we get: `7 (18 = 2 * 9) 9 (4 = 2 * 2) 7 (6 = 2 * 3) 9 (16 = 2 * 8) 7 (2 = 2 * 1) 3`
15+
* The sum of all digits of the new number is 70, which is divisible by 10 => the card number is valid.
16+
17+
More examples:
18+
19+
* `79927398713` is a valid number
20+
* `79927398715` is invalid number
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Goldbach Conjecture
2+
3+
Implement a function, called `goldbach(n)` which returns a list of tuples, that is the goldbach conjecture for the given number `n`.
4+
5+
The Goldbach Conjecture states:
6+
7+
> Every even integer greater than 2 can be expressed as the sum of two primes.
8+
9+
Keep in mind that there can be more than one combination of two primes, that sums up to the given number.
10+
11+
**The result should be sorted by the first item in the tuple.**
12+
13+
For example:
14+
15+
- `4 = 2 + 2`
16+
- `6 = 3 + 3`
17+
- `8 = 3 + 5`
18+
- `10 = 3 + 7 = 5 + 5`
19+
- `100 = 3 + 97 = 11 + 89 = 17 + 83 = 29 + 71 = 41 + 59 = 47 + 53`
20+
21+
## Signature
22+
23+
```python
24+
def goldbach(n):
25+
pass
26+
```
27+
28+
## Test examples
29+
30+
```python
31+
>>> goldbach(4)
32+
[(2,2)]
33+
>>> goldbach(6)
34+
[(3,3)]
35+
>>> goldbach(8)
36+
[(3,5)]
37+
>>> goldbach(10)
38+
[(3,7), (5,5)]
39+
>>> goldbach(100)
40+
[(3, 97), (11, 89), (17, 83), (29, 71), (41, 59), (47, 53)]
41+
```
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
## Matrix Bombing
2+
3+
You are givn a `NxM` matrix of integer numbers.
4+
5+
We can drop a bomb at any place in the matrix, which has the following effect:
6+
7+
- All of the **3 to 8 neighbours** (depending on where you hit!) of the target are reduced by the value of the target.
8+
- Numbers can be reduced only to 0 - they cannot go to negative.
9+
10+
For example, if we have the following matrix:
11+
12+
```
13+
10 10 10
14+
10 9 10
15+
10 10 10
16+
```
17+
18+
and we drop bomb at `9`, this will result in the following matrix:
19+
20+
```
21+
1 1 1
22+
1 9 1
23+
1 1 1
24+
```
25+
26+
Implement a function called `matrix_bombing_plan(m)`.
27+
28+
The function should return a dictionary where keys are positions in the matrix, represented as tuples, and values are the total sum of the elements of the matrix, after the bombing at that position.
29+
30+
The positions are the standard indexes, starting from `(0, 0)`
31+
32+
For example if we have the following matrix:
33+
34+
```
35+
1 2 3
36+
4 5 6
37+
7 8 9
38+
```
39+
40+
and run the function, we will have:
41+
42+
```python
43+
{(0, 0): 42,
44+
(0, 1): 36,
45+
(0, 2): 37,
46+
(1, 0): 30,
47+
(1, 1): 15,
48+
(1, 2): 23,
49+
(2, 0): 29,
50+
(2, 1): 15,
51+
(2, 2): 26}
52+
```

week01/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Week 01 - Introduction to course & Python
22

33
[Intro slides](https://slides.com/hackbulgaria/python101-9th-opening)
4+
[Exceptions slides](https://slides.com/hackbulgaria/python101-9th-exceptions)
45

56
## Data Structures
67

0 commit comments

Comments
 (0)