Skip to content

Commit

Permalink
added more challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasstparker committed Feb 22, 2023
1 parent 6532636 commit 1d7581f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
16 changes: 8 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
def find_incorrect_value(tree):
for child in enumerate(tree):
left_child = i * 2 + 1
right_child = i * 2 + 2
def move_zeros(lst):
zeros = []
for i in range(len(lst)-1, -1, -1):
if lst[i] == 0:
zeros.append(lst.pop(i))
lst.extend(zeros)
return lst



print(find_incorrect_value([28, 13, 14, 6, 7, 5, 9]))
# 9, 5, 7, 6, 14, 13, 28
print(find_incorrect_value([27, 14, 14, 6, 7, 5, 9]))

print(move_zeros([1, 2, 0, 1, 0, 1, 0, 3, 0, 1]))
13 changes: 13 additions & 0 deletions pig_it.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import re


def pig_it(text):
word_pattern = re.compile(r'[a-zA-Z]+')

def pig_word(word):
return word[1:] + word[0] + 'ay'

return word_pattern.sub(lambda match: pig_word(match.group()), text)


print(pig_it("Hello there sir 67!"))
14 changes: 14 additions & 0 deletions rgb_to_hex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
rgb_hex_dict = {x: str(x) if x < 10 else chr(x + 55) for x in range(16)}


def rgb(r, g, b):
r = max(0, min(255, r))
g = max(0, min(255, g))
b = max(0, min(255, b))
r_hex = f"{rgb_hex_dict[r // 16]}{rgb_hex_dict[r % 16]}"
g_hex = f"{rgb_hex_dict[g // 16]}{rgb_hex_dict[g % 16]}"
b_hex = f"{rgb_hex_dict[b // 16]}{rgb_hex_dict[b % 16]}"
return f"{r_hex}{g_hex}{b_hex}"


print(rgb(0, 1, 1))

0 comments on commit 1d7581f

Please sign in to comment.