diff --git a/python/src/codewars.py b/python/src/codewars.py new file mode 100644 index 0000000..ddb3225 --- /dev/null +++ b/python/src/codewars.py @@ -0,0 +1,51 @@ +# Evenor Odd +def even_or_odd(number): + if (number % 2) != 0: + return "Odd" + return "Even" + + +# Counting sheep... +def count_sheeps(sheep): + return sheep.count(True) + + +# Count the Monkeys! +def monkey_count(n): + result = [] + for num in range(1, n + 1): + result.append(num) + return result + + +# Beginner Series #1 School Paperwork +def paperwork(n, m): + if n < 0 or m < 0: + return 0 + else: + return n * m + + +# Is he gonna survive? +def hero(bullets, dragons): + return bullets >= (2 * dragons) + + +# Polish alphabet +def correct_polish_letters(st): + pol = pol = {"ą": "a", "ć": "c", "ę": "e", "ł": "l", "ń": "n", "ó": "o", "ś": "s", "ź": "z", "ż": "z"} + return "".join([pol[c] if c in pol else c for c in st]) + + +# Sum of Minimums! +def sum_of_minimums(numbers): + return sum(map(min, numbers)) + + +# Find all occurrences of an element in an array +def find_all(array, n): + indices = [] + for i in range(len(array)): + if array[i] == n: + indices.append(i) + return indices diff --git a/python/src/main.py b/python/src/main.py index e37a77c..29e99a5 100644 --- a/python/src/main.py +++ b/python/src/main.py @@ -1,7 +1,41 @@ -def summ(a: int, b: int) -> int: - return a + b +import math +from codewars import find_all, even_or_odd, correct_polish_letters, count_sheeps, monkey_count, hero, paperwork, sum_of_minimums +print(even_or_odd(2)) +print(count_sheeps([True, True, True, False, + True, True, True, True, + True, False, True, False, + True, False, False, True, + True, True, True, True, + False, False, True, True])) +print(monkey_count(5)) +print(paperwork(10, 10)) +print(hero(20, 5)) +print(correct_polish_letters("Jędrzej Błądziński")) +print(sum_of_minimums([[7, 9, 8, 6, 2], [6, 3, 5, 4, 3], [5, 8, 7, 4, 5]])) +print(find_all([6, 9, 3, 4, 3, 82, 11], 3)) -if __name__ == "__main__": - print("Hello world") - print(summ(3, 4)) +def frange(start, stop, step): + + i = start + while i < stop: + yield i + i += step + + +def y(x): + y = (a**(x**2) - 1) - math.log10((x**2) - 1) + pow((x ** 2) - 1, 1 / 3) + return y + + +for x in frange(1.2, 3.7, 0.5): + a = 1.6 + print(y(x)) + + +xrange = [1.28, 1.36, 2.47, 3.68, 4.56] +xlen = len(xrange) +for i in range(0, xlen): + x = xrange[i] + a = 1.6 + print(y(x))