Skip to content

Commit

Permalink
Merge pull request YearOfProgramming#102 from ningyuansg/master
Browse files Browse the repository at this point in the history
  • Loading branch information
Remillardj committed Jan 3, 2017
2 parents 6729524 + 94ee769 commit 81a4937
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions challenge_0/python/ning/challenge_0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print('Hello World!')
6 changes: 6 additions & 0 deletions challenge_1/python/ning/challenge_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def reverse_string(original_string):
return original_string[::-1]

original_string = str(input("Enter a string to be reversed > "))
print(reverse_string(original_string))

19 changes: 19 additions & 0 deletions challenge_2/python/ning/challenge_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from collections import defaultdict

def find_unique(sequence):
counter_dict = defaultdict(int)
uniques = []

for item in sequence:
counter_dict[item] += 1

for item, count in counter_dict.items():
if count == 1:
uniques.append(item)

return uniques

test_sequence_list = [2,'a','l',3,'l',4,'k',2,3,4,'a',6,'c',4,'m',6,'m','k',9,10,9,8,7,8,10,7]

print(find_unique(test_sequence_list))

4 changes: 4 additions & 0 deletions challenge_3/python/ning/challenge_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from collections import Counter

test_sequence_list = [2,2,3,7,5,7,7,7,4,7,2,7,4,5,6,7,7,8,6,7,7,8,10,12,29,30,19,10,7,7,7,7,7,7,7,7,7]
print(Counter(test_sequence_list).most_common(1)[0][0])
30 changes: 30 additions & 0 deletions challenge_4/python/ning/challenge_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class BTree:
def __init__(self, b_tree_list=list()):
self.b_tree_list = b_tree_list
self.levels = len(b_tree_list)

def visualise(self):
for index, level in enumerate(self.b_tree_list):
spacing = 2 ** (self.levels - index) - 1
print(((spacing-1)//2)*' ', end='')
for node in level:
if node is None:
print(' ', end='')
else:
print(node, end='')
print(spacing * ' ', end='')
print('') # newline

def invert(self):
for level in self.b_tree_list:
level.reverse()


example_tree = BTree([
[4],
[2, 7],
[1, 3, 6, 9]])

example_tree.visualise()
example_tree.invert()
example_tree.visualise()

0 comments on commit 81a4937

Please sign in to comment.