From b995db92eecd4aad41ecf3c23987e1a7dcf4b759 Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Mon, 30 Dec 2024 06:03:54 -0800 Subject: [PATCH 01/25] Pointless Farmer --- kyu_7/README.md | 74 ++++++------ kyu_7/pointless_farmer/README.md | 38 ++++++ kyu_7/pointless_farmer/__init__.py | 1 + kyu_7/pointless_farmer/solution.py | 33 ++++++ kyu_7/pointless_farmer/test_buy_or_sell.py | 130 +++++++++++++++++++++ 5 files changed, 239 insertions(+), 37 deletions(-) create mode 100644 kyu_7/pointless_farmer/README.md create mode 100644 kyu_7/pointless_farmer/__init__.py create mode 100644 kyu_7/pointless_farmer/solution.py create mode 100644 kyu_7/pointless_farmer/test_buy_or_sell.py diff --git a/kyu_7/README.md b/kyu_7/README.md index 0a547bdaa9c..8e45422d5e2 100644 --- a/kyu_7/README.md +++ b/kyu_7/README.md @@ -15,42 +15,42 @@ rank - the harder the kata the faster you advance. ### List of Completed Kata (Python 3) -| No. | Puzzle/Kata Name | Solution / GitHub Link | -|-----|:--------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------:| -| 1 | [Always perfect](https://www.codewars.com/kata/55f3facb78a9fd5b26000036) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/always_perfect) | -| 2 | [Beginner Series #3 Sum of Numbers](https://www.codewars.com/kata/55f2b110f61eb01779000053) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/beginner_series_sum_of_numbers) | -| 2 | [Coloured Triangles](https://www.codewars.com/kata/5a25ac6ac5e284cfbe000111) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/coloured_triangles) | -| 3 | [Disemvowel Trolls](https://www.codewars.com/kata/52fba66badcd10859f00097e) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/disemvowel_trolls) | -| 4 | [Factorial](https://www.codewars.com/kata/54ff0d1f355cfd20e60001fc) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/factorial) | -| 5 | [Computer problem series #1](https://www.codewars.com/kata/5d49c93d089c6e000ff8428c) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/fill_the_hard_disk_drive) | -| 6 | [Fun with lists: length](https://www.codewars.com/kata/581e476d5f59408553000a4b) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/fun_with_lists_length) | -| 7 | [Jaden Casing Strings](https://www.codewars.com/kata/5390bac347d09b7da40006f6) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/jaden_casing_strings) | -| 8 | [Make Class](https://www.codewars.com/kata/5d774cfde98179002a7cb3c8) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/make_class) | -| 9 | [Maximum Multiple](https://www.codewars.com/kata/5aba780a6a176b029800041c) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/maximum_multiple) | -| 10 | [Password validator](https://www.codewars.com/kata/56a921fa8c5167d8e7000053) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/password_validator) | -| 11 | [Powers of 3](https://www.codewars.com/kata/57be674b93687de78c0001d9) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/powers_of_3) | -| 12 | [Pull your words together, man!](https://www.codewars.com/kata/59ad7d2e07157af687000070) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/pull_your_words_together_man) | -| 13 | [The museum of incredible dull things](https://www.codewars.com/kata/563cf89eb4747c5fb100001b) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/remove_the_minimum) | -| 14 | [Share price](https://www.codewars.com/kata/5603a4dd3d96ef798f000068) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/share_prices) | -| 15 | [Significant Figures Challenge](https://www.codewars.com/kata/5d9fe0ace0aad7001290acb7) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/significant_figures) | -| 16 | [Simple Fun #152: Invite More Women](https://www.codewars.com/kata/58acfe4ae0201e1708000075) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/simple_fun_152) | -| 17 | [Sort Out The Men From Boys](https://www.codewars.com/kata/5af15a37de4c7f223e00012d) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/sort_out_the_men_from_boys) | -| 18 | [Substituting Variables Into Strings: Padded Numbers](https://www.codewars.com/kata/51c89385ee245d7ddf000001) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/substituting_variables_into_strings_padded_numbers) | -| 19 | [Sum of powers of 2](https://www.codewars.com/kata/5d9f95424a336600278a9632) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/sum_of_powers_of_2) | -| 20 | [Sum of Triangular Numbers](https://www.codewars.com/kata/580878d5d27b84b64c000b51) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/sum_of_triangular_numbers) | -| 21 | [Sum of two lowest positive integers](https://www.codewars.com/kata/558fc85d8fd1938afb000014) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/sum_of_two_lowest_int) | -| 22 | [The First Non Repeated Character In A String](https://www.codewars.com/kata/570f6436b29c708a32000826) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/the_first_non_repeated_character_in_string) | -| 23 | [V A P O R C O D E](https://www.codewars.com/kata/5966eeb31b229e44eb00007a) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/vaporcode) | -| 24 | [You're a square](https://www.codewars.com/kata/54c27a33fb7da0db0100040e) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/you_are_square) | -| 25 | [Find the longest gap!](https://www.codewars.com/kata/55b86beb1417eab500000051) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/find_the_longest_gap) | -| 26 | [Simple Fun #74: Growing Plant](https://www.codewars.com/kata/58941fec8afa3618c9000184) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/growing_plant) | -| 27 | [Basic Math (Add or Subtract)](https://www.codewars.com/kata/5809b62808ad92e31b000031) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/basic_math_add_or_subtract) | -| 28 | [Sum of odd numbers](https://www.codewars.com/kata/55fd2d567d94ac3bc9000064) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/sum_of_odd_numbers) | -| 29 | [Help Bob count letters and digits](https://www.codewars.com/kata/5738f5ea9545204cec000155) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/help_bob_count_letters_and_digits) | -| 30 | [Make Class](https://www.codewars.com/kata/5d774cfde98179002a7cb3c8) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/make_class) | -| 31 | [Easy Line](https://www.codewars.com/kata/56e7d40129035aed6c000632) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/easy_line) | -| 32 | [Valid Parentheses](https://www.codewars.com/kata/6411b91a5e71b915d237332d) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/valid_parentheses) | -| 33 | [Complete The Pattern #5 - Even Ladder](https://www.codewars.com/kata/55749101ae1cf7673800003e) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/complete_the_pattern_5_even_ladder) | - +| No. | Puzzle/Kata Name | Solution / GitHub Link | +|-----|:-------------------------------------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------------------------------------------------------:| +| 1 | [Always perfect](https://www.codewars.com/kata/55f3facb78a9fd5b26000036) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/always_perfect) | +| 2 | [Beginner Series #3 Sum of Numbers](https://www.codewars.com/kata/55f2b110f61eb01779000053) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/beginner_series_sum_of_numbers) | +| 2 | [Coloured Triangles](https://www.codewars.com/kata/5a25ac6ac5e284cfbe000111) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/coloured_triangles) | +| 3 | [Disemvowel Trolls](https://www.codewars.com/kata/52fba66badcd10859f00097e) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/disemvowel_trolls) | +| 4 | [Factorial](https://www.codewars.com/kata/54ff0d1f355cfd20e60001fc) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/factorial) | +| 5 | [Computer problem series #1](https://www.codewars.com/kata/5d49c93d089c6e000ff8428c) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/fill_the_hard_disk_drive) | +| 6 | [Fun with lists: length](https://www.codewars.com/kata/581e476d5f59408553000a4b) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/fun_with_lists_length) | +| 7 | [Jaden Casing Strings](https://www.codewars.com/kata/5390bac347d09b7da40006f6) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/jaden_casing_strings) | +| 8 | [Make Class](https://www.codewars.com/kata/5d774cfde98179002a7cb3c8) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/make_class) | +| 9 | [Maximum Multiple](https://www.codewars.com/kata/5aba780a6a176b029800041c) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/maximum_multiple) | +| 10 | [Password validator](https://www.codewars.com/kata/56a921fa8c5167d8e7000053) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/password_validator) | +| 11 | [Powers of 3](https://www.codewars.com/kata/57be674b93687de78c0001d9) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/powers_of_3) | +| 12 | [Pull your words together, man!](https://www.codewars.com/kata/59ad7d2e07157af687000070) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/pull_your_words_together_man) | +| 13 | [The museum of incredible dull things](https://www.codewars.com/kata/563cf89eb4747c5fb100001b) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/remove_the_minimum) | +| 14 | [Share price](https://www.codewars.com/kata/5603a4dd3d96ef798f000068) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/share_prices) | +| 15 | [Significant Figures Challenge](https://www.codewars.com/kata/5d9fe0ace0aad7001290acb7) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/significant_figures) | +| 16 | [Simple Fun #152: Invite More Women](https://www.codewars.com/kata/58acfe4ae0201e1708000075) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/simple_fun_152) | +| 17 | [Sort Out The Men From Boys](https://www.codewars.com/kata/5af15a37de4c7f223e00012d) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/sort_out_the_men_from_boys) | +| 18 | [Substituting Variables Into Strings: Padded Numbers](https://www.codewars.com/kata/51c89385ee245d7ddf000001) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/substituting_variables_into_strings_padded_numbers) | +| 19 | [Sum of powers of 2](https://www.codewars.com/kata/5d9f95424a336600278a9632) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/sum_of_powers_of_2) | +| 20 | [Sum of Triangular Numbers](https://www.codewars.com/kata/580878d5d27b84b64c000b51) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/sum_of_triangular_numbers) | +| 21 | [Sum of two lowest positive integers](https://www.codewars.com/kata/558fc85d8fd1938afb000014) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/sum_of_two_lowest_int) | +| 22 | [The First Non Repeated Character In A String](https://www.codewars.com/kata/570f6436b29c708a32000826) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/the_first_non_repeated_character_in_string) | +| 23 | [V A P O R C O D E](https://www.codewars.com/kata/5966eeb31b229e44eb00007a) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/vaporcode) | +| 24 | [You're a square](https://www.codewars.com/kata/54c27a33fb7da0db0100040e) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/you_are_square) | +| 25 | [Find the longest gap!](https://www.codewars.com/kata/55b86beb1417eab500000051) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/find_the_longest_gap) | +| 26 | [Simple Fun #74: Growing Plant](https://www.codewars.com/kata/58941fec8afa3618c9000184) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/growing_plant) | +| 27 | [Basic Math (Add or Subtract)](https://www.codewars.com/kata/5809b62808ad92e31b000031) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/basic_math_add_or_subtract) | +| 28 | [Sum of odd numbers](https://www.codewars.com/kata/55fd2d567d94ac3bc9000064) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/sum_of_odd_numbers) | +| 29 | [Help Bob count letters and digits](https://www.codewars.com/kata/5738f5ea9545204cec000155) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/help_bob_count_letters_and_digits) | +| 30 | [Make Class](https://www.codewars.com/kata/5d774cfde98179002a7cb3c8) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/make_class) | +| 31 | [Easy Line](https://www.codewars.com/kata/56e7d40129035aed6c000632) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/easy_line) | +| 32 | [Valid Parentheses](https://www.codewars.com/kata/6411b91a5e71b915d237332d) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/valid_parentheses) | +| 33 | [Complete The Pattern #5 - Even Ladder](https://www.codewars.com/kata/55749101ae1cf7673800003e) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/complete_the_pattern_5_even_ladder) | +| 34 | [Pointless Farmer](https://www.codewars.com/kata/597ab747d1ba5b843f0000ca) | [Solution](https://github.com/ikostan/codewars/tree/master/kyu_7/pointless_farmer) | [Source](https://www.codewars.com/about) \ No newline at end of file diff --git a/kyu_7/pointless_farmer/README.md b/kyu_7/pointless_farmer/README.md new file mode 100644 index 00000000000..cd6338462b0 --- /dev/null +++ b/kyu_7/pointless_farmer/README.md @@ -0,0 +1,38 @@ +# Pointless Farmer + +You've harvested a fruit. But the Internal Raisin Service (IRS) doesn't +allow you to eat your own produce, you have to launder it on the market first. +When you visit the market, you are given three conversion offers, and for +each conversion offer you must decide which direction to trade. A conversion +offer is a pair of fruits, and to buy the second fruit for the first fruit, +the action is "buy". The opposite direction is "sell". + +Given the offer `("apple", "orange")`, if you have an `apple`, then you may `buy +an orange`, or, if you have an `orange`, you may `sell` it for the apple. + +## Example + +```bash +pairs: [("apple", "orange"), ("orange", "pear"), ("apple", "pear")] +harvested fruit: "apple" + +currently holding: apple +("apple", "orange") +buy +currently holding: orange +("orange", "pear") +buy +currently holding: pear +("apple", "pear") +sell +currently holding: apple (successfully ended up with the same fruit again) +``` + +As input you receive three conversion offers together with your harvested fruit, +and your output is a list of three actions of buy/sell, for the above example the +output is: `["buy", "buy", "sell"]`. + +If it is not possible to end up with the original kind of fruit again after the +three conversions, return `"ERROR"` instead of the list of actions. + +[Source](https://www.codewars.com/kata/597ab747d1ba5b843f0000ca) \ No newline at end of file diff --git a/kyu_7/pointless_farmer/__init__.py b/kyu_7/pointless_farmer/__init__.py new file mode 100644 index 00000000000..57ade5c82d2 --- /dev/null +++ b/kyu_7/pointless_farmer/__init__.py @@ -0,0 +1 @@ +"""Pointless Farmer.""" diff --git a/kyu_7/pointless_farmer/solution.py b/kyu_7/pointless_farmer/solution.py new file mode 100644 index 00000000000..02e4ca5b35d --- /dev/null +++ b/kyu_7/pointless_farmer/solution.py @@ -0,0 +1,33 @@ +""" +Solution for -> Pointless Farmer. + +Created by Egor Kostan. +GitHub: https://github.com/ikostan +""" + + +def buy_or_sell(pairs: list, harvested_fruit: str) -> list | str: + """ + Decide which direction to trade. + + :param pairs: list + :param harvested_fruit: str + :return: list + """ + currently_holding: str = harvested_fruit + results: list = [] + + for pair in pairs: + # First item in pairs is for selling, second is for buying. + if pair[0] == currently_holding == pair[-1]: + results.append('sell') + elif pair[-1] == currently_holding: + results.append('sell') + currently_holding = pair[0] + elif pair[0] == currently_holding: + results.append('buy') + currently_holding = pair[-1] + else: + return "ERROR" + + return results if currently_holding == harvested_fruit else "ERROR" diff --git a/kyu_7/pointless_farmer/test_buy_or_sell.py b/kyu_7/pointless_farmer/test_buy_or_sell.py new file mode 100644 index 00000000000..00bca6e78ee --- /dev/null +++ b/kyu_7/pointless_farmer/test_buy_or_sell.py @@ -0,0 +1,130 @@ +""" +Test for -> Pointless Farmer. + +Created by Egor Kostan. +GitHub: https://github.com/ikostan +""" + +# ALGORITHMS + +import unittest +import allure +from parameterized import parameterized +from utils.log_func import print_log +from kyu_7.pointless_farmer.solution import buy_or_sell + + +# pylint: disable-msg=R0801 +@allure.epic('7 kyu') +@allure.parent_suite('Beginner') +@allure.suite("Algorithms") +@allure.sub_suite("Unit Tests") +@allure.feature("Lista") +@allure.story('Password validator') +@allure.tag('FUNDAMENTALS', + 'ALGORITHMS') +@allure.link( + url='https://www.codewars.com/kata/597ab747d1ba5b843f0000ca', + name='Source/Kata') +# pylint: enable-msg=R0801 +class PointlessFarmerTestCase(unittest.TestCase): + """Test 'buy_or_sell' function.""" + + @parameterized.expand([ + ([("apple", "orange"), ("orange", "pear"), ("apple", "pear")], + "apple", ["buy", "buy", "sell"]), + ([("orange", "apple"), ("orange", "pear"), ("pear", "apple")], + "apple", ["sell", "buy", "buy"]), + ([("apple", "orange"), ("pear", "orange"), ("apple", "pear")], + "apple", ["buy", "sell", "sell"]), + ([("orange", "apple"), ("pear", "orange"), ("pear", "apple")], + "apple", ["sell", "sell", "buy"]), + ([("orange", "apple"), ("orange", "pear"), ("apple", "pear")], + "apple", ["sell", "buy", "sell"]), + ([("apple", "orange"), ("pear", "orange"), ("pear", "apple")], + "apple", ["buy", "sell", "buy"]), + ([("apple", "orange"), ("orange", "pear"), ("pear", "apple")], + "apple", ["buy", "buy", "buy"]), + ([("orange", "apple"), ("pear", "orange"), ("apple", "pear")], + "apple", ["sell", "sell", "sell"]), + ([('Raspberry', 'Raspberry'), ('Jabuticaba', 'Raspberry'), + ('Jabuticaba', 'Raspberry')], 'Raspberry', ['sell', 'sell', 'buy'])]) + def test_buy_or_sell_positive(self, market, harvested_fruit, expected): + """ + Testing 'buy_or_sell' function, positive test case.. + + :return: + """ + # pylint: disable-msg=R0801 + allure.dynamic.title("Testing 'buy_or_sell' function -> positive.") + allure.dynamic.severity(allure.severity_level.NORMAL) + allure.dynamic.description_html( + '
"
+ "When you visit the market, you are given three conversion "
+ "offers, and for each conversion offer you must decide which "
+ "direction to trade. A conversion offer is a pair of fruits, "
+ "and to buy the second fruit for the first fruit, the action is 'buy'."
+ "
"
+ "The opposite direction is 'sell'."
+ "
" + "If it is not possible to end up with the original kind " + "of fruit again after the three conversions, return \"ERROR\" " + "instead of the list of actions." + "
") + # pylint: enable-msg=R0801 + with allure.step(f"Enter test data: {market} " + f"and verify the expected result: {expected}."): + result: list = buy_or_sell(market, harvested_fruit) + print_log(market=market, + harvested_fruit=harvested_fruit, + expected=expected, + result=result) + self.assertEqual(expected, result) + + + From ff5a4cfaf4ee24598444dfe01773481490e86d91 Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Mon, 30 Dec 2024 06:04:42 -0800 Subject: [PATCH 02/25] Create kyu_7.pointless_farmer.rst --- docs/kyu_7.pointless_farmer.rst | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 docs/kyu_7.pointless_farmer.rst diff --git a/docs/kyu_7.pointless_farmer.rst b/docs/kyu_7.pointless_farmer.rst new file mode 100644 index 00000000000..0d37f7e894e --- /dev/null +++ b/docs/kyu_7.pointless_farmer.rst @@ -0,0 +1,32 @@ +kyu\_7.pointless\_farmer package +================================ + +Submodules +---------- + +kyu\_7.pointless\_farmer.solution module +---------------------------------------- + +.. automodule:: kyu_7.pointless_farmer.solution + :members: + :undoc-members: + :show-inheritance: + :private-members: + +kyu\_7.pointless\_farmer.test\_buy\_or\_sell module +--------------------------------------------------- + +.. automodule:: kyu_7.pointless_farmer.test_buy_or_sell + :members: + :undoc-members: + :show-inheritance: + :private-members: + +Module contents +--------------- + +.. automodule:: kyu_7.pointless_farmer + :members: + :undoc-members: + :show-inheritance: + :private-members: From f8f20d7c5ecaf233d066392047bfadd4049e3fde Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Mon, 30 Dec 2024 06:09:32 -0800 Subject: [PATCH 03/25] Updated docs --- docs/kyu_7/kyu_7.password_validator.module.rst | 4 ++-- docs/kyu_7/kyu_7.pointless_farmer.module.rst | 11 +++++++++++ docs/kyu_7/kyu_7.pointless_farmer.readme.rst | 5 +++++ docs/{ => kyu_7}/kyu_7.pointless_farmer.rst | 0 docs/kyu_7/kyu_7.rst | 1 + 5 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 docs/kyu_7/kyu_7.pointless_farmer.module.rst create mode 100644 docs/kyu_7/kyu_7.pointless_farmer.readme.rst rename docs/{ => kyu_7}/kyu_7.pointless_farmer.rst (100%) diff --git a/docs/kyu_7/kyu_7.password_validator.module.rst b/docs/kyu_7/kyu_7.password_validator.module.rst index 5b2bd79d7e0..5e7e80d06fc 100644 --- a/docs/kyu_7/kyu_7.password_validator.module.rst +++ b/docs/kyu_7/kyu_7.password_validator.module.rst @@ -1,5 +1,5 @@ -kyu\_7.password_validator.module package -======================================== +kyu\_7.password\_validator.module package +========================================= Subpackages ----------- diff --git a/docs/kyu_7/kyu_7.pointless_farmer.module.rst b/docs/kyu_7/kyu_7.pointless_farmer.module.rst new file mode 100644 index 00000000000..777bba80277 --- /dev/null +++ b/docs/kyu_7/kyu_7.pointless_farmer.module.rst @@ -0,0 +1,11 @@ +kyu\_7.pointless\_farmer.module package +======================================= + +Subpackages +----------- + +.. toctree:: + :maxdepth: 4 + + kyu_7.pointless_farmer.readme + kyu_7.pointless_farmer \ No newline at end of file diff --git a/docs/kyu_7/kyu_7.pointless_farmer.readme.rst b/docs/kyu_7/kyu_7.pointless_farmer.readme.rst new file mode 100644 index 00000000000..c90786f5020 --- /dev/null +++ b/docs/kyu_7/kyu_7.pointless_farmer.readme.rst @@ -0,0 +1,5 @@ +README +====== + +.. include:: ../../kyu_7/pointless_farmer/README.md + :parser: myst_parser.sphinx_ \ No newline at end of file diff --git a/docs/kyu_7.pointless_farmer.rst b/docs/kyu_7/kyu_7.pointless_farmer.rst similarity index 100% rename from docs/kyu_7.pointless_farmer.rst rename to docs/kyu_7/kyu_7.pointless_farmer.rst diff --git a/docs/kyu_7/kyu_7.rst b/docs/kyu_7/kyu_7.rst index 0542201924d..5f5b71943a5 100644 --- a/docs/kyu_7/kyu_7.rst +++ b/docs/kyu_7/kyu_7.rst @@ -26,6 +26,7 @@ Subpackages kyu_7.make_class.module kyu_7.maximum_multiple.module kyu_7.password_validator.module + kyu_7.pointless_farmer.module kyu_7.powers_of_3.module kyu_7.pull_your_words_together_man.module kyu_7.remove_the_minimum.module From 6ddff15c4ccdf377c77de1b5664cd4c1b8c69de2 Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Mon, 30 Dec 2024 06:12:33 -0800 Subject: [PATCH 04/25] Update test_buy_or_sell.py --- kyu_7/pointless_farmer/test_buy_or_sell.py | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/kyu_7/pointless_farmer/test_buy_or_sell.py b/kyu_7/pointless_farmer/test_buy_or_sell.py index 00bca6e78ee..12d72075735 100644 --- a/kyu_7/pointless_farmer/test_buy_or_sell.py +++ b/kyu_7/pointless_farmer/test_buy_or_sell.py @@ -32,21 +32,21 @@ class PointlessFarmerTestCase(unittest.TestCase): @parameterized.expand([ ([("apple", "orange"), ("orange", "pear"), ("apple", "pear")], - "apple", ["buy", "buy", "sell"]), + "apple", ["buy", "buy", "sell"]), ([("orange", "apple"), ("orange", "pear"), ("pear", "apple")], - "apple", ["sell", "buy", "buy"]), + "apple", ["sell", "buy", "buy"]), ([("apple", "orange"), ("pear", "orange"), ("apple", "pear")], - "apple", ["buy", "sell", "sell"]), + "apple", ["buy", "sell", "sell"]), ([("orange", "apple"), ("pear", "orange"), ("pear", "apple")], - "apple", ["sell", "sell", "buy"]), + "apple", ["sell", "sell", "buy"]), ([("orange", "apple"), ("orange", "pear"), ("apple", "pear")], - "apple", ["sell", "buy", "sell"]), + "apple", ["sell", "buy", "sell"]), ([("apple", "orange"), ("pear", "orange"), ("pear", "apple")], - "apple", ["buy", "sell", "buy"]), + "apple", ["buy", "sell", "buy"]), ([("apple", "orange"), ("orange", "pear"), ("pear", "apple")], - "apple", ["buy", "buy", "buy"]), + "apple", ["buy", "buy", "buy"]), ([("orange", "apple"), ("pear", "orange"), ("apple", "pear")], - "apple", ["sell", "sell", "sell"]), + "apple", ["sell", "sell", "sell"]), ([('Raspberry', 'Raspberry'), ('Jabuticaba', 'Raspberry'), ('Jabuticaba', 'Raspberry')], 'Raspberry', ['sell', 'sell', 'buy'])]) def test_buy_or_sell_positive(self, market, harvested_fruit, expected): @@ -84,18 +84,18 @@ def test_buy_or_sell_positive(self, market, harvested_fruit, expected): @parameterized.expand([ ([("orange", "apple"), ("pear", "orange"), ("apple", "paer")], - "apple", "ERROR"), + "apple", "ERROR"), ([('Jackfruit', 'Physalis'), ('Physalis', 'Prune'), ('Prune', 'Tamarind')], - 'Tamarind', 'ERROR'), + 'Tamarind', 'ERROR'), ([('Mulberry', 'Strawberry'), ('Passionfruit', 'Mulberry'), ('Strawberry', 'Mulberry')], - 'Strawberry', 'ERROR'), + 'Strawberry', 'ERROR'), ([('Cherry', 'Cucumber'), ('Cherry', 'Cherry'), ('Cucumber', 'Ugli fruit')], - 'Boysenberry', 'ERROR'), + 'Boysenberry', 'ERROR'), ([('Jackfruit', 'Purple mangosteen'), ('Purple mangosteen', 'Jackfruit'), ('Purple mangosteen', 'Jackfruit')], - 'Purple mangosteen', 'ERROR')]) + 'Purple mangosteen', 'ERROR')]) def test_buy_or_sell_negative(self, market, harvested_fruit, expected): """ Testing 'buy_or_sell' function, negative test case. From c84b223167891a644721cffaaeaa27a4a3fee3c5 Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Mon, 30 Dec 2024 06:15:01 -0800 Subject: [PATCH 05/25] Update test_buy_or_sell.py --- kyu_7/pointless_farmer/test_buy_or_sell.py | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/kyu_7/pointless_farmer/test_buy_or_sell.py b/kyu_7/pointless_farmer/test_buy_or_sell.py index 12d72075735..d7a826d42c3 100644 --- a/kyu_7/pointless_farmer/test_buy_or_sell.py +++ b/kyu_7/pointless_farmer/test_buy_or_sell.py @@ -32,21 +32,21 @@ class PointlessFarmerTestCase(unittest.TestCase): @parameterized.expand([ ([("apple", "orange"), ("orange", "pear"), ("apple", "pear")], - "apple", ["buy", "buy", "sell"]), + "apple", ["buy", "buy", "sell"]), ([("orange", "apple"), ("orange", "pear"), ("pear", "apple")], - "apple", ["sell", "buy", "buy"]), + "apple", ["sell", "buy", "buy"]), ([("apple", "orange"), ("pear", "orange"), ("apple", "pear")], - "apple", ["buy", "sell", "sell"]), + "apple", ["buy", "sell", "sell"]), ([("orange", "apple"), ("pear", "orange"), ("pear", "apple")], - "apple", ["sell", "sell", "buy"]), + "apple", ["sell", "sell", "buy"]), ([("orange", "apple"), ("orange", "pear"), ("apple", "pear")], - "apple", ["sell", "buy", "sell"]), + "apple", ["sell", "buy", "sell"]), ([("apple", "orange"), ("pear", "orange"), ("pear", "apple")], - "apple", ["buy", "sell", "buy"]), + "apple", ["buy", "sell", "buy"]), ([("apple", "orange"), ("orange", "pear"), ("pear", "apple")], - "apple", ["buy", "buy", "buy"]), + "apple", ["buy", "buy", "buy"]), ([("orange", "apple"), ("pear", "orange"), ("apple", "pear")], - "apple", ["sell", "sell", "sell"]), + "apple", ["sell", "sell", "sell"]), ([('Raspberry', 'Raspberry'), ('Jabuticaba', 'Raspberry'), ('Jabuticaba', 'Raspberry')], 'Raspberry', ['sell', 'sell', 'buy'])]) def test_buy_or_sell_positive(self, market, harvested_fruit, expected): @@ -84,18 +84,18 @@ def test_buy_or_sell_positive(self, market, harvested_fruit, expected): @parameterized.expand([ ([("orange", "apple"), ("pear", "orange"), ("apple", "paer")], - "apple", "ERROR"), + "apple", "ERROR"), ([('Jackfruit', 'Physalis'), ('Physalis', 'Prune'), ('Prune', 'Tamarind')], - 'Tamarind', 'ERROR'), + 'Tamarind', 'ERROR'), ([('Mulberry', 'Strawberry'), ('Passionfruit', 'Mulberry'), ('Strawberry', 'Mulberry')], - 'Strawberry', 'ERROR'), + 'Strawberry', 'ERROR'), ([('Cherry', 'Cucumber'), ('Cherry', 'Cherry'), ('Cucumber', 'Ugli fruit')], - 'Boysenberry', 'ERROR'), + 'Boysenberry', 'ERROR'), ([('Jackfruit', 'Purple mangosteen'), ('Purple mangosteen', 'Jackfruit'), ('Purple mangosteen', 'Jackfruit')], - 'Purple mangosteen', 'ERROR')]) + 'Purple mangosteen', 'ERROR')]) def test_buy_or_sell_negative(self, market, harvested_fruit, expected): """ Testing 'buy_or_sell' function, negative test case. From f500c8a877f29f7eda56a45c9fb49407f6907005 Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Mon, 30 Dec 2024 06:16:13 -0800 Subject: [PATCH 06/25] Update test_buy_or_sell.py --- kyu_7/pointless_farmer/test_buy_or_sell.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/kyu_7/pointless_farmer/test_buy_or_sell.py b/kyu_7/pointless_farmer/test_buy_or_sell.py index d7a826d42c3..79f9e25cc91 100644 --- a/kyu_7/pointless_farmer/test_buy_or_sell.py +++ b/kyu_7/pointless_farmer/test_buy_or_sell.py @@ -125,6 +125,3 @@ def test_buy_or_sell_negative(self, market, harvested_fruit, expected): expected=expected, result=result) self.assertEqual(expected, result) - - - From e478e15fa4eb1a517ff39499efb0b55c84599621 Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Mon, 30 Dec 2024 06:20:48 -0800 Subject: [PATCH 07/25] Update solution.py --- kyu_7/pointless_farmer/solution.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kyu_7/pointless_farmer/solution.py b/kyu_7/pointless_farmer/solution.py index 02e4ca5b35d..b3e2b7d27a4 100644 --- a/kyu_7/pointless_farmer/solution.py +++ b/kyu_7/pointless_farmer/solution.py @@ -6,7 +6,7 @@ """ -def buy_or_sell(pairs: list, harvested_fruit: str) -> list | str: +def buy_or_sell(pairs: list, harvested_fruit: str) -> list[str] | str: """ Decide which direction to trade. From 020da2bc84aaf96f2021e4442037dab99a04043a Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Mon, 30 Dec 2024 06:22:38 -0800 Subject: [PATCH 08/25] Update solution.py --- kyu_7/pointless_farmer/solution.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kyu_7/pointless_farmer/solution.py b/kyu_7/pointless_farmer/solution.py index b3e2b7d27a4..021fd35ca57 100644 --- a/kyu_7/pointless_farmer/solution.py +++ b/kyu_7/pointless_farmer/solution.py @@ -5,8 +5,10 @@ GitHub: https://github.com/ikostan """ +from typing import Tuple -def buy_or_sell(pairs: list, harvested_fruit: str) -> list[str] | str: + +def buy_or_sell(pairs: list, harvested_fruit: str) -> Tuple[list, str]: """ Decide which direction to trade. From 60ce175e4af4acacfa474d31ac0e98916064f8a6 Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Mon, 30 Dec 2024 06:23:10 -0800 Subject: [PATCH 09/25] Update solution.py --- kyu_7/pointless_farmer/solution.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/kyu_7/pointless_farmer/solution.py b/kyu_7/pointless_farmer/solution.py index 021fd35ca57..02e4ca5b35d 100644 --- a/kyu_7/pointless_farmer/solution.py +++ b/kyu_7/pointless_farmer/solution.py @@ -5,10 +5,8 @@ GitHub: https://github.com/ikostan """ -from typing import Tuple - -def buy_or_sell(pairs: list, harvested_fruit: str) -> Tuple[list, str]: +def buy_or_sell(pairs: list, harvested_fruit: str) -> list | str: """ Decide which direction to trade. From 4b117f3b14cf0fd622cc0cda769e2e1757fc37ff Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Mon, 30 Dec 2024 06:25:12 -0800 Subject: [PATCH 10/25] Update solution.py --- kyu_7/pointless_farmer/solution.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kyu_7/pointless_farmer/solution.py b/kyu_7/pointless_farmer/solution.py index 02e4ca5b35d..bca89d979da 100644 --- a/kyu_7/pointless_farmer/solution.py +++ b/kyu_7/pointless_farmer/solution.py @@ -5,8 +5,10 @@ GitHub: https://github.com/ikostan """ +from typing import Any -def buy_or_sell(pairs: list, harvested_fruit: str) -> list | str: + +def buy_or_sell(pairs: list, harvested_fruit: str) -> list[Any] | str: """ Decide which direction to trade. From 9a9d23d3d8874662e5baba482d8499d672ff05e7 Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Mon, 30 Dec 2024 06:28:17 -0800 Subject: [PATCH 11/25] Update solution.py --- kyu_7/pointless_farmer/solution.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/kyu_7/pointless_farmer/solution.py b/kyu_7/pointless_farmer/solution.py index bca89d979da..5659555e0dc 100644 --- a/kyu_7/pointless_farmer/solution.py +++ b/kyu_7/pointless_farmer/solution.py @@ -21,9 +21,7 @@ def buy_or_sell(pairs: list, harvested_fruit: str) -> list[Any] | str: for pair in pairs: # First item in pairs is for selling, second is for buying. - if pair[0] == currently_holding == pair[-1]: - results.append('sell') - elif pair[-1] == currently_holding: + if pair[0] == currently_holding == pair[-1] or pair[-1] == currently_holding: results.append('sell') currently_holding = pair[0] elif pair[0] == currently_holding: From 04bd4401314ae011beac7d05b218705dfe05282c Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Mon, 30 Dec 2024 06:31:06 -0800 Subject: [PATCH 12/25] Update solution.py --- kyu_7/pointless_farmer/solution.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kyu_7/pointless_farmer/solution.py b/kyu_7/pointless_farmer/solution.py index 5659555e0dc..afd865412ab 100644 --- a/kyu_7/pointless_farmer/solution.py +++ b/kyu_7/pointless_farmer/solution.py @@ -24,10 +24,12 @@ def buy_or_sell(pairs: list, harvested_fruit: str) -> list[Any] | str: if pair[0] == currently_holding == pair[-1] or pair[-1] == currently_holding: results.append('sell') currently_holding = pair[0] + continue elif pair[0] == currently_holding: results.append('buy') currently_holding = pair[-1] - else: - return "ERROR" + continue + + return "ERROR" return results if currently_holding == harvested_fruit else "ERROR" From f23183a40c8e09dcb30bc48f7f1b0d956210a00c Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Mon, 30 Dec 2024 06:32:54 -0800 Subject: [PATCH 13/25] Update solution.py --- kyu_7/pointless_farmer/solution.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kyu_7/pointless_farmer/solution.py b/kyu_7/pointless_farmer/solution.py index afd865412ab..b0426698072 100644 --- a/kyu_7/pointless_farmer/solution.py +++ b/kyu_7/pointless_farmer/solution.py @@ -21,7 +21,7 @@ def buy_or_sell(pairs: list, harvested_fruit: str) -> list[Any] | str: for pair in pairs: # First item in pairs is for selling, second is for buying. - if pair[0] == currently_holding == pair[-1] or pair[-1] == currently_holding: + if pair[-1] == currently_holding: results.append('sell') currently_holding = pair[0] continue From 2b8e71f85384f4f6b9fbfa28d21c681a0cf5e0d8 Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Mon, 30 Dec 2024 06:35:16 -0800 Subject: [PATCH 14/25] Update solution.py --- kyu_7/pointless_farmer/solution.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kyu_7/pointless_farmer/solution.py b/kyu_7/pointless_farmer/solution.py index b0426698072..ae98bb74fd4 100644 --- a/kyu_7/pointless_farmer/solution.py +++ b/kyu_7/pointless_farmer/solution.py @@ -32,4 +32,4 @@ def buy_or_sell(pairs: list, harvested_fruit: str) -> list[Any] | str: return "ERROR" - return results if currently_holding == harvested_fruit else "ERROR" + return "ERROR" if currently_holding != harvested_fruit else results From 4cf1a447bac0ed71d3a90f02b56b629a300adc76 Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Mon, 30 Dec 2024 06:36:49 -0800 Subject: [PATCH 15/25] Update solution.py --- kyu_7/pointless_farmer/solution.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kyu_7/pointless_farmer/solution.py b/kyu_7/pointless_farmer/solution.py index ae98bb74fd4..152e4ac7223 100644 --- a/kyu_7/pointless_farmer/solution.py +++ b/kyu_7/pointless_farmer/solution.py @@ -25,7 +25,8 @@ def buy_or_sell(pairs: list, harvested_fruit: str) -> list[Any] | str: results.append('sell') currently_holding = pair[0] continue - elif pair[0] == currently_holding: + + if pair[0] == currently_holding: results.append('buy') currently_holding = pair[-1] continue From 7eea164b98ce8f51af4e2116bdae459016f63b23 Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Mon, 30 Dec 2024 06:43:32 -0800 Subject: [PATCH 16/25] Update solution.py --- kyu_7/pointless_farmer/solution.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kyu_7/pointless_farmer/solution.py b/kyu_7/pointless_farmer/solution.py index 152e4ac7223..8cf2847b537 100644 --- a/kyu_7/pointless_farmer/solution.py +++ b/kyu_7/pointless_farmer/solution.py @@ -8,7 +8,7 @@ from typing import Any -def buy_or_sell(pairs: list, harvested_fruit: str) -> list[Any] | str: +def buy_or_sell(pairs: list, harvested_fruit: str) -> str | list: """ Decide which direction to trade. @@ -20,12 +20,12 @@ def buy_or_sell(pairs: list, harvested_fruit: str) -> list[Any] | str: results: list = [] for pair in pairs: - # First item in pairs is for selling, second is for buying. + # First item in pairs is for selling. if pair[-1] == currently_holding: results.append('sell') currently_holding = pair[0] continue - + # Second is for buying. if pair[0] == currently_holding: results.append('buy') currently_holding = pair[-1] From 6615dc559af268e60e1af8f9627c9221bb0578a6 Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Mon, 30 Dec 2024 06:45:37 -0800 Subject: [PATCH 17/25] Update solution.py --- kyu_7/pointless_farmer/solution.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/kyu_7/pointless_farmer/solution.py b/kyu_7/pointless_farmer/solution.py index 8cf2847b537..b4430c20550 100644 --- a/kyu_7/pointless_farmer/solution.py +++ b/kyu_7/pointless_farmer/solution.py @@ -5,8 +5,6 @@ GitHub: https://github.com/ikostan """ -from typing import Any - def buy_or_sell(pairs: list, harvested_fruit: str) -> str | list: """ From 1c2a2d90def79f8ee4020013584b997f21bc1785 Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Mon, 30 Dec 2024 06:58:03 -0800 Subject: [PATCH 18/25] Update solution.py --- kyu_7/pointless_farmer/solution.py | 35 +++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/kyu_7/pointless_farmer/solution.py b/kyu_7/pointless_farmer/solution.py index b4430c20550..d53421deb05 100644 --- a/kyu_7/pointless_farmer/solution.py +++ b/kyu_7/pointless_farmer/solution.py @@ -12,23 +12,38 @@ def buy_or_sell(pairs: list, harvested_fruit: str) -> str | list: :param pairs: list :param harvested_fruit: str - :return: list + :return: """ currently_holding: str = harvested_fruit results: list = [] for pair in pairs: - # First item in pairs is for selling. - if pair[-1] == currently_holding: - results.append('sell') - currently_holding = pair[0] - continue - # Second is for buying. - if pair[0] == currently_holding: - results.append('buy') - currently_holding = pair[-1] + currently_holding = make_deal(results, pair, currently_holding) + if currently_holding: continue return "ERROR" return "ERROR" if currently_holding != harvested_fruit else results + + +def make_deal(results: list, pair: tuple, currently_holding: str) -> str: + """ + Buy or sell. + + Return an empty string if no deal made. + :param results: list + :param pair: tuple + :param currently_holding: str + :return: str + """ + # First item in pairs is for selling. + if pair[-1] == currently_holding: + results.append('sell') + return pair[0] + # Second is for buying. + if pair[0] == currently_holding: + results.append('buy') + return pair[-1] + + return '' From a8f34ca451e7e166c97acccb5f2719a79a6b6955 Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Mon, 30 Dec 2024 06:59:49 -0800 Subject: [PATCH 19/25] Update solution.py --- kyu_7/pointless_farmer/solution.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kyu_7/pointless_farmer/solution.py b/kyu_7/pointless_farmer/solution.py index d53421deb05..e07f98b8800 100644 --- a/kyu_7/pointless_farmer/solution.py +++ b/kyu_7/pointless_farmer/solution.py @@ -5,8 +5,10 @@ GitHub: https://github.com/ikostan """ +from typing import Any -def buy_or_sell(pairs: list, harvested_fruit: str) -> str | list: + +def buy_or_sell(pairs: list, harvested_fruit: str) -> list[Any]: """ Decide which direction to trade. From 7dc66d6f51fcf9ee0cc0be5e6dc340d39a681a3f Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Mon, 30 Dec 2024 07:01:28 -0800 Subject: [PATCH 20/25] Update solution.py --- kyu_7/pointless_farmer/solution.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/kyu_7/pointless_farmer/solution.py b/kyu_7/pointless_farmer/solution.py index e07f98b8800..d53421deb05 100644 --- a/kyu_7/pointless_farmer/solution.py +++ b/kyu_7/pointless_farmer/solution.py @@ -5,10 +5,8 @@ GitHub: https://github.com/ikostan """ -from typing import Any - -def buy_or_sell(pairs: list, harvested_fruit: str) -> list[Any]: +def buy_or_sell(pairs: list, harvested_fruit: str) -> str | list: """ Decide which direction to trade. From c61d6ea35b8cc93545c80dcdb65b97e238bdca1d Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Mon, 30 Dec 2024 07:10:38 -0800 Subject: [PATCH 21/25] Update solution.py --- kyu_7/pointless_farmer/solution.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kyu_7/pointless_farmer/solution.py b/kyu_7/pointless_farmer/solution.py index d53421deb05..9fe073ca461 100644 --- a/kyu_7/pointless_farmer/solution.py +++ b/kyu_7/pointless_farmer/solution.py @@ -5,8 +5,12 @@ GitHub: https://github.com/ikostan """ +from typing import TypeVar -def buy_or_sell(pairs: list, harvested_fruit: str) -> str | list: + +T = TypeVar("T", bound=str|list) + +def buy_or_sell(pairs: list, harvested_fruit: str) -> T: """ Decide which direction to trade. From 22c66d5fe289a7a2bdda40eb5f10c04bb4d2635f Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Mon, 30 Dec 2024 07:12:24 -0800 Subject: [PATCH 22/25] Update solution.py --- kyu_7/pointless_farmer/solution.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kyu_7/pointless_farmer/solution.py b/kyu_7/pointless_farmer/solution.py index 9fe073ca461..bcfb5df8662 100644 --- a/kyu_7/pointless_farmer/solution.py +++ b/kyu_7/pointless_farmer/solution.py @@ -7,8 +7,8 @@ from typing import TypeVar +T = TypeVar("T", bound=str | list) -T = TypeVar("T", bound=str|list) def buy_or_sell(pairs: list, harvested_fruit: str) -> T: """ From 67975bbf3866c544c0a5d087595d81c029f69715 Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Mon, 30 Dec 2024 07:13:59 -0800 Subject: [PATCH 23/25] Update solution.py --- kyu_7/pointless_farmer/solution.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kyu_7/pointless_farmer/solution.py b/kyu_7/pointless_farmer/solution.py index bcfb5df8662..88151994cc9 100644 --- a/kyu_7/pointless_farmer/solution.py +++ b/kyu_7/pointless_farmer/solution.py @@ -5,9 +5,9 @@ GitHub: https://github.com/ikostan """ -from typing import TypeVar +from typing import TypeVar, Any -T = TypeVar("T", bound=str | list) +T = TypeVar("T", bound=str | list[Any]) def buy_or_sell(pairs: list, harvested_fruit: str) -> T: From 8890887c9259011701c4f199150222378c40c3c8 Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Mon, 30 Dec 2024 07:19:04 -0800 Subject: [PATCH 24/25] Update solution.py --- kyu_7/pointless_farmer/solution.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/kyu_7/pointless_farmer/solution.py b/kyu_7/pointless_farmer/solution.py index 88151994cc9..b2699542079 100644 --- a/kyu_7/pointless_farmer/solution.py +++ b/kyu_7/pointless_farmer/solution.py @@ -5,12 +5,8 @@ GitHub: https://github.com/ikostan """ -from typing import TypeVar, Any -T = TypeVar("T", bound=str | list[Any]) - - -def buy_or_sell(pairs: list, harvested_fruit: str) -> T: +def buy_or_sell(pairs: list, harvested_fruit: str): """ Decide which direction to trade. From c25cc6cb292cfad5ade573102a8b9c7a2c1fd631 Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Mon, 30 Dec 2024 07:26:34 -0800 Subject: [PATCH 25/25] Update solution.py --- kyu_7/pointless_farmer/solution.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kyu_7/pointless_farmer/solution.py b/kyu_7/pointless_farmer/solution.py index b2699542079..a5cba2c3e77 100644 --- a/kyu_7/pointless_farmer/solution.py +++ b/kyu_7/pointless_farmer/solution.py @@ -29,7 +29,7 @@ def buy_or_sell(pairs: list, harvested_fruit: str): def make_deal(results: list, pair: tuple, currently_holding: str) -> str: """ - Buy or sell. + Return the new currently_holding value on successful deals. Return an empty string if no deal made. :param results: list