-
Notifications
You must be signed in to change notification settings - Fork 20
Week2 #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Abusagit
wants to merge
18
commits into
aglabx:main
Choose a base branch
from
Abusagit:week2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Week2 #15
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5c6b4da
Added ./students/Abusagit/ as template
Abusagit 6c91d88
feat: add codewars sorting solutions
Abusagit dca2001
feat: add yandex week2
Abusagit a3095ed
feat: add codewars week2
Abusagit adf4cf7
feat: add rosalind week2
Abusagit a1bbdd9
feat/add Yandex
Abusagit 64c18b6
merged conflicts symmetric.py
Abusagit 9570778
feat/add koonin/chapter2.md
Abusagit 7541cff
feat/add fasta_reader.py
Abusagit 72bd080
Merge branch 'main' into week2
Abusagit c9d2814
feat/add: rename playgrounds -> playground
Abusagit 0c6f46d
Merge branch 'week2' of https://github.com/Abusagit/edusummer2021 int…
Abusagit a2c5b2a
feat/add: rename kunin -> koonin
Abusagit e848d6e
feat/add: rename basic_algo -> yandex
Abusagit 799496f
feat/add: tsv_readers.py
Abusagit 6feed0a
feat/update bloc_reader.py gbff_readers.py
Abusagit 8a12830
feat/add: remove .idea from VCS
Abusagit a94b3b6
feat/fix merge conflicts
Abusagit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,9 @@ __pycache__/ | |
| *.py[cod] | ||
| *$py.class | ||
|
|
||
| # WebStorm | ||
| .idea/ | ||
|
|
||
| # C extensions | ||
| *.so | ||
|
|
||
|
|
||
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| from functools import reduce | ||
|
|
||
|
|
||
| def separate_liquids(glass): | ||
| density_chart = { | ||
| 'H': 1.36, | ||
| 'W': 1.00, | ||
| 'A': 0.87, | ||
| 'O': 0.8 | ||
| } | ||
| height = len(glass) | ||
| width = len(glass[0]) | ||
| overall = height * width | ||
| new_arr = reduce(lambda x, y: x + y, glass, []) # x.extend returns None so it doesn`t work | ||
|
|
||
| for bypass in range(1, overall): | ||
| for i in range(overall - bypass): | ||
| if density_chart[new_arr[i]] > density_chart[new_arr[i + 1]]: | ||
| new_arr[i], new_arr[i + 1] = new_arr[i + 1], new_arr[i] | ||
| return [[new_arr[w + width * h] for w in range(width)] for h in range(height)] | ||
|
|
||
|
|
||
| print(new_arr) | ||
| if __name__ == '__main__': | ||
| example = [ | ||
| ['H', 'H', 'W', 'O'], | ||
| ['W', 'W', 'O', 'W'], | ||
| ['H', 'H', 'O', 'O'], | ||
| ] | ||
| print(separate_liquids(example)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import random | ||
| import sys | ||
|
|
||
| def quickSort(a): | ||
| """ | ||
|
|
||
| :param a: | ||
| :return: sorted a | ||
| """ | ||
| if len(a) < 2: | ||
| return a | ||
| pivot = a[random.randint(0, len(a) - 1)] | ||
| middle = [i for i in a if i == pivot] | ||
| less = [i for i in a if i < pivot] | ||
| # print('less', less) | ||
| greater = [i for i in a if i > pivot] | ||
| # print('greater', greater) | ||
| return quickSort(less) + middle + quickSort(greater) | ||
|
|
||
|
|
||
| def sort_by_name(arr): | ||
| def int_to_string(number): | ||
| nonlocal transition | ||
| if number: | ||
| string = "{} {}" | ||
| hundreds = {0: '', | ||
| 1: "one hundred", | ||
| 2: "two hundred", | ||
| 3: "three hundred", | ||
| 4: "four hundred", | ||
| 5: "five hundred", | ||
| 6: "six hundred", | ||
| 7: "seven hundred", | ||
| 8: "eight hundred", | ||
| 9: "nine hundred" | ||
| } | ||
|
|
||
| numerals = { | ||
| 0: '', | ||
| 1: "one", | ||
| 2: "two", | ||
| 3: "three", | ||
| 4: "four", | ||
| 5: "five", | ||
| 6: "six", | ||
| 7: "seven", | ||
| 8: "eight", | ||
| 9: "nine" | ||
| } | ||
|
|
||
| decimals = { | ||
| 10: "ten", | ||
| 11: "eleven", | ||
| 12: "twelve", | ||
| 13: "thirteen", | ||
| 14: "fourteen", | ||
| 15: "fifteen", | ||
| 16: "sixteen", | ||
| 17: "seventeen", | ||
| 18: "eighteen", | ||
| 19: "nineteen" | ||
| } | ||
|
|
||
| rounds = { | ||
| 20: "twen", | ||
| 30: "thir", | ||
| 40: "for", | ||
| 50: "fif", | ||
| 80: "eigh" | ||
| } | ||
|
|
||
| part_1 = number // 100 | ||
| decimal = number % 100 | ||
|
|
||
| if decimal < 10: | ||
| part_2 = numerals[decimal] | ||
| elif 10 <= decimal < 20: | ||
| part_2 = decimals[decimal] | ||
| else: | ||
| part_2 = f"{rounds.get(decimal - decimal % 10, numerals[(decimal - decimal % 10) // 10])}ty {numerals[decimal % 10]}" | ||
|
|
||
| name = string.format(hundreds[part_1], part_2).strip() | ||
| else: | ||
| name = "zero" | ||
| if name not in transition: | ||
| transition[name] = number | ||
| return name | ||
|
|
||
| transition = {} | ||
|
|
||
| strings = quickSort(list(map(int_to_string, arr))) | ||
|
|
||
| return [transition[number] for number in strings] | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| array = list(map(int, sys.stdin.read().strip().split(", "))) | ||
| print(sort_by_name(array)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| # 1. Sort arrays - 1. https://www.codewars.com/kata/reviews/60926e96b2c8070001711d95/groups/60d0639452c15e0001f67283 | ||
|
|
||
| ```python | ||
| import random | ||
|
|
||
|
|
||
| def sortme(names): | ||
| if len(names) < 2: | ||
| return names | ||
| pivot = names[random.randint(0, len(names) - 1)] | ||
|
|
||
| middle = [i for i in names if i == pivot] | ||
| less = [i for i in names if i < pivot] | ||
| greater = [i for i in names if i > pivot] | ||
|
|
||
| return sortme(less) + middle + sortme(greater) | ||
| ``` | ||
|
|
||
| # 2. Two to One. https://www.codewars.com/kata/5656b6906de340bd1b0000ac | ||
|
|
||
| ```python | ||
| def longest(a1, a2): | ||
| a = list(set(a1) | set(a2)) | ||
|
|
||
| for bypass in range(1, len(a)): | ||
| for k in range(len(a) - bypass): | ||
| if a[k] > a[k + 1]: | ||
| a[k], a[k + 1] = a[k + 1], a[k] | ||
| return ''.join(a) | ||
| ``` | ||
|
|
||
| # 3. Sort - one, three, two. https://www.codewars.com/kata/reviews/5af42785ec2ef4a12c0000b0/groups/60d051f82d6e210001264b2b | ||
|
|
||
| ```python | ||
| import random | ||
|
|
||
| def quickSort(a): | ||
| """ | ||
|
|
||
| :param a: | ||
| :return: sorted a | ||
| """ | ||
| if len(a) < 2: | ||
| return a | ||
| pivot = a[random.randint(0, len(a) - 1)] | ||
| middle = [i for i in a if i == pivot] | ||
| less = [i for i in a if i < pivot] | ||
| # print('less', less) | ||
| greater = [i for i in a if i > pivot] | ||
| # print('greater', greater) | ||
| return quickSort(less) + middle + quickSort(greater) | ||
|
|
||
|
|
||
| def sort_by_name(arr): | ||
| def int_to_string(number): | ||
| nonlocal transition | ||
| if number: | ||
| string = "{} {}" | ||
| hundreds = {0: '', | ||
| 1: "one hundred", | ||
| 2: "two hundred", | ||
| 3: "three hundred", | ||
| 4: "four hundred", | ||
| 5: "five hundred", | ||
| 6: "six hundred", | ||
| 7: "seven hundred", | ||
| 8: "eight hundred", | ||
| 9: "nine hundred" | ||
| } | ||
|
|
||
| numerals = { | ||
| 0: '', | ||
| 1: "one", | ||
| 2: "two", | ||
| 3: "three", | ||
| 4: "four", | ||
| 5: "five", | ||
| 6: "six", | ||
| 7: "seven", | ||
| 8: "eight", | ||
| 9: "nine" | ||
| } | ||
|
|
||
| decimals = { | ||
| 10: "ten", | ||
| 11: "eleven", | ||
| 12: "twelve", | ||
| 13: "thirteen", | ||
| 14: "fourteen", | ||
| 15: "fifteen", | ||
| 16: "sixteen", | ||
| 17: "seventeen", | ||
| 18: "eighteen", | ||
| 19: "nineteen" | ||
| } | ||
|
|
||
| rounds = { | ||
| 20: "twen", | ||
| 30: "thir", | ||
| 40: "for", | ||
| 50: "fif", | ||
| 80: "eigh" | ||
| } | ||
|
|
||
| part_1 = number // 100 | ||
| decimal = number % 100 | ||
|
|
||
| if decimal < 10: | ||
| part_2 = numerals[decimal] | ||
| elif 10 <= decimal < 20: | ||
| part_2 = decimals[decimal] | ||
| else: | ||
| part_2 = f"{rounds.get(decimal - decimal % 10, numerals[(decimal - decimal % 10) // 10])}ty {numerals[decimal % 10]}" | ||
|
|
||
| name = string.format(hundreds[part_1], part_2).strip() | ||
| else: | ||
| name = "zero" | ||
| if name not in transition: | ||
| transition[name] = number | ||
| return name | ||
|
|
||
| transition = {} | ||
|
|
||
| strings = quickSort(list(map(int_to_string, arr))) | ||
|
|
||
| return [transition[number] for number in strings] | ||
| ``` | ||
|
|
||
| # 4. Merge two sorted arrays into one. https://www.codewars.com/kata/reviews/589b9bed66413d26e4000033/groups/60cf8d4d9a9bc1000154b317 | ||
|
|
||
| ```python | ||
| # merge sort practise | ||
| def merge(a1, a2): | ||
| sorted_arr = [None for _ in range(len(a1) + len(a2))] | ||
|
|
||
| i = j = k = 0 | ||
|
|
||
| while i < len(a1) and j < len(a2): | ||
| if a1[i] <= a2[j]: | ||
| sorted_arr[k] = a1[i] | ||
| i += 1 | ||
| else: | ||
| sorted_arr[k] = a2[j] | ||
| j += 1 | ||
| k += 1 | ||
|
|
||
| sorted_arr[k:] = a1[i:] | ||
| k += len(a1) - i | ||
| sorted_arr[k:] = a2[j:] | ||
|
|
||
| return sorted_arr | ||
|
|
||
| def merge_sort(array): | ||
| if len(array) <= 1: | ||
| return array | ||
|
|
||
| middle = len(array) // 2 | ||
| left = merge_sort(array[:middle]) | ||
| right = merge_sort(array[middle:]) | ||
|
|
||
| return merge(left, right) | ||
|
|
||
| def merge_arrays(arr1, arr2): | ||
| array = list(set(arr1) | set(arr2)) | ||
|
|
||
| return merge_sort(array) | ||
| ``` | ||
|
|
||
| # 5. Don't Drink the Water. https://www.codewars.com/kata/reviews/56b26ac972b0b53b4400002e/groups/60d05f092d6e210001264c89 | ||
|
|
||
| ```python | ||
| from functools import reduce | ||
|
|
||
|
|
||
| def separate_liquids(glass): | ||
| if glass: | ||
| density_chart = { | ||
| 'H': 1.36, | ||
| 'W': 1.00, | ||
| 'A': 0.87, | ||
| 'O': 0.8 | ||
| } | ||
| height = len(glass) | ||
| width = len(glass[0]) | ||
| overall = height * width | ||
| new_arr = reduce(lambda x, y: x + y, glass, []) # x.extend returns None so it doesn`t work | ||
|
|
||
| for bypass in range(1, overall): | ||
| for i in range(overall - bypass): | ||
| if density_chart[new_arr[i]] > density_chart[new_arr[i + 1]]: | ||
| new_arr[i], new_arr[i + 1] = new_arr[i + 1], new_arr[i] | ||
| return [[new_arr[w + width * h] for w in range(width)] for h in range(height)] | ||
| return glass | ||
| ``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Удали папку .idea из репозитория, но оставь у себя. Пойми как это сделать.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Мне тогда надо глобальный гитигнор отредаяить?