This repository contains my solutions to algorithmic tasks in Python. Here, I publish solutions to various problems along with tests to verify their correctness. The purpose of this repository is to showcase my approach to problem-solving and demonstrate my programming skills.
Tasks are organized into folders, each containing:
- Task description (
task.md) - Solution to the task (
solution.py) - Tests to verify the solution (
test_solution.py)
-
- Task: Check if a sequence is continuous without any number gaps.
- Solution: The
is_continuous_sequencefunction verifies whether the sequence is increasing and continuous. - Tests: Verifying the correctness of the solution through various test cases.
-
- Task: Find the length of the longest substring without repeating elements.
- Solution: The
find_longest_lengthfunction returns the length of the longest sequence of non-repeating characters. - Tests: Verifying the correctness of the solution through various test cases.
-
- Task: Write a function that returns a specified row of Pascal's triangle as a list.
- Solution: The
trianglefunction returns a specified row of Pascal's triangle as a list. - Tests: Verifying the correctness of the solution through various test cases.
-
- Task: Write a function that should accept a matrix as a list of lists and return the transposed matrix (a new list of lists).
- Solution: The
transposedfunction returns the transposed matrix. - Tests: Verifying the correctness of the solution through various test cases.
-
- Task: Write a function that takes a list of intervals as input and returns the sum of all non-intersecting interval lengths.
- Solution: The
sum_of_intervalsfunction returns the transposed sum of all non-intersecting interval lengths. - Tests: Verifying the correctness of the solution through various test cases.
-
- Task: Write a function that which returns the length of the last word of the string passed to the input
- Solution: The
length_of_last_wordfunction returns the length of the last word. - Tests: Verifying the correctness of the solution through various test cases.
-
- Task: Write a function which returns a list consisting of chunks of the specified size.
- Solution: The
chunkedfunction returns a list of chunks of the specified size. - Tests: Verifying the correctness of the solution through various test cases.
-
- Task: Write a function which calculates the Hamming weight of an integer.
- Solution: The
hamming_weightfunction returns the Hamming weight. - Tests: Verifying the correctness of the solution through various test cases.
-
- Task: Write a function that takes a list which contains a number or an operator and return the result of the calculation using reverse Polish notation.
- Solution: The
rpn_calcfunction. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Write a function that takes an image as a two-dimensional list of strings and enlarges it by a factor of two, that is, doubles each character horizontally and vertically.
- Solution: The
enlargefunction. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Write a function which compares the passed versions version1 AND version2. If version1 › version2, then the function should return 1, if version1 ‹ version2, TO -1, if version1 = version2 — 0.
- Solution: The
compare_versionfunction. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Write a function that finds contiguous increasing sequences of numbers in a list and returns a list listing them.
- Solution: The
summary_rangesfunction. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Write a function that returns an iterator of lists of a given length containing elements from the data source.
- Solution: The
ichunksfunction. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Write a function that takes a two-dimensional list (matrix) and modifies it so that the right half of the matrix becomes a mirror copy of the left half, symmetrical about the vertical axis of the matrix.
- Solution: The
mirror_matrixfunction. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Write a function that takes a matrix as input and returns a list of matrix elements in clockwise order from the top-left element to the innermost element.
- Solution: The
snail_pathfunction. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Write a multiply function that takes two matrices and returns a new matrix that is the product of them.
- Solution: The
multiplyfunction. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Write a multiply function that counts how many coins of each denomination are in the piggy bank and displays the result as a graph.
- Solution: The
visualizefunction. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Implement a function to_rna that takes a DNA strand as input and returns the corresponding RNA strand (transcribes the RNA).
- Solution: The
to_rnafunction. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Implement a function that takes a dictionary of parameters as input and returns a query string formed from these parameters.
- Solution: The
build_query_stringfunction. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Implement a to_roman() function that converts Arabic numerals to Roman numerals.
- Solution: The
to_romanfunction. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Implement a to_roman() function that converts Arabic numerals to Roman numerals.
- Solution: The
to_arabicfunction. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Implement a find_where function that takes a list of books and a search query as input and returns the first book that matches the query.
- Solution: The
find_wherefunction. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Implement a scrabble predicate function that takes two parameters: a set of characters (a string) and a word, and checks whether the given set can be used to create the word.
- Solution: The
scrabblefunction. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Implement a function merged that merges multiple dictionaries into a single dictionary.
- Solution: The
scrabblefunction. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Implement a gen_diff function that compares two dictionaries and returns the result of the comparison as a dictionary.
- Solution: The
gen_difffunction. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Implement a function called compose that takes two other one-argument functions as input and returns a new function.
- Solution: The
composefunction. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Implement a decode function that takes a string as a graphical representation of a linear signal and returns a string with binary code.
- Solution: The
decodefunction. - Tests: Verifying the correctness of the solution through various test cases.
- Task:Implement a function same_parity_filter that takes a list as input and returns a new list consisting of elements that have the same parity as the first element of the original list.
- Solution: The
same_parity_filterfunction. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Create a decorator that checks the types of arguments according to their annotations and returns TypeError, if needed.
- Solution: The
typecheckfunction. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Create a decorator that checks the argument types according to their arguments' annotations. The decorator should check all arguments, accumulating errors, and only then stop execution if there were errors. The previously written typecheck decorator should be used in the implementation of this decorator.
- Solution: The
typecheck_allfunction. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Implement two decorators that form a small DSL that allows you to turn regular functions into interactive programs.
- Solution: The
interactive_functionmodule. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Implement and export the ip2int and int2ip functions, which convert the dotted-decimal representation of an IP address to a 32-bit dotted-decimal number and back.
- Solution: The
ip2int and int2ipfunctions. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Implement a function called enlarge in functional style that enlarges the passed "image" by a factor of two: each "pixel" is doubled horizontally and vertically. The image is a list of strings, and the pixels in it are the characters of the strings.
- Solution: The
enlarge2function. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Implement a function rgb2hex that converts colors to the corresponding representation.
- Solution: The
rgb2hexfunction. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Implement the find_index_of_nearest function that takes a list of numbers and the desired number as input. The function's task is to find the closest number to the desired number in the list and return its index.
- Solution: The
find_index_of_nearestfunction. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Implement a function filter_anagrams that finds all anagram words. The function takes a source word and an iterable of words to check, and returns a sequence of anagrams.
- Solution: The
filter_anagramsfunction. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Implement a histo function that takes a list or tuple of numbers as input and returns a histogram as a string, with the histogram columns separated by \n characters. Each column displays the number of occurrences of a number in the list: graphically using the specified characters and as a numeric value, except when the count is zero.
- Solution: The
histofunction. - Tests: Verifying the correctness of the solution through various test cases.
- Task: Implement the predicate function is_valid_ipv6, which checks IPv6 (Internet Protocol version 6) addresses for validity. The function takes a string with an IPv address as input and returns True if the address is valid and False otherwise.
- Solution: The
is_valid_iрv6function. - Tests: Verifying the correctness of the solution through various test cases.
-
Clone the repository to your machine:
git clone https://github.com/iamsashason/coding-tasks.git. -
Go to the tasks directory:
cd coding-tasks/tasks/is_continuous_sequence. -
Make sure you have Python 3 installed. You can check the Python version with the command:
python3 --version. If Python 3 is not installed, download it from the official Python website. -
Run the tests with unittest:
python3 -m unittest test_solution.py.
- Feel free to reach out to me through my GitHub Profile.
- For inquiries, you can email me at: svshvson@icloud.com.
- Telegram