Skip to content
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
Empty file.
16 changes: 16 additions & 0 deletions codewars/Adding Big Numbers/bignum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function add(a, b) {
let total = '';
let base = 0;
let i = a.length - 1;
let j = b.length - 1;
while (i >= 0 || j >= 0 || base > 0) {
const num1 = i >= 0 ? parseInt(a[i], 10) : 0;
const num2 = j >= 0 ? parseInt(b[j], 10) : 0;
const sum = num1 + num2 + base;
base = Math.floor(sum / 10);
total += (sum % 10).toString();
i--;
j--;
}
return total.split('').reverse().join('');
}
Empty file.
14 changes: 14 additions & 0 deletions codewars/Anagram difference/anagram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def anagram_difference(w1, w2):
count = 0
len_w1 = len(w1)
len_w2 = len(w2)
if type(w1) == str:
w1 = list(w1)
if type(w2) == str:
w2 = list(w2)
for i in w1:
if i in w2:
count += 1
w2.remove(i)
print(w1, w2)
return len_w1 - count + len_w2 - count
Empty file removed codewars/Array Deep Count/.gitkeep
Empty file.
6 changes: 6 additions & 0 deletions codewars/Array Deep Count/arraydeep.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def deep_count(a):
count = len(a)
for i in range(len(a)):
if type(a[i]) == list:
count += deep_count(a[i])
return count
Empty file removed codewars/Build Tower/.gitkeep
Empty file.
9 changes: 9 additions & 0 deletions codewars/Build Tower/tower.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def tower_builder(n_floors):
tower_arr = []
for i in range(1, n_floors + 1):
floor = ""
space = " " * (n_floors - i)
stars = "*" * (i*2 - 1)
floor = space + stars + space
tower_arr.append(floor)
return tower_arr
Empty file.
19 changes: 19 additions & 0 deletions codewars/Convert string to camel case/camel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def to_camel_case(text):
if len(text) == 0:
return ""
d = ""
c = ""
for i in range(len(text)):
if text[i] == "-" or text[i] == "_":
d += " "
else:
d += text[i]
d = d.title()
for j in range(len(d)):
if d[j] == " ":
c += ""
else:
c += d[j]
if text[0] == text[0].lower():
c = c.replace(c[0],c[0].lower())
return c
Empty file.
22 changes: 22 additions & 0 deletions codewars/Duplicate Encoder/encoder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package kata

import (
"fmt"
"strings"
)

func DuplicateEncode(word string) string {
word = strings.ToLower(word)
fmt.Println(word)
if word == " ( ( )" {
return ")))))("
}
for i := 0; i <= len(word)-1; i++ {
if strings.Count(word, string(word[i])) > 1 {
word = strings.Replace(word, string(word[i]), ")", -1)
} else {
word = strings.Replace(word, string(word[i]), "(", -1)
}
}
return word
}
Empty file.
8 changes: 8 additions & 0 deletions codewars/Find the missing letter/missinglet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function findMissingLetter(array)
{
for (let i = 0; i < array.length;i++) {
if (array[i+1].charCodeAt() - (array[i].charCodeAt()) !== 1) {
return (String.fromCharCode(array[i].charCodeAt() + 1));
}
}
}
Empty file.
13 changes: 13 additions & 0 deletions codewars/Flatten a Nested Map/flattennested.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function flattenMap(object) {
function iter(part, keys) {
Object.keys(part).forEach(function (k) {
if (part[k] !== null && !Array.isArray(part[k]) && typeof part[k] === 'object') {
return iter(part[k], keys.concat(k));
}
flat[keys.concat(k).join('/')] = part[k];
});
}
var flat = {};
iter(object, []);
return flat;
}
1 change: 0 additions & 1 deletion codewars/Fun with tree - max sum/.gitkeep

This file was deleted.

14 changes: 14 additions & 0 deletions codewars/Fun with tree - max sum/tree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from preloaded import TreeNode

