Skip to content

math lab + lint fix #88

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
wants to merge 4 commits into
base: Mahotina_Valerija_Olegovna
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions codewars/Adding Big Numbers/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function add(num1, num2) {
num1 = num1.split('').reverse().join('');
num2 = num2.split('').reverse().join('');

let result = '';
let carry = 0;
let maxLength = Math.max(num1.length, num2.length);

for (let i = 0; i < maxLength; i++) {
let digit1 = i < num1.length ? parseInt(num1[i]) : 0;
let digit2 = i < num2.length ? parseInt(num2[i]) : 0;

let sum = digit1 + digit2 + carry;

carry = Math.floor(sum / 10);
result += (sum % 10).toString();
}

if (carry > 0) {
result += carry.toString();
}

return result.split('').reverse().join('');
}
14 changes: 14 additions & 0 deletions codewars/Anagram difference/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from collections import Counter

def anagram_difference(word1, word2):
count1 = Counter(word1)
count2 = Counter(word2)

remove_count = 0

all_letters = set(count1.keys()).union(set(count2.keys()))

for letter in all_letters:
remove_count += abs(count1.get(letter, 0) - count2.get(letter, 0))

return remove_count
6 changes: 6 additions & 0 deletions codewars/Array Deep Count/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def deep_count(arr):
count = len(arr)
for element in arr:
if isinstance(element, list):
count += deep_count(element)
return count
10 changes: 10 additions & 0 deletions codewars/Build Tower/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def tower_builder(n_floors):
max_width = 2 * n_floors - 1
tower = []
for i in range(n_floors):
num_stars = 2 * i + 1
num_spaces = (max_width - num_stars) // 2
floor_string = ' ' * num_spaces + '*' * num_stars + ' ' * num_spaces
tower.append(floor_string)

return tower
6 changes: 6 additions & 0 deletions codewars/Convert string to camel case/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import re

def to_camel_case(s):
words = re.split('[-_]', s)
camel_case = words[0] + ''.join(word.capitalize() for word in words[1:])
return camel_case
12 changes: 12 additions & 0 deletions codewars/Duplicate Encoder/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def duplicate_encode(word):
normalized_word = word.lower()
char_count = {}
for char in normalized_word:
char_count[char] = char_count.get(char, 0) + 1
encoded_string = ''
for char in normalized_word:
if char_count[char] == 1:
encoded_string += '('
else:
encoded_string += ')'
return encoded_string
5 changes: 5 additions & 0 deletions codewars/Find the missing letter/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def find_missing_letter(char_array):
start = ord(char_array[0])
for i in range(len(char_array)):
if ord(char_array[i]) != start + i:
return chr(start + i)
13 changes: 13 additions & 0 deletions codewars/Flatten a Nested Map/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function flattenMap(map, parentKey = '', result = {}) {
for (let key in map) {
if (map.hasOwnProperty(key)) {
const newKey = parentKey ? `${parentKey}/${key}` : key;
if (typeof map[key] === 'object' && map[key] !== null && !Array.isArray(map[key])) {
flattenMap(map[key], newKey, result);
} else {
result[newKey] = map[key];
}
}
}
return result;
}
30 changes: 30 additions & 0 deletions codewars/Fun with tree - max sum/.gitkeep
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
class TreeNode {
constructor(value, left = null, right = null) {
this.value = value;
this.left = left;
this.right = right;
}
}

function maxSum(root) {
if (!root) {
return 0;
}

function helper(node) {
if (!node) {
return Number.NEGATIVE_INFINITY;
}

if (!node.left && !node.right) {
return node.value;
}

const leftSum = helper(node.left);
const rightSum = helper(node.right);


return Math.max(leftSum, rightSum) + node.value;
}

return helper(root);
}
26 changes: 26 additions & 0 deletions codewars/Linked Lists - Sorted Insert/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Node:
def __init__(self, data):
self.data = data
self.next = None

def sorted_insert(head, data):
if head is None:
return Node(data)
if data < head.data:
new_head = Node(data)
new_head.next = head
return new_head
current_node = head
while current_node.next is not None and current_node.next.data < data:
current_node = current_node.next
insert = Node(data)
insert.next = current_node.next
current_node.next = insert
return head

def print_list(head):
current = head
while current:
print(current.data, end=" -> ")
current = current.next
print("null")
19 changes: 19 additions & 0 deletions codewars/Merge two arrays/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function mergeArrays(a, b) {
const result = [];
const length1 = a.length;
const length2 = b.length;
const minLength = Math.min(length1, length2);

for (let i = 0; i < minLength; i++) {
result.push(a[i]);
result.push(b[i]);
}

if (length1 > minLength) {
result.push(...a.slice(minLength));
} else if (length2 > minLength) {
result.push(...b.slice(minLength));
}

return result;
}
10 changes: 10 additions & 0 deletions codewars/Moving Zeros To The End/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def move_zeros(arr):
result = []
zero_count = 0
for num in arr:
if num != 0:
result.append(num)
else:
zero_count += 1
result.extend([0] * zero_count)
return result
6 changes: 6 additions & 0 deletions codewars/Permutations/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from itertools import permutations as perm

def permutations(s):
perms = perm(s)
unique_perms = set(''.join(p) for p in perms)
return list(unique_perms)
8 changes: 8 additions & 0 deletions codewars/Product of consecutive Fib numbers/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def product_fib(_prod):
a, b = 0, 1
while a * b < _prod:
a, b = b, a + b
if a * b == _prod:
return [a, b, True]
else:
return [a, b, False]
11 changes: 11 additions & 0 deletions codewars/Simple Pig Latin/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def pig_it(text):
words = text.split()
result = []
for word in words:
if word.isalpha():
new_word = word[1:] + word[0] + "ay"
result.append(new_word)
else:
result.append(word)

return ' '.join(result)
27 changes: 27 additions & 0 deletions codewars/Snail/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
def snail(snail_map):
pass
if not snail_map or not snail_map[0]:
return []
result = []
top, bottom = 0, len(snail_map) - 1
left, right = 0, len(snail_map[0]) - 1

while top <= bottom and left <= right:
for i in range(left, right + 1):
result.append(snail_map[top][i])
top += 1
for i in range(top, bottom + 1):
result.append(snail_map[i][right])
right -= 1

if top <= bottom:
for i in range(right, left - 1, -1):
result.append(snail_map[bottom][i])
bottom -= 1

if left <= right:
for i in range(bottom, top - 1, -1):
result.append(snail_map[i][left])
left += 1

return result
4 changes: 4 additions & 0 deletions codewars/Sum of Digits - Digital Root/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def digital_root(n):
if n == 0:
return 0
return 1 + (n - 1) % 9
16 changes: 16 additions & 0 deletions codewars/Sum of Intervals/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function sumIntervals(intervals) {
intervals.sort((a, b) => a[0] - b[0]);
let merged = [];
for (let interval of intervals) {
if (merged.length === 0 || merged[merged.length - 1][1] < interval[0]) {
merged.push(interval);
} else {
merged[merged.length - 1][1] = Math.max(merged[merged.length - 1][1], interval[1]);
}
}
let totalLength = 0;
for (let interval of merged) {
totalLength += interval[1] - interval[0];
}
return totalLength;
}
9 changes: 9 additions & 0 deletions codewars/Sum of pairs/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def sum_pairs(ints, s):
seen = {}

for index, number in enumerate(ints):
complement = s - number
if complement in seen:
return [complement, number]
seen[number] = index
return None
22 changes: 22 additions & 0 deletions codewars/Tic-Tac-Toe Checker/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
def is_solved(board):
pass
winning_combinations = [
[board[0][0], board[0][1], board[0][2]],
[board[1][0], board[1][1], board[1][2]],
[board[2][0], board[2][1], board[2][2]],
[board[0][0], board[1][0], board[2][0]],
[board[0][1], board[1][1], board[2][1]],
[board[0][2], board[1][2], board[2][2]],
[board[0][0], board[1][1], board[2][2]],
[board[0][2], board[1][1], board[2][0]],
]

for combination in winning_combinations:
if combination == [1, 1, 1]:
return 1
elif combination == [2, 2, 2]:
return 2
for row in board:
if 0 in row:
return -1
return 0
12 changes: 12 additions & 0 deletions codewars/Valid Parentheses/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def valid_parentheses(string):
stack = []

for char in string:
if char == '(':
stack.append(char)
elif char == ')':
if not stack:
return False
stack.pop()

return len(stack) == 0
4 changes: 4 additions & 0 deletions codewars/Where my anagrams at/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def anagrams(word, words):
pass
sorted_word = sorted(word)
return [w for w in words if sorted(w) == sorted_word]
Loading
Loading