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

feat: math func lab + codewars #49

Open
wants to merge 7 commits into
base: Habibulina_Alina_Mihajlovna
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 adding(a, b) {
while (a.length < b.length) {
a = '0' + a;
}

while (b.length < a.length) {
b = '0' + b;
}

let bigNumber = 0;
let result = '';

for (let i = a.length - 1; i >= 0; i--) {
const summ = parseInt(a[i]) + parseInt(b[i]) + bigNumber;
result = (summ % 10) + result;
bigNumber = Math.floor(summ / 10);
}

if (bigNumber > 0) {
result = bigNumber + result;
}

return result;
}
15 changes: 15 additions & 0 deletions codewars/Anagram difference/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def anagramDifference(w1, w2):
number_w1 = [0] * 26
number_w2 = [0] * 26
removedSymbols = 0
for symbol in w1:
number_w1[ord(symbol) - ord('a')] += 1
for symbol in w2:
number_w2[ord(symbol) - ord('a')] += 1
for i in range(26):
removedSymbols += abs(number_w1[i] - number_w2[i])

return removedSymbols

if __name__ == "__main__":
print(anagramDifference(input(), input()))
11 changes: 11 additions & 0 deletions codewars/Array Deep Count/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def deepСount(a):
summ = 0
for elements in a:
summ += 1
if isinstance(elements, list) == True:
summ += deepСount(elements)

return summ

if __name__ == "__main__":
print(deepСount(list(input())))
14 changes: 14 additions & 0 deletions codewars/Build Tower/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def builder(floors):
tower = list()
for i in range(floors):
if i == 0:
towerSector = (" " * (floors - 1)) + "*" + (" " * (floors - 1))
tower.append(towerSector)
else:
towerSector = (" " * (floors - 1 - i)) + ("*" * (1 + (i * 2))) + (" " * (floors - 1 - i))
tower.append(towerSector)

return tower

if __name__ == '__main__':
print(builder(int(input())))
10 changes: 10 additions & 0 deletions codewars/Convert string to camel case/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def camelCase(text):
line = text.replace("_", " ").replace("-", " ")
line = line.split()
if len(text) == 0:
return text

return line[0] + ''.join(i.capitalize() for i in line[1:])

if __name__ == '__main__':
print(camelCase(input()))
14 changes: 14 additions & 0 deletions codewars/Duplicate Encoder/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function duplicateEncode(word){
word = word.toLowerCase();
const deathSymbol = {};
for (const death of word) {
deathSymbol[death] = (deathSymbol[death] || 0) + 1;
}

let result = "";
for (const death of word) {
result += deathSymbol[death] === 1 ? "(" : ")";
}

return result;
}
10 changes: 10 additions & 0 deletions codewars/Find the missing letter/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def findLetter(symbols):
missing_char = ""
for i in range(len(symbols) - 1):
if ord(symbols[i]) + 1 != ord(symbols[i + 1]):
missing_char = chr(ord(symbols[i]) + 1)

return missing_char