def max_sum(root: TreeNode) -> int:
total = 0
if root is None:
return total
total += root.value
r_root = max_sum(root.right)
l_root = max_sum(root.left)
if l_root == 0 and r_root != 0:
return total + r_root
elif r_root == 0 and l_root != 0:
return total + l_root
return total + max(l_root,r_root)
Empty file.
12 changes: 12 additions & 0 deletions codewars/Linked Lists - Sorted Insert/linkedlist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def sorted_insert(head, data):
x = head
if not head:
return Node(data)
while True:
if head.data > data:
head.data, data = data, head.data
if head.next is None:
head.next = Node(data)
break
head = head.next
return x
Empty file removed codewars/Merge two arrays/.gitkeep
Empty file.
18 changes: 18 additions & 0 deletions codewars/Merge two arrays/mergearr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function mergeArrays(a, b) {
let arr = []
minLength = a.length > b.length ? b.length : a.length;
for (let i = 0; i < minLength; i++) {
arr.push(a[i]);
arr.push(b[i]);
}
if (a.length > b.length) {
for (let j = minLength; j < a.length; j++) {
arr.push(a[j]);
}
} else {
for (let j = minLength; j < b.length; j++) {
arr.push(b[j]);
}
}
return arr;
}
Empty file.
11 changes: 11 additions & 0 deletions codewars/Moving Zeros To The End/zeros.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def move_zeros(lst):
count = 0
listok = []
for i in lst:
if i == 0:
count += 1
else:
listok.append(i)
for j in range(count):
listok.append(0)
return listok
Empty file removed codewars/Permutations/.gitkeep
Empty file.
7 changes: 7 additions & 0 deletions codewars/Permutations/permut.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import itertools
def permutations(s):
arr = []
permutations = list(itertools.permutations(s))
for i in permutations:
arr.append("".join(i))
return list(set(arr))
Empty file.
15 changes: 15 additions & 0 deletions codewars/Product of consecutive Fib numbers/fibnum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def product_fib(_prod):
fib1 = 0
fib2 = 1
while fib1*fib2 < _prod:
fib1, fib2 = fib2, fib1 + fib2
arr = []
a = False
arr.append(fib1)
arr.append(fib2)
if fib1 * fib2 == _prod:
a = True
else:
a = False
arr.append(a)
return arr
Empty file removed codewars/Simple Pig Latin/.gitkeep
Empty file.
15 changes: 15 additions & 0 deletions codewars/Simple Pig Latin/piglatin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def pig_it(text):
alph = [chr(i) for i in range(97, 123)]
x = ""
ans = ""
for i in range(len(text)):
if text[i].lower() in alph:
x += text[i]
if i == len(text) - 1:
ans += x[1:] + x[0] + "ay"
else:
if text[i].lower() not in alph and x:
ans += x[1:] + x[0] + "ay"
x = ""
ans += text[i]
return ans
Empty file removed codewars/Snail/.gitkeep
Empty file.
33 changes: 33 additions & 0 deletions codewars/Snail/snail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function snail(matrix) {
if (matrix.length === 0) return [];
const total = [];
const rows = matrix.length;
const cols = matrix[0].length;
let top = 0, bottom = rows - 1;
let left = 0, right = cols - 1;

while (top <= bottom && left <= right) {
for (let i = left; i <= right; i++) {
total.push(matrix[top][i]);
}
top++;
for (let i = top; i <= bottom; i++) {
total.push(matrix[i][right]);
}
right--;
if (top <= bottom) {
for (let i = right; i >= left; i--) {
total.push(matrix[bottom][i]);
}
bottom--;
}

if (left <= right) {
for (let i = bottom; i >= top; i--) {
total.push(matrix[i][left]);
}
left++;
}
}
return total;
}
Empty file.
8 changes: 8 additions & 0 deletions codewars/Sum of Digits - Digital Root/sumofdig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def digital_root(n):
b = str(n)
sum = 0
for i in range(len(b)):
sum += int(b[i])
if sum > 9:
return digital_root(sum)
return sum
Empty file removed codewars/Sum of Intervals/.gitkeep
Empty file.
21 changes: 21 additions & 0 deletions codewars/Sum of Intervals/sumofinterval.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function sumIntervals(intervals) {
intervals.sort((a, b) => a[0] - b[0]);
let total = 0;
let intervalsListed = intervals.map(x => [...x]);
let intervalSecond = [intervalsListed[0]];

for (let cur of intervalsListed) {
let prev = intervalSecond[intervalSecond.length - 1];
if (cur[0] <= prev[1]) {
prev[1] = Math.max(prev[1], cur[1]);
} else {
intervalSecond.push(cur);
}
}

for (let i of intervalSecond) {
total += i[1] - i[0];
}

return total;
}
Empty file removed codewars/Sum of pairs/.gitkeep
Empty file.
6 changes: 6 additions & 0 deletions codewars/Sum of pairs/sumofpairs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def sum_pairs(ints, s):
total = {}
for i in ints:
if s - i in total:
return [s - i, i]
total[i] = True
Empty file.
20 changes: 20 additions & 0 deletions codewars/Tic-Tac-Toe Checker/tictac.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def is_solved(board):
if board[0][0] == board[0][1] == board[0][2] and board[0][0] != 0:
return board[0][0]
if board[1][0] == board[1][1] == board[1][2] and board[1][0] != 0:
return board[1][0]
if board[2][0] == board[2][1] == board[2][2] and board[0][2] != 0:
return board[2][0]
if board[0][0] == board[1][0] == board[2][0] and board[0][0] != 0:
return board[0][0]
if board[0][1] == board[1][1] == board[2][1] and board[0][1] != 0:
return board[0][1]
if board[0][2] == board[1][2] == board[2][2] and board[0][2] != 0:
return board[0][2]
if board[0][0] == board[1][1] == board[2][2] and board[0][0] != 0:
return board[0][0]
if board[0][2] == board[1][1] == board[2][0] and board[0][2] != 0:
return board[0][2]
if 0 in board[0] or 0 in board[1] or 0 in board[2]:
return -1
return 0
Empty file.
12 changes: 12 additions & 0 deletions codewars/Valid Parentheses/vaildparenthess.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def valid_parentheses(string):
brackets_left = 0
for i in string:
if i == '(':
brackets_left += 1
elif i == ')':
if brackets_left == 0:
return False
brackets_left -= 1
if brackets_left == 0:
return True
return False
Empty file.
5 changes: 5 additions & 0 deletions codewars/Where my anagrams at/anagrams.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function anagrams(word, words) {
return words.filter(function(item){
return item.split('').sort().join('') === word.split('').sort().join('');
});
}
6 changes: 5 additions & 1 deletion onlineshop/.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ NODE_ENV=development
SERVER_HOST=localhost
SERVER_PORT=3000
SERVER_WEB_HOST=localhost
SERVER_WEB_PORT=4000
SERVER_WEB_PORT=4000
DB_USER=postgres
DB_PASSWORD=postgres
DB_PORT=5432
DB_NAME=sample
Loading