diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..a00cee1 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,18 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.0 + hooks: + - id: ruff # Linting + + - repo: https://github.com/psf/black + rev: stable + hooks: + - id: black # formatting diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/caesar_cipher_helper b/src/caesar_cipher_helper new file mode 100644 index 0000000..2ba5dfb --- /dev/null +++ b/src/caesar_cipher_helper @@ -0,0 +1,39 @@ +""" +Lösung des Katas: Caesar Cipher Helper +Link: https://www.codewars.com/kata/526d42b6526963598d0004db +""" + + +beginning_alphabet = ord("A") +ending_alphabet = ord("Z") + +class CaesarCipher(object): + def __init__(self, offset): + self.offset = offset + + def encode(self, st): + upper = st.upper() + encoded_st = "" + for char in upper: + if beginning_alphabet <= ord(char) <= ending_alphabet: + encoded_char = (ord(char) + self.offset) + if encoded_char > ending_alphabet: + encoded_char -= (ending_alphabet - (beginning_alphabet - 1)) + encoded_st += chr(encoded_char) + else: + encoded_st += char + + return encoded_st + + def decode(self, st): + decoded_st = "" + for char in st: + if beginning_alphabet <= ord(char) <= ending_alphabet: + decoded_char = (ord(char) - self.offset) + if decoded_char < beginning_alphabet: + decoded_char += (ending_alphabet - (beginning_alphabet - 1)) + decoded_st += chr(decoded_char) + else: + decoded_st += char + + return decoded_st diff --git a/src/kata_mean_square_error.py b/src/kata_mean_square_error.py new file mode 100644 index 0000000..fa179f6 --- /dev/null +++ b/src/kata_mean_square_error.py @@ -0,0 +1,13 @@ +""" +Lösung des Katas: Mean Square Error von kylehill +Link zum Kata: https://www.codewars.com/kata/51edd51599a189fe7f000015 + +""" + + +def solution(array_a, array_b): + numbers_list = list(zip(array_a, array_b)) + differences = [x[0] - x[1] for x in numbers_list] + mean_square_error = sum([x * x for x in differences]) / len(differences) + + return mean_square_error diff --git a/src/moduleA.py b/src/moduleA.py new file mode 100644 index 0000000..b7f0906 --- /dev/null +++ b/src/moduleA.py @@ -0,0 +1,10 @@ +def addition(a=1, b=2): + return a + b + + +def f(x: int, y: int) -> int: + return x + y + + +if __name__ == "__main__": + print(addition(5, 5)) diff --git a/tests/test_moduleA.py b/tests/test_moduleA.py new file mode 100644 index 0000000..42fe6cc --- /dev/null +++ b/tests/test_moduleA.py @@ -0,0 +1,6 @@ +from src.moduleA import addition + + +def test_a(): + assert addition() == 3 + assert addition(5, 5) == 10