Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.

Commit c4326cd

Browse files
authored
Update 2023.08.1 (#103)
1 parent efeafc8 commit c4326cd

24 files changed

+582
-513
lines changed

.github/workflows/tests.yml renamed to .github/workflows/run_tests.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: tests
1+
name: Run tests, checkers and linters with Tox
22

33
on:
44
push:
@@ -23,9 +23,9 @@ jobs:
2323
uses: actions/setup-python@v2
2424
with:
2525
python-version: ${{ matrix.python-version }}
26-
- name: install dependencies
26+
- name: Install dependencies
2727
run: |
2828
python -m pip install --upgrade pip
2929
pip install tox tox-gh-actions
30-
- name: Tests
30+
- name: Run tox
3131
run: tox

poetry.lock

+303-302
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "problem-sets"
7-
version = "2023.05.1"
7+
version = "2023.08.1"
88
description = "Challenges and solutions for the Python training course"
99
license = "MIT"
1010
authors = [
@@ -43,9 +43,10 @@ packages = [
4343
{ include = "conv_store", from = "src" },
4444
{ include = "datasets", from = "src" },
4545
{ include = "dynamic", from = "src" },
46+
{ include = "geom", from = "src" },
47+
{ include = "primes", from = "src" },
4648
{ include = "sequences", from = "src" },
4749
{ include = "sorting", from = "src" },
48-
{ include = "primes", from = "src" },
4950
{ include = "wtk", from = "src" },
5051
]
5152

src/atm/func.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def withdraw(target: int,
2929
number of coins/bills. If no exact solution is possible, the algorithm
3030
returns the largest possible amount that is less than the target amount.
3131
32-
Usage examples:
32+
Usage:
3333
3434
>>> assert withdraw(0) == []
3535
>>> assert withdraw(135) == [(1, 10), (1, 25), (1, 100)]
@@ -54,9 +54,9 @@ def withdraw(target: int,
5454
target -= multipliers[idx] * denominations[idx]
5555

5656
# filter zero multipliers
57-
filtered = filter(lambda pair: pair[0] > 0, zip(multipliers, denominations))
57+
filtered = filter(lambda val: val[0] > 0, zip(multipliers, denominations))
5858

59-
return sorted(filtered, key=lambda pair: pair[1])
59+
return sorted(filtered, key=lambda val: val[1])
6060

6161

6262
def withdraw_rev(target: int,
@@ -78,35 +78,35 @@ def withdraw_rev(target: int,
7878
to use the smallest denominations as many times as it possible (it's
7979
limited with ``limit`` argument).
8080
81-
Usage examples:
81+
Usage:
8282
8383
>>> assert withdraw_rev(0) == []
8484
>>> assert withdraw_rev(14) == [(10, 1), (2, 2)]
8585
>>> assert withdraw_rev(17) == [(9, 1), (4, 2)]
8686
8787
"""
8888

89-
raise NotImplementedError
89+
raise NotImplementedError # TODO:
9090

9191

92-
def get_total(pairs: Iterable[Tuple[int, int]]) -> int:
92+
def get_total(values: Iterable[Tuple[int, int]]) -> int:
9393
"""Calculate the total sum
9494
95-
:param pairs: pairs of denominations and their multipliers
96-
:type pairs: list
95+
:param values: pairs of denominations and their multipliers
96+
:type values: list
9797
9898
:return: the total sum
9999
:rtype: int
100100
101101
``pairs`` is a list of tuples. Each ``pair`` tuple contains multiplier
102102
at the first position and denomination at the second one.
103103
104-
Usage examples:
104+
Usage:
105105
106106
>>> assert get_total([(1, 50), (1, 500), (2, 2000), (2, 10000)]) == 24500
107107
>>> assert get_total([(1, 500), (1, 2000), (1, 5000), (1, 10000)]) == 17545
108108
>>> assert get_total([(1, 2000)]) == 2000
109109
110110
"""
111111

112-
return sum(map(lambda pair: pair[0] * pair[1], pairs))
112+
return sum(map(lambda val: val[0] * val[1], values))

src/bisearch/prefix.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ def bisect_right(origin: List[str], search: str = "") -> int:
2020
"""
2121
Return the most right one index matching the search value
2222
23-
Current function implements common ``bisect_right`` algorithms.
24-
The search value represents prefix the string should starts with,
25-
that's why current string is trimmed before comparison operation.
26-
2723
:param origin: a list of strings
2824
:type origin: list
2925
:param search: a prefix to search
@@ -34,6 +30,10 @@ def bisect_right(origin: List[str], search: str = "") -> int:
3430
3531
:raise NotFound: if the searched value isn't in the list
3632
33+
Current function implements common ``bisect_right`` algorithms.
34+
The search value represents prefix the string should starts with,
35+
that's why current string is trimmed before comparison operation.
36+
3737
Usage:
3838
3939
>>> data = ["apple", "apple", "banana", "banana", "cherry"]
@@ -66,10 +66,6 @@ def bisect_left(origin: List[str], search: str = "") -> int:
6666
"""
6767
Return the most left one index matching the search value
6868
69-
Current function implements common ``bisect_left`` algorithms.
70-
The search value represents prefix the string should starts with,
71-
that's why current string is trimmed before comparison operation.
72-
7369
:param origin: a list of strings
7470
:type origin: list
7571
:param search: a prefix to search
@@ -80,6 +76,10 @@ def bisect_left(origin: List[str], search: str = "") -> int:
8076
8177
:raise NotFound: if the searched value isn't in the list
8278
79+
Current function implements common ``bisect_left`` algorithms.
80+
The search value represents prefix the string should starts with,
81+
that's why current string is trimmed before comparison operation.
82+
8383
Usage:
8484
8585
>>> data = ["apple", "apple", "banana", "banana", "cherry"]
@@ -112,14 +112,20 @@ def find_all(origin: List[str], search: str = "") -> List[str]:
112112
"""
113113
Return strings starting with prefix
114114
115-
:param origin: the list of strings
115+
:param origin: the sorted list of strings
116116
:type origin: list
117117
:param search: the prefix to search, defaults to empty string
118118
:type search: str
119119
120120
:return: the list of strings starting with the search prefix
121121
:rtype: list
122122
123+
The task is to find **all** values starting with a specified preffix
124+
in a **sorted** list of strings. The straightforward (brute force)
125+
solution to iterate over the entire list is not effective. Instead,
126+
there is a better solution to use "binary search" algorithm, to find
127+
the first one and the last one values, that suite the condition.
128+
123129
Usage:
124130
125131
>>> data = ["apple", "apple", "banana", "banana", "cherry"]

src/calc/func.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ def get_fibonacci_number_nr(idx: int, /) -> int:
8686
"""
8787
Return a Fibonacci's sequence number at a specified index
8888
89-
This function implements the non-recursive algorithm, which is more
90-
efficient, since it does not have multiple recursive calls.
91-
9289
:param idx: a Fibonacci sequence index starting from 0
9390
:type idx: int
9491
9592
:return: a sequence's member
9693
:rtype: int
9794
95+
This function implements the non-recursive algorithm, which is more
96+
efficient, since it does not have multiple recursive calls.
97+
9898
Usage:
9999
100100
>>> assert get_fibonacci_number(0) == 0
@@ -122,9 +122,6 @@ def get_sum_of_strings(number_1: str, number_2: str, /) -> str:
122122
"""
123123
Return the sum of two numbers of string type as string
124124
125-
Valid input is a string of any length containing numeric characters from
126-
0 to 9. Empty strings are allowed as well and should be considered as 0.
127-
128125
:param number_1: first number
129126
:type number_1: str
130127
:param number_2: second number
@@ -133,6 +130,9 @@ def get_sum_of_strings(number_1: str, number_2: str, /) -> str:
133130
:return: the sum of two numbers
134131
:rtype: str
135132
133+
Valid input is a string of any length containing numeric characters from
134+
0 to 9. Empty strings are allowed as well and should be considered as 0.
135+
136136
Usage:
137137
138138
>>> assert get_sum_of_strings("123", "456") == "579"

src/conv_store/models.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ class Product:
1010
"""
1111
Product model implementation
1212
13-
Instances of this class represent a product available for purchase.
14-
1513
:ivar name: the name of a product
1614
:type name: str
1715
:ivar price: the price for a single product unit
1816
:type price: int
1917
:ivar unit: the size of a single product unit
2018
:type unit: int | float
2119
20+
Instances of this class represent a product available for purchase.
21+
2222
"""
2323

2424
def __init__(self,
@@ -78,15 +78,15 @@ def get_total(self, quantity: Optional[Union[int, float]] = None) -> int:
7878
"""
7979
Return the total price for a specified amount of a product
8080
81-
If the quantity argument is omitted, unit attribute value should be
82-
used instead.
83-
8481
:param quantity: a quantity to purchase, defaults to None
8582
:type quantity: int | float, optional
8683
8784
:return: total price for a specified amount of a product
8885
:rtype: int
8986
87+
If the quantity argument is omitted, unit attribute value should be
88+
used instead.
89+
9090
"""
9191

9292
quantity = quantity or self.unit
@@ -103,15 +103,15 @@ def get_units(self, quantity: Union[int, float]) -> int:
103103
class ShoppingCart:
104104
"""Shopping cart model implementation
105105
106-
In general shopping cart is a container for products. Instances of this
107-
class handle product and corresponding quantity for each item inside
108-
a shopping cart instance.
109-
110106
:ivar products: product appended to the shopping cart instance
111107
:type products: list
112108
:ivar quantities: corresponding quantities for each product in cart
113109
:type quantities: list
114110
111+
In general shopping cart is a container for products. Instances of this
112+
class handle product and corresponding quantity for each item inside
113+
a shopping cart instance.
114+
115115
"""
116116

117117
def __init__(self) -> None:
@@ -188,15 +188,15 @@ def add_product(self,
188188
"""
189189
Add product to the shopping cart
190190
191-
This method adds a product instance and corresponding quantity value
192-
to the cart.
193-
194191
:param product: a product instance to add to cart
195192
:type product: :class: `Product`
196193
:param quantity: a quantity of a product to add. Defaults to the
197194
product unit value.
198195
:type quantity: int | float, optional
199196
197+
This method adds a product instance and corresponding quantity value
198+
to the cart.
199+
200200
"""
201201

202202
quantity = quantity or product.unit
@@ -221,14 +221,14 @@ def sub_product(self,
221221
"""
222222
Subtract product from the shopping cart
223223
224-
If quantity value is less or equal to 0 the product is to be
225-
removed from the shopping cart
226-
227224
:param product: a product instance to add to cart
228225
:type product: :class: `Product`
229226
:param quantity: a quantity of a product to add
230227
:type quantity: int | float
231228
229+
If quantity value is less or equal to 0 the product is to be
230+
removed from the shopping cart
231+
232232
"""
233233

234234
quantity = - abs(quantity)

0 commit comments

Comments
 (0)