From d55cb679bb1df09d8283cebb9d567c5754998da2 Mon Sep 17 00:00:00 2001 From: Vladislav Mihov <37806520+skilldeliver@users.noreply.github.com> Date: Thu, 28 Nov 2019 23:02:02 +0200 Subject: [PATCH 01/11] Initial directory structure for the first week. --- week01/01. Problems/README.md | 0 week01/01. Problems/solutions.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 week01/01. Problems/README.md create mode 100644 week01/01. Problems/solutions.py diff --git a/week01/01. Problems/README.md b/week01/01. Problems/README.md new file mode 100644 index 0000000..e69de29 diff --git a/week01/01. Problems/solutions.py b/week01/01. Problems/solutions.py new file mode 100644 index 0000000..e69de29 From d8647107d19b2247eb805142664ca4f812c2063f Mon Sep 17 00:00:00 2001 From: Vladislav Mihov <37806520+skilldeliver@users.noreply.github.com> Date: Thu, 28 Nov 2019 23:24:49 +0200 Subject: [PATCH 02/11] Add definiton of a modular arithmetic problem. --- week01/01. Problems/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/week01/01. Problems/README.md b/week01/01. Problems/README.md index e69de29..ad35829 100644 --- a/week01/01. Problems/README.md +++ b/week01/01. Problems/README.md @@ -0,0 +1 @@ +#Python problems ### Divisible by given number Find all numbers in the list `n` which are divisible by a given integer `d`. ##### Signature ```python def divisible_by_d(n: list, d: int) -> list: pass ``` ##### Test examples ```python >>> divisible_by_d([1,2,3,4,5,6], 3) [3, 6] >>> divisible_by_d([0,1,2,3,4,5,6], 4) [0, 4] >>> divisible_by_d([0], 4) [0] >>> divisible_by_d([1,3,5], 2) [] ``` \ No newline at end of file From 1e0d9f9cc7f041101bba85bc9d069486bb2625e2 Mon Sep 17 00:00:00 2001 From: Vladislav Mihov <37806520+skilldeliver@users.noreply.github.com> Date: Thu, 28 Nov 2019 23:33:47 +0200 Subject: [PATCH 03/11] Solution for the modular arithmetic problem. --- week01/01. Problems/README.md | 2 +- week01/01. Problems/solutions.py | 11 +++++++++++ week01/README.md | 0 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 week01/README.md diff --git a/week01/01. Problems/README.md b/week01/01. Problems/README.md index ad35829..4e7cb4f 100644 --- a/week01/01. Problems/README.md +++ b/week01/01. Problems/README.md @@ -1 +1 @@ -#Python problems ### Divisible by given number Find all numbers in the list `n` which are divisible by a given integer `d`. ##### Signature ```python def divisible_by_d(n: list, d: int) -> list: pass ``` ##### Test examples ```python >>> divisible_by_d([1,2,3,4,5,6], 3) [3, 6] >>> divisible_by_d([0,1,2,3,4,5,6], 4) [0, 4] >>> divisible_by_d([0], 4) [0] >>> divisible_by_d([1,3,5], 2) [] ``` \ No newline at end of file +#Python problems ### Divisible by given number Find all numbers in the list `n` which are divisible by a given integer `d`. ##### Signature ```python def divisible_by_d(n: list, d: int) -> list: pass ``` ##### Test examples ```python >>> divisible_by_d([1,2,3,4,5,6], 3) [3, 6] >>> divisible_by_d([0,1,2,3,4,5,6], 4) [0, 4] >>> divisible_by_d([0], 4) [0] >>> divisible_by_d([1,3,5], 2) [] ``` \ No newline at end of file diff --git a/week01/01. Problems/solutions.py b/week01/01. Problems/solutions.py index e69de29..06f39ad 100644 --- a/week01/01. Problems/solutions.py +++ b/week01/01. Problems/solutions.py @@ -0,0 +1,11 @@ +""" +Copyright (c) 2019 Hack Bulgaria + +The project is released under MIT License +https://github.com/HackBulgaria/Programming-101-Python-2020-Spring +""" + + +def divisible_by_d(n: list, d: int) -> list: + '''Returns a list of all numbers from n divislbe by d.''' + return [i for i in n if i % d == 0] diff --git a/week01/README.md b/week01/README.md new file mode 100644 index 0000000..e69de29 From 8ffe14a28920a42db0c39b9a96629794e3acaa54 Mon Sep 17 00:00:00 2001 From: Vladislav Mihov <37806520+skilldeliver@users.noreply.github.com> Date: Thu, 28 Nov 2019 23:45:46 +0200 Subject: [PATCH 04/11] Fix heading. --- week01/01. Problems/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week01/01. Problems/README.md b/week01/01. Problems/README.md index 4e7cb4f..4f6a025 100644 --- a/week01/01. Problems/README.md +++ b/week01/01. Problems/README.md @@ -1 +1 @@ -#Python problems ### Divisible by given number Find all numbers in the list `n` which are divisible by a given integer `d`. ##### Signature ```python def divisible_by_d(n: list, d: int) -> list: pass ``` ##### Test examples ```python >>> divisible_by_d([1,2,3,4,5,6], 3) [3, 6] >>> divisible_by_d([0,1,2,3,4,5,6], 4) [0, 4] >>> divisible_by_d([0], 4) [0] >>> divisible_by_d([1,3,5], 2) [] ``` \ No newline at end of file + # Python problems ### Divisible by a given number Find all numbers in the list `n` which are divisible by a given integer `d`. ##### Signature ```python def divisible_by_d(n: list, d: int) -> list: pass ``` ##### Test examples ```python >>> divisible_by_d([1,2,3,4,5,6], 3) [3, 6] >>> divisible_by_d([0,1,2,3,4,5,6], 4) [0, 4] >>> divisible_by_d([0], 4) [0] >>> divisible_by_d([1,3,5], 2) [] ``` \ No newline at end of file From 1c36e7522cf6dea5433e439a31b502bd3d5e43c6 Mon Sep 17 00:00:00 2001 From: Vladislav Mihov <37806520+skilldeliver@users.noreply.github.com> Date: Thu, 28 Nov 2019 23:50:54 +0200 Subject: [PATCH 05/11] Use problems definiton layout from the previous year. --- week01/01. Problems/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week01/01. Problems/README.md b/week01/01. Problems/README.md index 4f6a025..f23da1c 100644 --- a/week01/01. Problems/README.md +++ b/week01/01. Problems/README.md @@ -1 +1 @@ - # Python problems ### Divisible by a given number Find all numbers in the list `n` which are divisible by a given integer `d`. ##### Signature ```python def divisible_by_d(n: list, d: int) -> list: pass ``` ##### Test examples ```python >>> divisible_by_d([1,2,3,4,5,6], 3) [3, 6] >>> divisible_by_d([0,1,2,3,4,5,6], 4) [0, 4] >>> divisible_by_d([0], 4) [0] >>> divisible_by_d([1,3,5], 2) [] ``` \ No newline at end of file +Python Problems ============== ## Divisible by a given number Find all numbers in the list `n` which are divisible by a given integer `d`. ### Signature ```python def divisible_by_d(n: list, d: int) -> list: pass ``` ### Test examples ```python >>> divisible_by_d([1,2,3,4,5,6], 3) [3, 6] >>> divisible_by_d([0,1,2,3,4,5,6], 4) [0, 4] >>> divisible_by_d([0], 4) [0] >>> divisible_by_d([1,3,5], 2) [] ``` \ No newline at end of file From ca089cf5d5c499ec37da8f8d02bf77440cac8f1e Mon Sep 17 00:00:00 2001 From: Vladislav Mihov <37806520+skilldeliver@users.noreply.github.com> Date: Fri, 29 Nov 2019 01:44:42 +0200 Subject: [PATCH 06/11] Chess problem signature and graphical example. --- week01/01. Problems/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week01/01. Problems/README.md b/week01/01. Problems/README.md index f23da1c..1ec9134 100644 --- a/week01/01. Problems/README.md +++ b/week01/01. Problems/README.md @@ -1 +1 @@ -Python Problems ============== ## Divisible by a given number Find all numbers in the list `n` which are divisible by a given integer `d`. ### Signature ```python def divisible_by_d(n: list, d: int) -> list: pass ``` ### Test examples ```python >>> divisible_by_d([1,2,3,4,5,6], 3) [3, 6] >>> divisible_by_d([0,1,2,3,4,5,6], 4) [0, 4] >>> divisible_by_d([0], 4) [0] >>> divisible_by_d([1,3,5], 2) [] ``` \ No newline at end of file +Python Problems ============== ## Divisible by a given number Find all numbers in the list `n` which are divisible by a given integer `d`. ### Signature ```python def divisible_by_d(n: list, d: int) -> list: pass ``` ### Test examples ```python >>> divisible_by_d([1,2,3,4,5,6], 3) [3, 6] >>> divisible_by_d([0,1,2,3,4,5,6], 4) [0, 4] >>> divisible_by_d([0], 4) [0] >>> divisible_by_d([1,3,5], 2) [] ``` ## Knight valid positions count Given a tuple with two indexes than denotes the knight position on a matrix board, return the count of all valid positions which the knight can made. ### Signature ```python def knight_positions(pos: tuple) -> int: # pos[0] denotes the knights row # pos[1] denotes the knights column pass ``` Consider these graphical examples `There are maximum eight legal positons` | M | 0| 1 | 2| 3| 4| 5| 6| 7| | - |::| :| :| :| :| :| :| :| | **0**| | | | | | | | | | **1** | | | | | | | | | | **2** | | | *| | *| | | | | **3** | | *| | | | *| | | | **4** | | | |K | | | | | | **5** | | *| | | | *| | | | **6** | | | *| | *| | | | | **7** | | | | | | | | | `Example with only two legal moves` | M | 0| 1 | 2| 3| 4| 5| 6| 7| | - |::| :| :| :| :| :| :| :| | **0**| | | | | | | | | | **1** | | | | | | | | | | **2** | | | | | | | | | | **3** | | | | | | | | | | **4** | | | | | | | | | | **5** | | | | | | | *| | | **6** | | | | | | *| | | | **7** | | | | | | | | K| \ No newline at end of file From 2d0f145b938b831599b189ffef858a65dea9b690 Mon Sep 17 00:00:00 2001 From: Vladislav Mihov <37806520+skilldeliver@users.noreply.github.com> Date: Fri, 29 Nov 2019 18:03:52 +0200 Subject: [PATCH 07/11] Chess Knight problem, examples and solution. --- week01/01. Problems/README.md | 2 +- week01/01. Problems/solutions.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/week01/01. Problems/README.md b/week01/01. Problems/README.md index 1ec9134..0204649 100644 --- a/week01/01. Problems/README.md +++ b/week01/01. Problems/README.md @@ -1 +1 @@ -Python Problems ============== ## Divisible by a given number Find all numbers in the list `n` which are divisible by a given integer `d`. ### Signature ```python def divisible_by_d(n: list, d: int) -> list: pass ``` ### Test examples ```python >>> divisible_by_d([1,2,3,4,5,6], 3) [3, 6] >>> divisible_by_d([0,1,2,3,4,5,6], 4) [0, 4] >>> divisible_by_d([0], 4) [0] >>> divisible_by_d([1,3,5], 2) [] ``` ## Knight valid positions count Given a tuple with two indexes than denotes the knight position on a matrix board, return the count of all valid positions which the knight can made. ### Signature ```python def knight_positions(pos: tuple) -> int: # pos[0] denotes the knights row # pos[1] denotes the knights column pass ``` Consider these graphical examples `There are maximum eight legal positons` | M | 0| 1 | 2| 3| 4| 5| 6| 7| | - |::| :| :| :| :| :| :| :| | **0**| | | | | | | | | | **1** | | | | | | | | | | **2** | | | *| | *| | | | | **3** | | *| | | | *| | | | **4** | | | |K | | | | | | **5** | | *| | | | *| | | | **6** | | | *| | *| | | | | **7** | | | | | | | | | `Example with only two legal moves` | M | 0| 1 | 2| 3| 4| 5| 6| 7| | - |::| :| :| :| :| :| :| :| | **0**| | | | | | | | | | **1** | | | | | | | | | | **2** | | | | | | | | | | **3** | | | | | | | | | | **4** | | | | | | | | | | **5** | | | | | | | *| | | **6** | | | | | | *| | | | **7** | | | | | | | | K| \ No newline at end of file +Python Problems ============== ## Divisible by a given number Find all numbers in the list `n` which are divisible by a given integer `d`. ### Signature ```python def divisible_by_d(n: list, d: int) -> list: pass ``` ### Test examples ```python >>> divisible_by_d([1,2,3,4,5,6], 3) [3, 6] >>> divisible_by_d([0,1,2,3,4,5,6], 4) [0, 4] >>> divisible_by_d([0], 4) [0] >>> divisible_by_d([1,3,5], 2) [] ``` ## Knight valid moves count Given a tuple with two indexes that denotes the knight position on a matrix board, return the count of all valid moves which the knight can made. ### Signature ```python def knight_moves(pos: tuple) -> int: # pos[0] denotes the knights row # pos[1] denotes the knights column pass ``` ### Test examples ```python >>> knight_moves((2, 6)) 6 >>> knight_moves((0, 7)) 2 >>> knight_moves((5, 0)) 4 >>> knight_moves((4, 3)) 8 >>> knight_moves((6, 7)) 3 ``` Consider these graphical examples `Eight legal moves where pos = (4, 3)` | M | 0| 1 | 2| 3| 4| 5| 6| 7| | - |::| :| :| :| :| :| :| :| | **0**| | | | | | | | | | **1** | | | | | | | | | | **2** | | | *| | *| | | | | **3** | | *| | | | *| | | | **4** | | | |K | | | | | | **5** | | *| | | | *| | | | **6** | | | *| | *| | | | | **7** | | | | | | | | | `Two legal moves where pos = (7, 7)` | M | 0| 1 | 2| 3| 4| 5| 6| 7| | - |::| :| :| :| :| :| :| :| | **0**| | | | | | | | | | **1** | | | | | | | | | | **2** | | | | | | | | | | **3** | | | | | | | | | | **4** | | | | | | | | | | **5** | | | | | | | *| | | **6** | | | | | | *| | | | **7** | | | | | | | | K| \ No newline at end of file diff --git a/week01/01. Problems/solutions.py b/week01/01. Problems/solutions.py index 06f39ad..b71d089 100644 --- a/week01/01. Problems/solutions.py +++ b/week01/01. Problems/solutions.py @@ -9,3 +9,35 @@ def divisible_by_d(n: list, d: int) -> list: '''Returns a list of all numbers from n divislbe by d.''' return [i for i in n if i % d == 0] + + +def knight_moves(pos: tuple) -> int: + '''Returns the count of all legal moves which the knight can make.''' + offsets = ((-2, -1), (-2, 1), (-1, -2), (-1, 2), + (1, -2), (1, 2), (2, -1), (2, 1)) + + return [ 0 <= (pos[0] + o[0]) < 8 and + 0 <= (pos[1] + o[1]) < 8 + for o in offsets].count(True) + + + # valids = ((pos[0] - 2, pos[1] - 1), + # (pos[0] - 2, pos[1] + 1), + # (pos[0] + 2, pos[1] - 1), + # (pos[0] + 2, pos[1] + 1), + # (pos[1] - 2, pos[0] - 1), + # (pos[1] - 2, pos[0] + 1), + # (pos[1] + 2, pos[0] - 1), + # (pos[1] + 2, pos[0] + 1)) + + # return ( + # 0 <= pos[0] - 2 <= 7 and 0 <= pos[1] - 1 <= 7, + # 0 <= pos[0] - 2 <= 7 and 0 <= pos[1] + 1 <= 7, + # 0 <= pos[0] + 2 <= 7 and 0 <= pos[1] - 1 <= 7, + # 0 <= pos[0] + 2 <= 7 and 0 <= pos[1] + 1 <= 7, + + # 0 <= pos[1] - 2 <= 7 and 0 <= pos[0] - 1 <= 7, + # 0 <= pos[1] - 2 <= 7 and 0 <= pos[0] + 1 <= 7, + # 0 <= pos[1] + 2 <= 7 and 0 <= pos[0] - 1 <= 7, + # 0 <= pos[1] + 2 <= 7 and 0 <= pos[0] + 1 <= 7 + # ).count(True) From 963ec802e07aca6de8b499111b9f18c6a8fb5283 Mon Sep 17 00:00:00 2001 From: Vladislav Mihov <37806520+skilldeliver@users.noreply.github.com> Date: Fri, 29 Nov 2019 18:04:37 +0200 Subject: [PATCH 08/11] Remove unused code. --- week01/01. Problems/solutions.py | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/week01/01. Problems/solutions.py b/week01/01. Problems/solutions.py index b71d089..ab89840 100644 --- a/week01/01. Problems/solutions.py +++ b/week01/01. Problems/solutions.py @@ -19,25 +19,3 @@ def knight_moves(pos: tuple) -> int: return [ 0 <= (pos[0] + o[0]) < 8 and 0 <= (pos[1] + o[1]) < 8 for o in offsets].count(True) - - - # valids = ((pos[0] - 2, pos[1] - 1), - # (pos[0] - 2, pos[1] + 1), - # (pos[0] + 2, pos[1] - 1), - # (pos[0] + 2, pos[1] + 1), - # (pos[1] - 2, pos[0] - 1), - # (pos[1] - 2, pos[0] + 1), - # (pos[1] + 2, pos[0] - 1), - # (pos[1] + 2, pos[0] + 1)) - - # return ( - # 0 <= pos[0] - 2 <= 7 and 0 <= pos[1] - 1 <= 7, - # 0 <= pos[0] - 2 <= 7 and 0 <= pos[1] + 1 <= 7, - # 0 <= pos[0] + 2 <= 7 and 0 <= pos[1] - 1 <= 7, - # 0 <= pos[0] + 2 <= 7 and 0 <= pos[1] + 1 <= 7, - - # 0 <= pos[1] - 2 <= 7 and 0 <= pos[0] - 1 <= 7, - # 0 <= pos[1] - 2 <= 7 and 0 <= pos[0] + 1 <= 7, - # 0 <= pos[1] + 2 <= 7 and 0 <= pos[0] - 1 <= 7, - # 0 <= pos[1] + 2 <= 7 and 0 <= pos[0] + 1 <= 7 - # ).count(True) From 320cce6b8f7747b289095803727ebdf4666145d9 Mon Sep 17 00:00:00 2001 From: Vladislav Mihov <37806520+skilldeliver@users.noreply.github.com> Date: Fri, 29 Nov 2019 18:29:18 +0200 Subject: [PATCH 09/11] Fix chess matrix tables. --- week01/01. Problems/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week01/01. Problems/README.md b/week01/01. Problems/README.md index 0204649..83c0762 100644 --- a/week01/01. Problems/README.md +++ b/week01/01. Problems/README.md @@ -1 +1 @@ -Python Problems ============== ## Divisible by a given number Find all numbers in the list `n` which are divisible by a given integer `d`. ### Signature ```python def divisible_by_d(n: list, d: int) -> list: pass ``` ### Test examples ```python >>> divisible_by_d([1,2,3,4,5,6], 3) [3, 6] >>> divisible_by_d([0,1,2,3,4,5,6], 4) [0, 4] >>> divisible_by_d([0], 4) [0] >>> divisible_by_d([1,3,5], 2) [] ``` ## Knight valid moves count Given a tuple with two indexes that denotes the knight position on a matrix board, return the count of all valid moves which the knight can made. ### Signature ```python def knight_moves(pos: tuple) -> int: # pos[0] denotes the knights row # pos[1] denotes the knights column pass ``` ### Test examples ```python >>> knight_moves((2, 6)) 6 >>> knight_moves((0, 7)) 2 >>> knight_moves((5, 0)) 4 >>> knight_moves((4, 3)) 8 >>> knight_moves((6, 7)) 3 ``` Consider these graphical examples `Eight legal moves where pos = (4, 3)` | M | 0| 1 | 2| 3| 4| 5| 6| 7| | - |::| :| :| :| :| :| :| :| | **0**| | | | | | | | | | **1** | | | | | | | | | | **2** | | | *| | *| | | | | **3** | | *| | | | *| | | | **4** | | | |K | | | | | | **5** | | *| | | | *| | | | **6** | | | *| | *| | | | | **7** | | | | | | | | | `Two legal moves where pos = (7, 7)` | M | 0| 1 | 2| 3| 4| 5| 6| 7| | - |::| :| :| :| :| :| :| :| | **0**| | | | | | | | | | **1** | | | | | | | | | | **2** | | | | | | | | | | **3** | | | | | | | | | | **4** | | | | | | | | | | **5** | | | | | | | *| | | **6** | | | | | | *| | | | **7** | | | | | | | | K| \ No newline at end of file +Python Problems ============== ## Divisible by a given number Find all numbers in the list `n` which are divisible by a given integer `d`. ### Signature ```python def divisible_by_d(n: list, d: int) -> list: pass ``` ### Test examples ```python >>> divisible_by_d([1,2,3,4,5,6], 3) [3, 6] >>> divisible_by_d([0,1,2,3,4,5,6], 4) [0, 4] >>> divisible_by_d([0], 4) [0] >>> divisible_by_d([1,3,5], 2) [] ``` ## Knight valid moves count Given a tuple with two indexes that denotes the knight position on a matrix board, return the count of all valid moves which the knight can made. ### Signature ```python def knight_moves(pos: tuple) -> int: # pos[0] denotes the knights row # pos[1] denotes the knights column pass ``` ### Test examples ```python >>> knight_moves((2, 6)) 6 >>> knight_moves((0, 7)) 2 >>> knight_moves((5, 0)) 4 >>> knight_moves((4, 3)) 8 >>> knight_moves((6, 7)) 3 ``` Consider these graphical examples `Eight legal moves where pos = (4, 3)` |M|0|1|2|3|4|5|6|7| |-|-|-|-|-|-|-|-|-| |**0**| | | | | | | | | |**1**| | | | | | | | | |**2**| | | \*| | \*| | | | |**3**| | \*| | | | \*| | | |**4**| | | | K| | | | | |**5**| | \*| | | | \*| | | |**6**| | | \*| | \*| | | | |**7**| | | | | | | | | `Two legal moves where pos = (7, 7)` |M|0|1|2|3|4|5|6|7| |-|-|-|-|-|-|-|-|-| |**0**| | | | | | | | | |**1**| | | | | | | | | |**2**| | | | | | | | | |**3**| | | | | | | | | |**4**| | | | | | | | | |**5**| | | | | | | | | |**6**| | | | | | | \*| | |**7**| | | | | | \*| | K| \ No newline at end of file From 52547d50bef756bae67db17e16f936d5a1b8eaad Mon Sep 17 00:00:00 2001 From: Vladislav Mihov <37806520+skilldeliver@users.noreply.github.com> Date: Fri, 29 Nov 2019 18:32:39 +0200 Subject: [PATCH 10/11] Inaccuracy in one of the graphical examples for chess move. --- week01/01. Problems/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week01/01. Problems/README.md b/week01/01. Problems/README.md index 83c0762..2c02ee3 100644 --- a/week01/01. Problems/README.md +++ b/week01/01. Problems/README.md @@ -1 +1 @@ -Python Problems ============== ## Divisible by a given number Find all numbers in the list `n` which are divisible by a given integer `d`. ### Signature ```python def divisible_by_d(n: list, d: int) -> list: pass ``` ### Test examples ```python >>> divisible_by_d([1,2,3,4,5,6], 3) [3, 6] >>> divisible_by_d([0,1,2,3,4,5,6], 4) [0, 4] >>> divisible_by_d([0], 4) [0] >>> divisible_by_d([1,3,5], 2) [] ``` ## Knight valid moves count Given a tuple with two indexes that denotes the knight position on a matrix board, return the count of all valid moves which the knight can made. ### Signature ```python def knight_moves(pos: tuple) -> int: # pos[0] denotes the knights row # pos[1] denotes the knights column pass ``` ### Test examples ```python >>> knight_moves((2, 6)) 6 >>> knight_moves((0, 7)) 2 >>> knight_moves((5, 0)) 4 >>> knight_moves((4, 3)) 8 >>> knight_moves((6, 7)) 3 ``` Consider these graphical examples `Eight legal moves where pos = (4, 3)` |M|0|1|2|3|4|5|6|7| |-|-|-|-|-|-|-|-|-| |**0**| | | | | | | | | |**1**| | | | | | | | | |**2**| | | \*| | \*| | | | |**3**| | \*| | | | \*| | | |**4**| | | | K| | | | | |**5**| | \*| | | | \*| | | |**6**| | | \*| | \*| | | | |**7**| | | | | | | | | `Two legal moves where pos = (7, 7)` |M|0|1|2|3|4|5|6|7| |-|-|-|-|-|-|-|-|-| |**0**| | | | | | | | | |**1**| | | | | | | | | |**2**| | | | | | | | | |**3**| | | | | | | | | |**4**| | | | | | | | | |**5**| | | | | | | | | |**6**| | | | | | | \*| | |**7**| | | | | | \*| | K| \ No newline at end of file +Python Problems ============== ## Divisible by a given number Find all numbers in the list `n` which are divisible by a given integer `d`. ### Signature ```python def divisible_by_d(n: list, d: int) -> list: pass ``` ### Test examples ```python >>> divisible_by_d([1,2,3,4,5,6], 3) [3, 6] >>> divisible_by_d([0,1,2,3,4,5,6], 4) [0, 4] >>> divisible_by_d([0], 4) [0] >>> divisible_by_d([1,3,5], 2) [] ``` ## Knight valid moves count Given a tuple with two indexes that denotes the knight position on a matrix board, return the count of all valid moves which the knight can made. ### Signature ```python def knight_moves(pos: tuple) -> int: # pos[0] denotes the knights row # pos[1] denotes the knights column pass ``` ### Test examples ```python >>> knight_moves((2, 6)) 6 >>> knight_moves((0, 7)) 2 >>> knight_moves((5, 0)) 4 >>> knight_moves((4, 3)) 8 >>> knight_moves((6, 7)) 3 ``` Consider these graphical examples `Eight legal moves where pos = (4, 3)` |M|0|1|2|3|4|5|6|7| |-|-|-|-|-|-|-|-|-| |**0**| | | | | | | | | |**1**| | | | | | | | | |**2**| | | \*| | \*| | | | |**3**| | \*| | | | \*| | | |**4**| | | | N| | | | | |**5**| | \*| | | | \*| | | |**6**| | | \*| | \*| | | | |**7**| | | | | | | | | `Two legal moves where pos = (7, 7)` |M|0|1|2|3|4|5|6|7| |-|-|-|-|-|-|-|-|-| |**0**| | | | | | | | | |**1**| | | | | | | | | |**2**| | | | | | | | | |**3**| | | | | | | | | |**4**| | | | | | | | | |**5**| | | | | | | |\* | |**6**| | | | | | | | | |**7**| | | | | | \*| | N| \ No newline at end of file From f64d0b9d7534972bae2f63c56be8769d963e4051 Mon Sep 17 00:00:00 2001 From: Vladislav Mihov <37806520+skilldeliver@users.noreply.github.com> Date: Fri, 29 Nov 2019 18:55:30 +0200 Subject: [PATCH 11/11] Typo and inaccuracy. --- week01/01. Problems/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week01/01. Problems/README.md b/week01/01. Problems/README.md index 2c02ee3..96637f2 100644 --- a/week01/01. Problems/README.md +++ b/week01/01. Problems/README.md @@ -1 +1 @@ -Python Problems ============== ## Divisible by a given number Find all numbers in the list `n` which are divisible by a given integer `d`. ### Signature ```python def divisible_by_d(n: list, d: int) -> list: pass ``` ### Test examples ```python >>> divisible_by_d([1,2,3,4,5,6], 3) [3, 6] >>> divisible_by_d([0,1,2,3,4,5,6], 4) [0, 4] >>> divisible_by_d([0], 4) [0] >>> divisible_by_d([1,3,5], 2) [] ``` ## Knight valid moves count Given a tuple with two indexes that denotes the knight position on a matrix board, return the count of all valid moves which the knight can made. ### Signature ```python def knight_moves(pos: tuple) -> int: # pos[0] denotes the knights row # pos[1] denotes the knights column pass ``` ### Test examples ```python >>> knight_moves((2, 6)) 6 >>> knight_moves((0, 7)) 2 >>> knight_moves((5, 0)) 4 >>> knight_moves((4, 3)) 8 >>> knight_moves((6, 7)) 3 ``` Consider these graphical examples `Eight legal moves where pos = (4, 3)` |M|0|1|2|3|4|5|6|7| |-|-|-|-|-|-|-|-|-| |**0**| | | | | | | | | |**1**| | | | | | | | | |**2**| | | \*| | \*| | | | |**3**| | \*| | | | \*| | | |**4**| | | | N| | | | | |**5**| | \*| | | | \*| | | |**6**| | | \*| | \*| | | | |**7**| | | | | | | | | `Two legal moves where pos = (7, 7)` |M|0|1|2|3|4|5|6|7| |-|-|-|-|-|-|-|-|-| |**0**| | | | | | | | | |**1**| | | | | | | | | |**2**| | | | | | | | | |**3**| | | | | | | | | |**4**| | | | | | | | | |**5**| | | | | | | |\* | |**6**| | | | | | | | | |**7**| | | | | | \*| | N| \ No newline at end of file +Python Problems ============== ## Divisible by a given number Find all numbers in the list `n` which are divisible by a given integer `d`. ### Signature ```python def divisible_by_d(n: list, d: int) -> list: pass ``` ### Test examples ```python >>> divisible_by_d([1,2,3,4,5,6], 3) [3, 6] >>> divisible_by_d([0,1,2,3,4,5,6], 4) [0, 4] >>> divisible_by_d([0], 4) [0] >>> divisible_by_d([1,3,5], 2) [] ``` ## Knight valid moves count Given a tuple with two indexes that denote the knight position on a matrix board, return the count of all valid moves which the knight can made. ### Signature ```python def knight_moves(pos: tuple) -> int: # pos[0] denotes the knights row # pos[1] denotes the knights column pass ``` ### Test examples ```python >>> knight_moves((2, 6)) 6 >>> knight_moves((0, 7)) 2 >>> knight_moves((5, 0)) 4 >>> knight_moves((4, 3)) 8 >>> knight_moves((6, 7)) 3 ``` Consider these graphical examples `Eight legal moves where pos = (4, 3)` |M|0|1|2|3|4|5|6|7| |-|-|-|-|-|-|-|-|-| |**0**| | | | | | | | | |**1**| | | | | | | | | |**2**| | | \*| | \*| | | | |**3**| | \*| | | | \*| | | |**4**| | | | N| | | | | |**5**| | \*| | | | \*| | | |**6**| | | \*| | \*| | | | |**7**| | | | | | | | | `Two legal moves where pos = (7, 7)` |M|0|1|2|3|4|5|6|7| |-|-|-|-|-|-|-|-|-| |**0**| | | | | | | | | |**1**| | | | | | | | | |**2**| | | | | | | | | |**3**| | | | | | | | | |**4**| | | | | | | | | |**5**| | | | | | | \*| | |**6**| | | | | | | | | |**7**| | | | | | \*| | N| \ No newline at end of file