Skip to content

Commit cf65cc2

Browse files
committedOct 16, 2020
Codewars
1 parent 976518e commit cf65cc2

File tree

4 files changed

+84
-1
lines changed

4 files changed

+84
-1
lines changed
 

‎README.md

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
[validDate Regex](https://www.codewars.com/kata/548db0bd1df5bbf29b0000b7/) | [Python solution](python/5_kyu/validDate_Regex.py)
2929
[Hail Caesar](https://www.codewars.com/kata/57067d7b7a53e88ae400024c) | [Python solution](python/5_kyu/Hail_Caesar.py)
3030
[String incrementer](https://www.codewars.com/kata/54a91a4883a7de5d7800009c/) | [Python solution](python/5_kyu/String_incrementer.py)
31+
[Directions Reduction](https://www.codewars.com/kata/550f22f4d758534c1100025a/solutions/python) | [Python solution](python/5_kyu/Directions_Reduction.py)
3132

3233
**6-kyu**
3334
Problems/Kata | Solution
@@ -53,3 +54,4 @@
5354
[Python's Dynamic Classes #1](https://www.codewars.com/kata/55ddb0ea5a133623b6000043) | [Python solution](python/7_kyu/Python_Dynamic_Classes_1.py)
5455
[Maximum Length Difference](https://www.codewars.com/kata/5663f5305102699bad000056/) | [Javascript solution](javascript/7_kyu/Maximum_Length_Difference.js)
5556
[Beginner Series #3 Sum of Numbers](https://www.codewars.com/kata/55f2b110f61eb01779000053/) | [Javascript solution](javascript/7_kyu/Beginner_Series3.js)
57+
[Remove the minimum](https://www.codewars.com/kata/563cf89eb4747c5fb100001b) | [Javascript solution](javascript/7_kyu/Remove_the_minimum.js)
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Kata link:
2+
// https://www.codewars.com/kata/563cf89eb4747c5fb100001b
3+
4+
// -------------------------------------
5+
// Instructions:
6+
/*
7+
8+
Given an array of integers, remove the smallest value. Do not mutate the original array/list. If there are multiple elements with the same value, remove the one with a lower index. If you get an empty array/list, return an empty array/list.
9+
10+
Don't change the order of the elements that are left.
11+
12+
Examples
13+
removeSmallest([1,2,3,4,5]) = [2,3,4,5]
14+
removeSmallest([5,3,2,1,4]) = [5,3,2,4]
15+
removeSmallest([2,2,1,2,1]) = [2,2,2,1]
16+
*/
17+
18+
// -------------------------------------
19+
// Solution 1:
20+
21+
function removeSmallest(numbers) {
22+
if (!numbers) {
23+
return [];
24+
}
25+
let min = Math.min(...numbers);
26+
let ind = numbers.indexOf(min);
27+
return numbers.slice(0, ind).concat(numbers.slice(ind + 1));
28+
}
29+
30+
31+
// -------------------------------------
32+
// Basic Tests
33+
34+
console.log(removeSmallest([1, 2, 3, 4, 5]), [2, 3, 4, 5]);
35+
console.log(removeSmallest([5, 3, 2, 1, 4]), [5, 3, 2, 4]);
36+
console.log(removeSmallest([2, 2, 1, 2, 1]), [2, 2, 2, 1]);
37+
console.log(removeSmallest([]), [])
38+

‎python/4_kyu/Number_of_Proper_Fractions_with_Denominator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def proper_fractions(num):
3535
return 0
3636
x = num > 1 and num
3737
for p in range(2, int(num ** .5) + 1):
38-
if not num % p:
38+
if not num % p:d
3939
x -= x // p
4040
while not num % p:
4141
num //= p

‎python/5_kyu/Directions_Reduction.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Kata link:
2+
# https://www.codewars.com/kata/550f22f4d758534c1100025a/train/python
3+
# -------------------------------------
4+
# Solution 1:
5+
6+
def dirReduc(arr):
7+
for _ in range(len(arr) // 2):
8+
if len(arr) > 1:
9+
for x in range(len(arr) - 1):
10+
if arr[x] == 'NORTH' and arr[x+1] == 'SOUTH' or arr[x] == 'SOUTH' and arr[x+1] == 'NORTH':
11+
del arr[x:x+2]
12+
break
13+
elif arr[x] == 'EAST' and arr[x+1] == 'WEST' or arr[x] == 'WEST' and arr[x+1] == 'EAST':
14+
del arr[x:x+2]
15+
break
16+
else:
17+
break
18+
return arr
19+
20+
# Solution 2:
21+
22+
# opposite = {'NORTH': 'SOUTH', 'EAST': 'WEST', 'SOUTH': 'NORTH', 'WEST': 'EAST'}
23+
24+
# def dirReduc(plan):
25+
# new_plan = []
26+
# for d in plan:
27+
# if new_plan and new_plan[-1] == opposite[d]:
28+
# new_plan.pop()
29+
# else:
30+
# new_plan.append(d)
31+
# return new_plan
32+
33+
# -------------------------------------
34+
# Basic Tests
35+
36+
37+
a = ["NORTH", "SOUTH", "SOUTH", "EAST", "WEST", "NORTH", "WEST"]
38+
39+
print(dirReduc(a), ['WEST'])
40+
u=["NORTH", "WEST", "SOUTH", "EAST"]
41+
42+
print(dirReduc(u), ["NORTH", "WEST", "SOUTH", "EAST"])
43+

0 commit comments

Comments
 (0)