if __name__ == '__main__':
print(findLetter(input()))
14 changes: 14 additions & 0 deletions codewars/Flatten a Nested Map/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function flattenMap(map, path = "", result = {}) {
Object.entries(map).forEach(([key, value]) => {
const route = path ? `${path}/${key}` : key;
const object = value !== null && typeof value === "object" && !Array.isArray(value);

if (object) {
flattenMap(value, route, result);
} else {
result[route] = value;
}
});

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

def maxSumm(root:TreeNode) -> int:
if root is None:
return 0
def maxPath(node, current_summ):
if node is None:
return float('-inf')
current_summ += node.value
if node.left is None and node.right is None:
return current_summ
leftS = maxPath(node.left, current_summ)
rightS = maxPath(node.right, current_summ)
return max(leftS, rightS)

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

def sorted(death, data):
death = Node(data)

if death is None or death.data >= death.data:
death.next = death
return death
actual = death

while actual.next is not None and actual.next.data < death.data:
actual = actual.next
death.next = actual.next
actual.next = death

return death
12 changes: 12 additions & 0 deletions codewars/Merge two arrays/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function mergeArrays(a, b) {
let res = [];
const lengthMin = Math.min(a.length, b.length);

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

res = res.concat(a.length > b.length ? a.slice(lengthMin) : b.slice(lengthMin));
return res;
}
13 changes: 13 additions & 0 deletions codewars/Moving Zeros To The End/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def movingZeros(list):
finalList = list()
for el in list:
if el != 0:
finalList.append(el)

while len(finalList) < len(list):
finalList.append(0)

return finalList

if __name__ == "__main__":
print(movingZeros(input()))
8 changes: 8 additions & 0 deletions codewars/Permutations/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import itertools

def permutations(string):
if len(string)<2: return [string]
else: return sorted(list({''.join(x) for x in itertools.permutations(string)}))

if __name__ == "__main__":
print(permutations(input()))
20 changes: 20 additions & 0 deletions codewars/Product of consecutive Fib numbers/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def productNumber(product):
if product == 0:
return [0, 1, True]
number_1 = 0
number_2 = 1

while True:
if number_2 > number_1:
number_1 += number_2
else:
number_2 += number_1

if number_1 * number_2 == product:
return [number_1, number_2, True] if number_1 < number_2 else [number_2, number_1, True]

elif number_1 * number_2 > product:
return [number_1, number_2, False] if number_1 < number_2 else [number_2, number_1, False]

if __name__ == "__main__":
print(productNumber(int(input())))
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 piggy(piggyLatin):
piggyLatin = list(piggyLatin.split())

for i in range(len(piggyLatin)):
if piggyLatin[i].isalpha():
piggyLatin[i] = piggyLatin[i][1:] + piggyLatin[i][0] + 'ay'

return ' '.join(piggyLatin)

if __name__ == "__main__":
print(piggy(input()))
22 changes: 22 additions & 0 deletions codewars/Snail/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
def reverseFunc(snailMap):
return [list(reversed(row)) for row in reversed(snailMap)]

def snail(snailMap):
if not snailMap or not snailMap[0]:
return []
res = []

elements = len(snailMap) * len(snailMap[0])

while len(res) < elements:
res.extend(snailMap[0])
snailMap = snailMap[1:]
if snailMap:
for row in snailMap:
res.append(row.pop())
snailMap = reverseFunc(snailMap)

return res

if __name__ == "__main__":
print(snail(input()))
8 changes: 8 additions & 0 deletions codewars/Sum of Digits - Digital Root/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def digitalRoot(number):
while number > 9:
number = sum([int(x) for x in str(number)])

return number

if __name__ == "__main__":
print(digitalRoot(int(input())))
21 changes: 21 additions & 0 deletions codewars/Sum of Intervals/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def summIntervals(intervals):
intervals = merge(intervals)
return sum([(end - start) for start, end in intervals])

def merge(intervals):
intervals.sort()
res = []
start, end = intervals[0][0], intervals[0][1]
for i, interval in enumerate(intervals[1:]):
new_start, new_end = interval[0], interval[1]
if new_start > end:
res.append([start, end])
start, end = new_start, new_end
else:
end = max(new_end, end)
res.append([start, end])

return res

if __name__ == "__main__":
print(summIntervals(input()))
12 changes: 12 additions & 0 deletions codewars/Sum of pairs/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def summPairs(ints, s):
seen = {}
for i, number in enumerate(ints):
purpose = s - number
if purpose in seen:
return [purpose, number]
seen[number] = i

return None

if __name__ == "__main__":
print(summPairs(input(), input()))
32 changes: 32 additions & 0 deletions codewars/Tic-Tac-Toe Checker/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
def resolved(board):
if emptySpaces(board):
return -1
return resultGame(board)

def emptySpaces(board):
for i in range(3):
for j in range(3):
if board[i][j] == 0 and resultGame(board) == 0:
return True

return False

def resultGame(board: tuple):
firstDiagonal = set([board[i][i] for i in range(len(board))])
secondDiagonal = set([board[i][len(board[0])-i-1] for i in range(len(board))])
for i in range(3):
line = set(board[i])
column = set(tuple(x[i] for x in board))
if len(line) == 1 and list(line)[0] != 0:
return list(line)[0]
elif len(column) == 1 and list(column)[0] != 0:
return list(column)[0]
elif len(firstDiagonal) == 1 and list(firstDiagonal)[0] != 0:
return list(firstDiagonal)[0]
elif len(secondDiagonal) == 1 and list(secondDiagonal)[0] != 0:
return list(secondDiagonal)[0]

return 0

if __name__ == "__main__":
print(resolved(input()))
2 changes: 1 addition & 1 deletion rpgsaga/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/saga/src/index.ts",
"program": "${workspaceFolder}\\saga\\src\\index.ts",
"outFiles": [
"${workspaceFolder}/**/*.js"
]
Expand Down
5 changes: 5 additions & 0 deletions rpgsaga/saga/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ export default [{
modifiers: ["private"],
format: ["camelCase"],
leadingUnderscore: "allow",
}, {
selector: ["memberLike"],
modifiers: ["protected"],
format: ["camelCase"],
leadingUnderscore: "allow",
}, {
selector: ["enumMember", "variable"],
format: ["camelCase", "PascalCase", "UPPER_CASE"],
Expand Down
Loading