Skip to content

Repository with solutions to algorithmic tasks in Python by Sasha Son as part of learning Python programming

Notifications You must be signed in to change notification settings

iamsashason/coding-tasks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 

Repository files navigation

Coding Tasks Collection

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.

Repository Structure

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)

Content (in progress)

  1. is_continuous_sequence

    • Task: Check if a sequence is continuous without any number gaps.
    • Solution: The is_continuous_sequence function verifies whether the sequence is increasing and continuous.
    • Tests: Verifying the correctness of the solution through various test cases.
  2. find_longest_length

    • Task: Find the length of the longest substring without repeating elements.
    • Solution: The find_longest_length function returns the length of the longest sequence of non-repeating characters.
    • Tests: Verifying the correctness of the solution through various test cases.
  3. triangle

    • Task: Write a function that returns a specified row of Pascal's triangle as a list.
    • Solution: The triangle function returns a specified row of Pascal's triangle as a list.
    • Tests: Verifying the correctness of the solution through various test cases.
  4. transposed

    • 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 transposed function returns the transposed matrix.
    • Tests: Verifying the correctness of the solution through various test cases.
  5. sum_of_intervals

    • 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_intervals function returns the transposed sum of all non-intersecting interval lengths.
    • Tests: Verifying the correctness of the solution through various test cases.
  6. length_of_last_word

    • 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_word function returns the length of the last word.
    • Tests: Verifying the correctness of the solution through various test cases.
  7. chunked

    • Task: Write a function which returns a list consisting of chunks of the specified size.
    • Solution: The chunked function returns a list of chunks of the specified size.
    • Tests: Verifying the correctness of the solution through various test cases.
  8. hamming_weight

    • Task: Write a function which calculates the Hamming weight of an integer.
    • Solution: The hamming_weight function returns the Hamming weight.
    • Tests: Verifying the correctness of the solution through various test cases.
  9. rpn_calc

    • 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_calc function.
    • Tests: Verifying the correctness of the solution through various test cases.
  10. enlarge

  • 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 enlarge function.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. compare_verison
  • 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_version function.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. summary_ranges
  • Task: Write a function that finds contiguous increasing sequences of numbers in a list and returns a list listing them.
  • Solution: The summary_ranges function.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. ichunks
  • Task: Write a function that returns an iterator of lists of a given length containing elements from the data source.
  • Solution: The ichunks function.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. mirror_matrix
  • 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_matrix function.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. snail_path
  • 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_path function.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. multiply
  • Task: Write a multiply function that takes two matrices and returns a new matrix that is the product of them.
  • Solution: The multiply function.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. visualize
  • 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 visualize function.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. to_rna
  • 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_rna function.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. build_query_string
  • 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_string function.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. to_roman
  • Task: Implement a to_roman() function that converts Arabic numerals to Roman numerals.
  • Solution: The to_roman function.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. to_arabic
  • Task: Implement a to_roman() function that converts Arabic numerals to Roman numerals.
  • Solution: The to_arabic function.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. find_where
  • 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_where function.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. scrabble
  • 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 scrabble function.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. merged
  • Task: Implement a function merged that merges multiple dictionaries into a single dictionary.
  • Solution: The scrabble function.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. gen_diff
  • Task: Implement a gen_diff function that compares two dictionaries and returns the result of the comparison as a dictionary.
  • Solution: The gen_diff function.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. compose
  • Task: Implement a function called compose that takes two other one-argument functions as input and returns a new function.
  • Solution: The compose function.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. decode
  • 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 decode function.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. same_parity_filter
  • 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_filter function.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. typecheck
  • Task: Create a decorator that checks the types of arguments according to their annotations and returns TypeError, if needed.
  • Solution: The typecheck function.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. typecheck_all
  • 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_all function.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. interactive_function
  • Task: Implement two decorators that form a small DSL that allows you to turn regular functions into interactive programs.
  • Solution: The interactive_function module.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. ip2int and int2ip
  • 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 int2ip functions.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. enlarge2
  • 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 enlarge2 function.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. rgb2hex
  • Task: Implement a function rgb2hex that converts colors to the corresponding representation.
  • Solution: The rgb2hex function.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. find_index_of_nearest
  • 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_nearest function.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. filter_anagrams
  • 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_anagrams function.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. histo
  • 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 histo function.
  • Tests: Verifying the correctness of the solution through various test cases.
  1. is_valid_iрv6
  • 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рv6 function.
  • Tests: Verifying the correctness of the solution through various test cases.

Installation and Running Tests

  1. Clone the repository to your machine: git clone https://github.com/iamsashason/coding-tasks.git.

  2. Go to the tasks directory: cd coding-tasks/tasks/is_continuous_sequence.

  3. 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.

  4. Run the tests with unittest: python3 -m unittest test_solution.py.

Contact information

  1. Feel free to reach out to me through my GitHub Profile.
  2. For inquiries, you can email me at: svshvson@icloud.com.
  3. Telegram
  4. Instagram

About

Repository with solutions to algorithmic tasks in Python by Sasha Son as part of learning Python programming

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages