Skip to content
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

lint_fix #81

Open
wants to merge 3 commits into
base: Kostina_Polina_Alekseevna
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
28 changes: 28 additions & 0 deletions codewars/Adding Big Numbers/15.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function add(a, b) {
a = a.replace(/^0+/, '');
b = b.replace(/^0+/, '');

if (a === '') a = '0';
if (b === '') b = '0';

a = a.split('').reverse().join('');
b = b.split('').reverse().join('');

let result = [];
let carry = 0;

for (let i = 0; i < Math.max(a.length, b.length); i++) {
let digitA = i < a.length ? parseInt(a[i]) : 0;
let digitB = i < b.length ? parseInt(b[i]) : 0;

let sum = digitA + digitB + carry;
carry = Math.floor(sum / 10);
result.push(sum % 10);
}

if (carry > 0) {
result.push(carry);
}

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


def anagram_difference(w1, w2):
count1 = Counter(w1)
count2 = Counter(w2)

remove_count = 0

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

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

return remove_count
10 changes: 10 additions & 0 deletions codewars/Array Deep Count/7.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def deep_count(a):
count = 0

for element in a:
if isinstance(element, list):
count += deep_count(element) + 1
else:
count += 1

return count
11 changes: 11 additions & 0 deletions codewars/Build Tower/6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def tower_builder(n_floors):
tower = []
max_width = 2 * n_floors - 1

for i in range(n_floors):
stars = 2 * i + 1
spaces = (max_width - stars) // 2
floor = ' ' * spaces + '*' * stars + ' ' * spaces
tower.append(floor)

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


def to_camel_case(text):
if not text:
return ""
words = re.split(r'[-_]', text)

if words:
if text[0].isupper():
words[0] = words[0].capitalize()
else:
words[0] = words[0].lower()

camel_case_words = [words[0]] + \
[word.capitalize() for word in words[1:]]

return ''.join(camel_case_words)
18 changes: 18 additions & 0 deletions codewars/Duplicate Encoder/1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def duplicate_encode(word):
word = word.lower()

frequency = {}
for char in word:
if char in frequency:
frequency[char] += 1
else:
frequency[char] = 1

result = ""
for char in word:
if frequency[char] == 1:
result += "("
else:
result += ")"

return result
7 changes: 7 additions & 0 deletions codewars/Find the missing letter/2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def find_missing_letter(chars):
for i in range(len(chars) - 1):
current_char = ord(chars[i])
next_char = ord(chars[i + 1])

if next_char != current_char + 1:
return chr(current_char + 1)
18 changes: 18 additions & 0 deletions codewars/Flatten a Nested Map/9.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function flattenMap(map, parentKey = '', sep = '/') {
const result = {};

for (const key in map) {
if (map.hasOwnProperty(key)) {
const newKey = parentKey ? `${parentKey}${sep}${key}` : key;
const value = map[key];

if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
Object.assign(result, flattenMap(value, newKey, sep));
} else {
result[newKey] = value;
}
}
}

return result;
}
18 changes: 18 additions & 0 deletions codewars/Fun with tree - max sum/18.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class TreeNode:
def __init__(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right


def max_sum(root: TreeNode) -> int:
if root is None:
return 0

if root.left is None and root.right is None:
return root.value

left_sum = max_sum(root.left) if root.left else float('-inf')
right_sum = max_sum(root.right) if root.right else float('-inf')

return root.value + max(left_sum, right_sum)
21 changes: 21 additions & 0 deletions codewars/Linked Lists - Sorted Insert/19.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Node(object):
def __init__(self, data):
self.data = data
self.next = None


def sorted_insert(head, data):
new_node = Node(data)

if head is None or data < head.data:
new_node.next = head
return new_node

current = head
while current.next is not None and current.next.data < data:
current = current.next

new_node.next = current.next
current.next = new_node

return head
15 changes: 15 additions & 0 deletions codewars/Merge two arrays/.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function mergeArrays(a, b) {
let result = [];
let maxLength = Math.max(a.length, b.length);

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

return result;
}
10 changes: 10 additions & 0 deletions codewars/Moving Zeros To The End/3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def move_zeros(lst):
a = []
count = 0
for i in lst:
if i != 0:
a.append(i)
else:
count += 1
a.extend([0]*count)
return a
10 changes: 10 additions & 0 deletions codewars/Permutations/8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def deep_count(a):
count = 0

for element in a:
if isinstance(element, list):
count += deep_count(element) + 1
else:
count += 1

return count
9 changes: 9 additions & 0 deletions codewars/Product of consecutive Fib numbers/13.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def product_fib(prod):
a, b = 0, 1

while a * b <= prod:
if a * b == prod:
return [a, b, True]
a, b = b, a + b

return [a, b, False]
12 changes: 12 additions & 0 deletions codewars/Simple Pig Latin/16.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def pig_it(text):
words = text.split()

changed_words = []
for word in words:
if word.isalpha():
changed_word = word[1:] + word[0] + 'ay'
changed_words.append(changed_word)
else:
changed_words.append(word)

return ' '.join(changed_words)
28 changes: 28 additions & 0 deletions codewars/Snail/14.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
def snail(snail_map):
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/5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def digital_root(n):
while n >= 10:
n = sum(int(digit) for digit in str(n))
return n
19 changes: 19 additions & 0 deletions codewars/Sum of Intervals/10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def sum_of_intervals(intervals):
if not intervals:
return 0

intervals.sort(key=lambda x: x[0])
merged_intervals = []
current_start, current_end = intervals[0]

for start, end in intervals[1:]:
if start <= current_end:
current_end = max(current_end, end)
else:
merged_intervals.append((current_start, current_end))
current_start, current_end = start, end

merged_intervals.append((current_start, current_end))
total_length = sum(end - start for start, end in merged_intervals)

return total_length
8 changes: 8 additions & 0 deletions codewars/Sum of pairs/12.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def sum_pairs(ints, s):
seen = set()
for num in ints:
complement = s - num
if complement in seen:
return [complement, num]
seen.add(num)
return None
17 changes: 17 additions & 0 deletions codewars/Tic-Tac-Toe Checker/20.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def is_solved(board):
for i in range(3):
if board[i][0] == board[i][1] == board[i][2] != 0:
return board[i][0]
if board[0][i] == board[1][i] == board[2][i] != 0:
return board[0][i]

if board[0][0] == board[1][1] == board[2][2] != 0:
return board[0][0]
if board[0][2] == board[1][1] == board[2][0] != 0:
return board[0][2]

for row in board:
if 0 in row:
return -1

return 0
Loading
Loading